Jé pa l'temps #4 - I love bash

Make a loop in bash

Array=(
  'Value 1'
  'Value 2'
  'Value 3'
)

for value in "${Array[@]}"; do
  echo $value
done

Search something

For searching something, use this awesome command

grep -rno 'something' --exclude-dir="./*/node_modules" .

--exclude-diris an option to exclude some large forlder . at the end is where you want to search, in this example i want to search where i am

⚠️ -r option tells you want to search recursively. It is absolutly powerful but it can be very slow

Copy hidden file to a remote server

scp -rp * user@domain.com:~/osef/
  • -r: recursive
  • -p: for hidden files

healthcheck command in bash

while true; do time curl https://www.wikipedia.org/; sleep 1; echo ""; done

Cheat sheet for common commands

Log-parsing-cheat-sheet

Convert row to column (invert of xargs)

ls | fmt -1

Display count of file per directory

du -a | cut -d/ -f2 | sort | uniq -c | sort -nr

Count lines per file

for i in $(find . -type f); do wc -l $i; done | sort -k1 -n

— — — — — — — — — — — — — — — — — — — — — —

La série « Jé pa l’temps » est une série de tutoriels rapides en mode “prise de note” pour avoir une trace de tout ce dont je ne peux me rappeler et pourquoi pas le partager à d’autre. On va à l’essentiel, laissons les jolis pavés à d’autres sites comme medium… LOL !