Useful shell commands

As with all devs on a linux project, I seem to be spending a great deal of time figuring out how to do things on the UNIX command line that I know will come in handy again in the future. As such, I will contribute yet another command line post…


ssh -f user@remote.machine -L localport:remote.machine:remoteport -N

Sends a message to localhost:localport and have it ‘tunnelled’ over to remote.machine:remoteport.

Delete files older than X:

find /path/to/dir -type f -name *foo* -mtime +3 | xargs rm -f

Finds all files in /path/to/dir that match the name *foo* (using wildcards) that are older than 3 days and delete them

Search contents of files for string:

find /path/to/dir -name *foo* | xargs grep "string to search"

Find everything in /path/to/dir that match the name *foo* (using wildcards) and then grep each for the string specified

Find files that match multiple different names:

find . -type f \( -iname "*.erb" -or -iname "*.rb" -or -iname "*.pp" \)

Find all files in /path/to/dir that end with (erb || rb || pp)