Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using find from sorted by
Terminal - Commands using find - 1,021 results
find . | grep deleteme | while read line; do rm $line; done
2009-02-18 00:55:57
User: tec
Functions: find grep read rm
-3

This command deletes all files in all subfolders if their name or path contains "deleteme".

To dry-run the command without actually deleting files run:

find . | grep deleteme | while read line; do echo rm $line; done
find . -name ".svn" -exec rm -rf {} \;
2009-02-17 23:00:30
User: mihaibojin
Functions: find rm
0

If you need to delete all redundant ".svn" directories from a given path and all its subdirectories, use this command !

Particulary useful if you want to upload to an ftp server, but don't use svn or if you need to update/backup some source code to another directory.

You can also try "svn export . /new/path/without/svn/dirs" (also from the CLI)

find /home -uid 1056 -exec chown 2056 {} \;
2009-02-17 19:42:50
Functions: chown find
5

Finds all files in /home owned by UID 1056 and changes to 2056.

find . -size +10240k -exec ls -l {} \; | awk '{ print $5,"",$9 }'|sort -rn > message.out
2009-02-17 19:39:56
User: rommelsharma
Functions: awk find ls
5

This command specifies the size in Kilobytes using 'k' in the -size +(N)k option. The plus sign says greater than. -exec [cmd] {} \; invokes ls -l command on each file and awk strips off the values of the 5th (size) and the 9th (filename) column from the ls -l output to display. Sort is done in reversed order (descending) numerically using sort -rn options.

A cron job could be run to execute a script like this and alert the users if a dir has files exceeding certain size, and provide file details as well.

sudo find / -user root -perm -4000 -print
find apps/ -name "*.svn-base" -prune -o -print -name "*.php" | xargs grep -E 'new .+Form\('
2009-02-17 14:56:01
User: ubermuda
Functions: find grep xargs
-1

finds all forms instanciated into a symfony project, pruning svn files.

find . -type f|while read f; do mv $f `echo $f |tr '[:upper:]' '[ :lower:]'`; done
2009-02-17 09:44:38
User: berta
Functions: find mv read
9

or, to process a single directory:

for f in *; do mv $f `echo $f |tr '[:upper:]' '[:lower:]'`; done
find . -type f -name \*.c | while read f; do mv $f "`basename $f .c`".C; done
2009-02-17 09:30:43
User: berta
Functions: find mv read
0

or, for a single directory:

for f in *.c; do mv $f "`basename $f .c`".C; done
find ~/bin/ -name "*sh" -print0 | xargs -0t tar -zcvf foofile.tar.gz
2009-02-17 08:48:34
User: lhb
Functions: find tar xargs
5

tar options may change ;)

c to compress into a tar file, z for gzip (j for bzip) man tar

-print0 and -0t are usefull for names with spaces, \, etc.

find /directory/to/search/ -type f -print0 | xargs -0 grep "findtext"
2009-02-17 07:16:32
User: dingobytes
Functions: find grep xargs
2

this will find text in the directory you specify and give you line where it appears.

find path/to/folder/ -type f -print0 | xargs -0 -n 1 md5sum | awk '{print $1}' | sort | md5sum | awk '{print $1}'
2009-02-16 19:39:37
User: mcover
Functions: awk find md5sum sort xargs
-2

For quick validation of folder's file-contents (structure not taken into account) - I use it mostly to check if two folders' contents are the same.

find . -type f -perm +0111 -print
find . -name "*.jar" | xargs -tn1 jar tvf | grep --color "SearchTerm"
2009-02-16 17:18:36
Functions: find grep xargs
2

Great for finding which jar some pesky class is hiding in!

find . -name "*.pyc" -exec rm {} \;
2009-02-16 17:15:58
User: nsmgr8
Functions: find rm
-2

For a python project, sometimes I need to clean all the compiled python files. I have an alias 'rmpyc' to this command. This really saves me a lot of typing and hunting throughout the folders to delete those files.

find . -type f -name "*" -mtime +10 -print -exec gzip {} \;
2009-02-16 14:33:32
User: migueldiab
Functions: find gzip
2

Useful for a cron job that runs nightly, gzipping or alternatively deleting files from a specific directory that are older than 10 days (in this case)

find / -type f -size +25M -exec ls -lh {} \; | awk '{ print $5 " " $6$7 ": " $9 }'
2009-02-16 12:27:48
User: darkon1365
Functions: awk find ls
1

Very useful for finding all files over a specified size, such as out of control log files chewing up all available disk space. Fedora Core x specific version.

find ./ -name '*' -exec rename 's/\s+/_/g' {} \;
find . -type f -name '*.html' -exec grep -H HACKED {} \; > hacklog.txt
2009-02-16 08:57:25
User: nullrouter
Functions: find grep
0

This will check all .HTML file contents for the word "Hacked" and dump it to hacklog.txt. This is great for located all those files affected by nasty Joomla exploits. Change the .HTML to any other extension you wish to check, and of course the word "HACKED" for other searches.

find / -name \*string\*
2009-02-16 08:43:01
User: tini
Functions: find
-2

run as root and use it fo find file you're looking for.

find . -type f -exec grep -l pattern {} \; | xargs vi +/pattern
find ${PATH//:/ } -executable -type f -printf "%f\n"
2009-02-16 06:03:46
User: kamathln
Functions: find
5

##Dependancies: bash coreutils

Many executables in $PATH have the keyword somewhere other than the beginning in their file names. The command is useful for exploring the executables in $PATH like this.

find ${PATH//:/ } -executable -type f -printf "%f\n" |grep admin

lpadmin

time-admin

network-admin

svnadmin

users-admin

django-admin

shares-admin

services-admin

find . \( -type d -name .svn -prune \) -o -type d -print
find . -type f -exec grep -l XXX {} \;|tee /tmp/fileschanged|xargs perl -pi.bak -e 's/XXX/YYY/g'
2009-02-16 02:55:23
User: drossman
Functions: find grep perl tee xargs
6

Find all files that contain string XXX in them, change the string from XXX to YYY, make a backup copy of the file and save a list of files changed in /tmp/fileschanged.

find . -maxdepth 1 -iname '*jpg' -exec convert -quality 60 {} lowQ/{} \;
2009-02-15 19:34:38
User: abhinay
Functions: find
-1

* lowQ/ is the output directory

* pass quality level from 1 to 100

find "$DIR" -regex "$FILENAME" -type f -print0 | xargs -0 sed -i _`date "+%y%m%d%H%M%S"` -E "s/$TEXT1/$TEXT2/g"