*nix Commands

In: Uncategorized

13 Aug 2009

Because I’m prone to forget some of my useful, extended, piped commands, I though I would post a few:

Search specific file types for phrases, print the line numbers, dump the errors:

find -regex ".*\.ext$" | xargs grep -n searchText 2> /dev/null

Search specific files and mod only matching files via sed (creating .old backups)

find -regex ".*\.ext$" | xargs grep -l searchText 2> /dev/null | xargs sed -i.old 's/searchText/replaceText/g'

Find recently modified files
Ex. modified in the last 30 days

find -mtime -30 -type f

syntax note: -X: modified within X, X: modified exactly X ago, +X: unmodified for X

Find modified files in CVS
Ex. find files that you since Aug 1 (-D is very flexible with date formats)

cvs history -c -D"August 1"

Replacing Windows EOL (Seriously, I still come across this!)

# Press Ctrl-V then Ctrl-M to get ^M
sed -i.old 's/^M/\n/g' index.jsp 

Of course, you may have the dos2unix command available. Simply,

dos2unix oldfile newfile

Some useful CVS commands

#compare to versions of a file
cvs diff -r 1.1 -r 1.2 file

Find all files of a certain type and size and add them to an archive file.

find . -name "*\.css" -size +1b | xargs tar cvf css.tar