SaltyCrane Blog — Notes on JavaScript and web development

Linux command-line tips and tricks

More at commandlinefu.com

Download and unpack a tarball without leaving it on your hard drive (via)

curl http://example.com/path/to/blah.tar.gz | tar xz

Remove a line matching a pattern from a file

Assume GNU sed

$ sed -i".bak" '/pattern to match/d' filename.txt 

Remove a line from multiple files

$ for filepath in $( find . -name '*.yaml' ); do sed -i '/pattern to match/d' $filepath; done 

How to recursively remove empty files

$ find . -size -0 | xargs rm 

Better way via http://www.thegeekstuff.com/2010/03/find-empty-directories-and-files/

$ find . -empty -type f | xargs rm 

Keep only lines matching a pattern in multiple files

$ for dirname in $( ls ); do grep -E '(pattern of lines to keep)' "$dirname/common_filename.csv" > "../tmp/${dirname}_common_filename.csv"; done 

Test sendmail from the command line

$ echo "Subject: test from eliot" | sendmail -v [email protected]  

Create a sequence of dated directories from 20111119 to 20111130

$ for i in `seq 19 30`; do mkdir "201111$i"; done 

Comments