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 tagged find from sorted by
Terminal - Commands tagged find - 364 results
find /path/to/search -xtype l
find . -name '*.rar' -execdir unrar e {} \;
2012-09-27 02:27:03
User: kyle0r
Functions: find

From the cwd, recursively find all rar files, extracting each rar into the directory where it was found, rather than cwd.

A nice time saver if you've used wget or similar to mirror something, where each sub dir contains an rar archive.

Its likely this can be tuned to work with multi-part archives where all parts use ambiguous .rar extensions but I didn't test this. Perhaps unrar would handle this gracefully anyway?

echo $(find <directory> -name '*.<extension>' -exec du -s {} \; | tee $(tty) | cut -f1 | tr '\n' '+') 0 | bc
2012-09-17 22:46:50
User: ysangkok
Functions: cut du echo find tee tr

Also shows files as they are found. Only works from a tty.

find . -cnewer <file a> -and ! -cnewer <file b>
2012-08-15 21:57:42
User: rdc
Functions: find
Tags: find

This command finds all the files whose status has changed between the ctime of the older and newer .

Very useful if you can see from an ls listing a block of consecutive files you want to move or delete, but can't figure out exactly the time range by date.

ff() { find -maxdepth 3 -type f -iname "$1"; }; fd() { find -maxdepth 4 -type d -iname "$1"; }
2012-08-15 15:04:48
User: plasticboy
Functions: find
Tags: find simple

These should be a little faster since they don't have to spawn grep.

ff() { find -maxdepth 3 -type f | grep -i "$1"; }; fd() { find -maxdepth 4 -type d | grep -i "$1"; }
find . -type f -exec ls -l --full-time {} + | sort -k 6,7
2012-08-03 22:22:51
User: quadcore
Functions: find ls sort
Tags: sort find ls

This sorts files in multiple directories by their modification date. Note that sorting is done at the end using "sort", instead of using the "-ltr" options to "ls". This ensures correct results when sorting a large number of files, in which case "find" will call "ls" multiple times.

find . -type f -exec du -sh {} + | sort -hr | head
find /backup/directory -name "FILENAME_*" -mtime +15 -exec rm -vf {} +
find . -type f -exec ls -shS {} + | head -10
2012-07-28 17:21:46
User: erichamion
Functions: find head ls

This requires a version of GNU find that supports the -exec {} + action, but it seems more straightforward than the versions already posted.

find . -type f \( -name '*.c' -o -name '*.cpp' -o -name '*.cc' -o -name '*.cxx' \) | xargs grep "#include.*\.c.*" 2>&1 | tee source_inside_source_list.txt
sudo find / \( -nouser -o -nogroup \)
2012-07-13 07:09:08
User: gwd
Functions: find sudo

suspicious/anomalous ownership may indicate system breach; should return no results

sudo find / -perm -2 ! -type l -ls
find . -type f -print0 | xargs -0 du -h | sort -hr | head -10
find . -type f -print0 | xargs -0 du -h | sort -hr | head
find . -type f -exec stat -f '%m %N' {} \; | sort -n
find /path/to/dir -type f -print0 | xargs -0 grep -l "foo"
find /SOME/PATH -type f -execdir rm -f {} \+
2012-06-15 05:32:31
User: kiiwii
Functions: find rm
Tags: find rm

rm /SOME/PATH/*, when you hit "argument list too long".

find ./ -type f -exec sh -c 'echo "{}" "$(dirname "{}")/$(basename "{}" | tr "[A-Z]" "[a-z]")"' \;
2012-06-14 07:13:42
User: jelloir
Functions: find sh
Tags: bash find mv rename tr

Handles spaces in file names and directories. Optionally change directories as well by pipe to tr from dirname.

find . -type f -exec chmod a-x {} +
2012-06-11 12:50:56
User: sanmiguel
Functions: chmod find
Tags: find xargs chmod

Using `-exec cmd {} +` causes find to build the command using all matching filenames before execution, rather than once per file.

find . -type l -xtype l
2012-05-15 08:24:47
Functions: find
Tags: find symlinks

This is much safer than using -L, because it will not follow links that point to places outside the target directory subtree (CWD, in this case). See here for explanation: http://unix.stackexchange.com/a/38691/9382

find . -name ._\* -exec rm -f {} \;
2012-05-14 22:25:42
User: silicontrip
Functions: find rm
Tags: find rm

This command won't delete resource forks from an HFS file system, only from file systems that don't natively support resource forks.

find . | xargs xattr -d com.apple.quarantine
2012-05-09 23:06:51
User: brockangelo
Functions: find xargs

When downloading files on a Mac, Apple adds the x-attribute: com.apple.quarantine. Often, this makes it so you can't even run a ./configure. This command gets rid of the quarantine for all files in the current directory.

ls **/*.c(|pp)~(unit-test|android)/*
find . ! -regex '.*/\(unit-test\|android\)/.*' \( -name '*.c' -o -name '*.cpp' \)
2012-04-26 17:53:45
User: flatcap
Functions: find
Tags: find

Find files matching multiple descriptions (*.c and *.cpp) excluding multiple directories (unit-test and android).