Scott Wiersdorf Updated: Mon Mar 1 10:20:55 MST 2004 Bourne Shell Tricks This file contains a few of my favorites from my bag o' tricks for Bourne shell commands. All of these commands have been tested with Bash 2.05 and many of them also work with plain old Bourne shell. ## using bash for truncating the *first part* of a filename: for i in projects-010*; do mv $i ${i#projects-}; done ## anchor the pattern: rename files that *start* with 'fr*' to 'fra*' for i in fr*; do mv $i ${i//#fr/fra}; done ## using bash for truncating the *last part* of a filename: for i in *.from; do mv $i ${i%from}to; done ## using bash for converting uppercase files to lowercase files: for i in *; do mv "$i" "`echo $i | tr '[:upper:]' '[:lower:]'`"; done ## using bash to delete a string in a name for i in Blechb*; do mv "$i" "${i//Blechb*serensemble - /}"; done ## using bash to substitute a string in a name ## - replace unprintable characters with ascii equivalents for i in Blechb*; do mv "$i" "${i//Blechbl?serensemble/Blechblaserensemble}"; done ## - replace underscores with spaces for i in *.wav; do mv "$i" "${i//_/ }"; done ## stripping DOS newlines from a file: tr tr -d '\r' < inputfile > outputfile ## stripping DOS newlines from a file inplace: Perl perl -pi -e 's/\r\n/\n/' inputfile