Saltycrane logo

SaltyCrane Blog

Notes on Python, Django, and web development on Ubuntu Linux

    

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 eliot@truecar.com  

Create a sequence of dated directories from 20111119 to 20111130

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

Post a comment

Required
Required, but not displayed
Optional

Format using Markdown. (No HTML.)
  • Code blocks: prefix each line by at least 4 spaces or 1 tab (and a blank line before and after)
  • Code span: surround with backticks
  • Blockquotes: prefix lines to be quoted with >
  • Links: <URL>
  • Links w/ description: [description](URL)
Created with Django | Hosted by Linode