Max's notebook

A collection of sorts

Bash Notes

23 Jul 2019

A quick and dirty reference for bash things I find useful.



for i in $(ls); do cat $i; done

in a shell script:

for i in $(ls)
    cat $i

Read a csv as input


while IFS="," read col1 col2 col3; do echo $col3 | md5sum; done < my.csv

in a shell script:

## usage: ./ my.csv


while IFS=, read col1 col2 col3
    echo $col3 | md5sum
done < $CSV_FILE

kill all the pids

for pid in $(ps aux | grep [m]yprocess | awk '{ print $2} '); do kill -9 $pid; done
# explanation of the bracket syntax:
# The square bracket expression is part of ... grep's character class pattern matching.
# omission mine


ignore dir tree, just compress the files

# one file from the dir, ignore the tree
tar czfv archive.tgz -C /path/to/dir/ file_in_dir_to_archive

# the whole dir, ignore the tree
tar czfv archive.tgz -C /path/to/dir .

extract the files to dir

# tar Xtract Zip File
tar xzfv archive.tgz -C files/should/live/here

unzip to dir

unzip -d files/should/live/here


listen on $PORT with netcat

nc -lvnp 9000

serve pwd with python

python -m SimpleHTTPServer 9000

move stuff when you only have a network connection

cat my_bin | base64 | nc -v