OneLiners

From MyLinuxNotes

Jump to: navigation, search

Contents

Rename a bunch of files

Example file name:

   This is a really long file name with spaces 001.txt
   This is a really long file name with spaces 002.txt

We are going to change it to:

   This is not 001.txt
   This is not 002.txt

Script:

   for i in *; do n=$(echo $i | sed 's/really.*\.txt/is\ not\.txt/'); mv "$i" "$n"; done

Edit a file in place

Example file foo.txt:

   foo
   bar
   barry
   curly
   moe

Lets change barry to larry

   sed -i -e 's/b\(arry\)/l\1/' foo.txt

Make an archive of a bunch of files:

(From Mike Ciul capmikee _at_ critpath _dot_ org)

   find <args> -print0 | tar -c --null -T -

Gives you nice output from the commandline

   enscript -E --color --fancy-header=emacs $1
Personal tools