Back


find

dos2unix

cp

xargs

pipe

Command Line Perl

Unix

Fun with find

To run dos2unix <filename> <filename> on each file ending in .xom in this directory and sub directories:

find . \( -name "*.xom" \) -exec dos2unix {} {} \;

You can use any find options instead of simply find by name:

find . \( -type f \) -exec dos2unix {} {} \;

To copy all python files in /tmp and below to this directory:

find /tmp \( -name "*.PY" \) -exec cp {} . \;

Recursive grep for a string in all text files:

find . \( -name "*.txt" \) -exec grep "APP_NJ" {} \;

Take dumped '.dat' files from a lynx traversal and change the file names to '.html' trimming off extra junk This only works for up to 99 files. The below example should be executed as one line:

find . -name "*.dat" -print | 
   perl -ne 'chop;
             $old=$_;
             $new=$old;
             $new =~ s#lnk.*(\d\d\.)dat#$1html#;
             system("mv $old $new");'
            

Pipe to command line perl via xargs

find . -name "*.htm*" -print | xargs perl -pi -e 's#trowe#god#g'

Find and delete files which have not been accessed today

find . -atime +1  -exec rm -f {} \; 
            
Find and copy all perl scripts under my home dir to here
find ~ -name "*.pl" -print | xargs -i -t cp {} .

Find some arbitrary files and create a tar archive file out of them:

find . -name "*.shtml" | xargs tar cvf htdocs-shtml.tar