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.

Universal configuration monitoring and system of record for IT.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





Commands using find from sorted by
Terminal - Commands using find - 1,060 results
find /var/www/html/ -type f -mtime +30 -exec basename {} \;
for i in *jpg; do jpeginfo -c $i | grep -E "WARNING|ERROR" | cut -d " " -f 1 | xargs -I '{}' find /mnt/sourcerep -name {} -type f -print0 | xargs -0 -I '{}' cp -f {} ./ ; done
2009-05-07 00:30:36
User: vincentp
Functions: cp cut find grep xargs

Find all corrupted jpeg in the current directory, find a file with the same name in a source directory hierarchy and copy it over the corrupted jpeg file.

Convenient to run on a large bunch of jpeg files copied from an unsure medium.

Needs the jpeginfo tool, found in the jpeginfo package (on debian at least).

find . -name "*.[ch]" -exec grep -i -H "search pharse" {} \;
2009-05-06 15:22:49
User: bunedoggle
Functions: find grep
Tags: find grep

I have a bash alias for this command line and find it useful for searching C code for error messages.

The -H tells grep to print the filename. you can omit the -i to match the case exactly or keep the -i for case-insensitive matching.

This find command find all .c and .h files

cd $(dirname $(find ~ -name emails.txt))
2009-05-01 21:26:58
User: haivu
Functions: cd dirname find
Tags: bash dirname

This command looks for a single file named emails.txt which is located somewhere in my home directory and cd to that directory. This command is especially helpful when the file is burried deep in the directory structure. I tested it against the bash shells in Xubuntu 8.10 and Mac OS X Leopard 10.5.6

find . -path ./mnt -prune -o -path ./lost+found -prune -o -path ./sys -prune -o -path ./proc -prune -o -print | cpio -pumd /destination && mkdir /destination/mnt/ && mkdir /destination/proc && mkdir /destination/sys
2009-04-28 22:14:45
User: nutria
Functions: cpio find mkdir
Tags: find cpio

Clone linux installation.

find . | cpio -pumdv /destination
2009-04-28 22:08:30
User: nutria
Functions: cpio find
Tags: find cpio

Copy every file from current directory to destination preserving modification time.

find ./ -type f -exec chmod 644 {} \;
find . -maxdepth 1 -type f -name '*.sh' -o -name '*.txt'
find -type f -printf '%P\000' | egrep -iz '\.(avi|mpg|mov|flv|wmv|asf|mpeg|m4v|divx|mp4|mkv)$' | sort -z | xargs -0 ls -1
find /usr/ -type l ! -xtype f ! -xtype d -ok rm -f {} \;
find /path/to/my/files/ -type f -name "*txt*" | xargs du -k | awk 'BEGIN{x=0}{x=x+$1}END{print x}'
2009-04-16 14:17:04
Functions: awk du find xargs

Use the find command to match certain files and summarise their total size in KBytes.

find | sed -e "s/^.*\///" | awk ' BEGIN { FS=""} { print NF " " $0 } ' | sort -nrf | head -10
find -writable
2009-04-11 22:16:35
User: kFiddle
Functions: find

Have a grudge against someone on your network? Do a "find -writable" in their directory and see what you can vandalize! But seriously, this is really useful to check the files in your own home directory to make sure they can't inadvertently be changed by someone else's wayward script.

find ~ -mtime +365 -exec mv {} /tmp/mybackup \;
2009-04-11 12:16:48
User: kayowas
Functions: find mv

This example uses the -exec option to move all matching files into a backup directory

for i in $( find . ); do echo zipping file: $i zip $i.zip $i done
2009-04-07 20:37:49
User: archlich
Functions: echo find

Note that this will not work with files with spaces or characters that need to be escaped. Feel free to leave any comments to improve upon this command, and I'll add it in.


for file in $(find -type f -iname "*wav"); do mv $file "$file"_orig.WAV; mplayer -ao pcm "$file"_orig.WAV -ao pcm:file=$file; done
find . \( -type d -name .svn -prune \) -o -print | while read file ; do mergeinfo=`svn propget svn:mergeinfo $file` ; [ "$mergeinfo" != "" ] && echo -e "$file\n $mergeinfo\n" ; done
find . -type f -size +25000k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'
find ./ -not -type d | xargs wc -l | cut -c 1-8 | awk '{total += $1} END {print total}'
find . -name "*.py" -exec grep -n -H -E "^(import|from) math" {} \;
find . -type f -exec grep StringToFind \{\} --with-filename \;|sed -e '/svn/d'|sed -e '/~/d'
2009-03-31 18:09:31
User: f241vc15
Functions: find grep sed

Look for a string in one of your codes, excluding the files with svn and ~ (temp/back up files). This can be useful when you're looking for a particular string in one of your source codes for example, inside a directory which is under version control (e.g. svn), removing all the annoying files with ~ (tilde) from the search. you can even change the command after -exec to delete (rm) or view (cat) files found by 'find' for example

find ~/.thumbnails/ -type f -atime +30 -print0 | xargs -0 rm
2009-03-30 04:23:07
User: alperyilmaz
Functions: find xargs

By time thumbnail images in ~/thumbnails take up too much space, this command will help deleting old ones.

Find options explained:

-type f : find files only, not directories

-atime +30 : last accessed more than 30 days ago

find /home/user/doc/ -type d -printf "mkdir -vp '/home/user/Dropbox%p'\n" -o -type f -printf "ln -vs '%p' '/home/user/Dropbox%p'\n" | sh
2009-03-29 09:25:12
User: jnash
Functions: find

Extremely useful to maintain backups if you're using Dropbox. This mirrors the entire directory structure and places symlinks in each to the original file. Instead of copying over the data again to the ~/Dropbox folder creating a symbolic link tree is much more sensible in terms of space usage.

This has to be supplemented by another script that removes dead symlinks in the Dropbox folder which point to files that have been moved/removed.

find -L ./ -type l -delete

And then removing empty directories

find ./ -type d -exec rmdir 2>/dev/null {} \;

**Actually after some finding I found lndir which creates symbolic trees but it wasn't in the Arch repos so.. ;)

find ./ -name '*.JPG' -type f -execdir rename -f 'y/A-Z/a-z/' {} \+
2009-03-27 13:49:56
User: pronoiaque
Functions: find rename

Change files case, without modify directories, recursively.

... fucking vfat

find ./ -iname "*.mp3" -type f -printf "mv '%p' '%p'\n" | sed -e "s/mp3'$/mp3'/I" | sh
2009-03-27 13:42:40
User: jnash
Functions: find sed

Extensible to other ugly extensions like *.JPG, *.Jpg etc..

Leave out the last pipe to sh to perform a dry run.