Pages

mercredi 21 avril 2010

useful bash commands

--ls *.{dat,txt} : List all the files named with "dat" or "txt"
--ls !(*dat): List all files that do not contain "dat" in the filenames
--mv foo!(*.dat) new_older: move all the files that start with "fool" and do not end with "dat" into the new_folder
--seq -w 1 10 : print 1 to 10 in the format of 01, 02...
--seq -f "%03g" 1 10: print 1 to 10 in the format of 001, 002, 003....

--To cp the first 9 files with filename starting with "foo" to the new folder
for i in $( ls foo* | head -9 ) ; do mv $i new_folder/; done

--To show the first 40 files with names starting with "foo":
for i in $( ls foo* | head -40 );do echo "file $i"; done

--to unzip many files from one folder to the current folder:
for i in $( ls path1/*zip); do unzip path&/$i ;done

A useful site for bash questions:
http://mywiki.wooledge.org/BashFAQ

Aucun commentaire:

Enregistrer un commentaire