Oneliners


List all directories - with different numbers of levels

$ find  -type d -maxdepth  | sed -r 's/^.///' | sort

to use this oneliner specify the path and how deep it should look.

$ find . -type d -maxdepth 1 | sed -r 's/^.///' | sort

this lists directories in current work directory.

Clean CVS build for Java-class files

$ find -name \*.class | xargs rm

the find command finds all class files and the sends the list of files to xargs, whichs then again runs the rm command on each file

Mirror local website and upload to server

$ cd; wget -r -np -k http://localhost/ && scp -r localhost/* fire2:.public_html/; rm -rf localhost/; cd -

- first change working directory to users home dir
- fetch the website on the local web server and have wget convert links to relative instead of absolute so it can be placed on another webserver.
- copy files to the CS departments web-server using SSH. (only if wget succeseded)
- remove temporary wget files.

Replace string in files with another

$ for x in `find -name *.php`; do sed -r "s/oldpass/newpass/" $x > $x.tmp; mv -f $x.tmp $x; done

removes string "oldpass" with "newpass" in all php files in working directory and down.
its important to place the output from sed to a temporary file since it would otherwise mess up the files.

Search for tab character

find -name \*.java | pcregrep -r '\t' *