Mastering the Shell

Upcase is incredible. All credit goes to https://thoughtbot.com/upcase/videos/slice-and-dice

Print first 10 lines

$ head ruby_file.rb

Print last 10 lines

$ tail ruby_file.rb

Print first 30 lines (tail also works for 30 last lines)

$ head -n 30 ruby_file.br

find text within file without caring about case

$ grep --ignore-case hello greetings.txt $ grep -i hello greetings.txt

Use grep with regular expressions always pass the -E flag

$ grep -E '[Hh]ello' greetings.txt

return everthing that doesn’t match

$ grep --invert-match hello greetings.txt $ grep -v hello greetings.txt

oh the fucking tree command

Visualized representation of the file structure

tree

sed ’s/Hello/Goodbye/’ greetings.txt

This will print out the changes, without actually changing the file. s stands for substitute.

sed -E ’s/Hello|hello/GOODBYE/’ greetings.txt

Regular expression sed

sed -i ’.old’ ’s/Hello/Goodbye/’ greetings.txt

will replace the old file and add a .old to the file name. DAYUM. If I leave the .old blank, it will replace the file and not create a backup file.

Post Content