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.

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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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 - 369 results
find . -type f -name \*.php | while IFS="" read i; do expand -t4 "$i" > "$i-"; mv "$i-" "$i"; done
2011-04-08 12:53:14
User: flatcap
Functions: expand find mv read

Recursively find php files and replace tab characters with spaces.


"\*.php" -- replace this with the files you wish to find

"expand" -- replace tabs with spaces (use "unexpand" to replace spaces with tabs)

"-t4" -- tabs represent 4 spaces

Note: The IFS="" in the middle is to prevent 'read' from eating leading/trailing whitespace in filenames.

find . -type l | xargs file | grep broken
find . -depth -print -execdir rename -f 'y/A-Z/a-z/' '{}' \;
2011-03-25 03:10:27
User: rsimpson
Functions: find rename
Tags: bash find mv rename tr

easier way to recursively change files to lowercase using rename instead

find . -name '*.xml' -type f -print | xargs du -ch
2011-03-22 00:47:42
User: nathwill
Functions: du find xargs
Tags: find du type

print sum of disk usage for filetype within current dir and subdirs

find . -type d -name .svn -prune -o -type f -print0 | xargs -r0 ...
find . -type f ! -iwholename \*.svn\* -print0 [ | xargs -0 ]
2011-03-21 16:45:35
User: alustenberg
Functions: find xargs

for when find . -print | grep -v .svn | xargs doesnt cut it.

alias big='BIG () { find . -size +${1}M -ls; }; BIG $1'
2011-03-10 06:33:00
User: greggster
Functions: alias find

This is for bash - make an alias - also a good blueprint for making aliases that take arguments to functions. If for Solaris use "-size +${1}000000c" to replace "-size +${1}M"

find . -maxdepth 1 -type d | grep -Pv "^.$" | sort -rn --field-separator="-" | sed -n '3,$p' | xargs rm -rf
find . -name "*.java" -type f -perm +600 -print | xargs -I _ sh -c 'grep -q hexianmao _ && iconv -f gb2312 -t utf8 -o _ -c _ '
2011-03-08 13:02:25
User: Sunng
Functions: find iconv sh xargs
Tags: find xargs iconv

One of my friends committed his code in the encoding of GB2312, which broke the build job. I have to find his code and convert.

find `pwd` -iname *SEARCH_STRING* >> ~/PLAYLIST_NAME.m3u
2011-02-27 09:00:38
User: wxl
Functions: find
Tags: find playlist m3u

must be in the directory containing the track

outputs to ~ but could be replaced with whatever you like e.g. ~/music/

files -type f | xargs -n100 | while read l; do mkdir $((++f)); cp $l $f; done
2011-02-15 23:15:16
User: flatcap
Functions: cp mkdir read xargs

Take a folder full of files and split it into smaller folders containing a maximum number of files. In this case, 100 files per directory.

find creates the list of files

xargs breaks up the list into groups of 100

for each group, create a directory and copy in the files

Note: This command won't work if there is whitespace in the filenames (but then again, neither do the alternative commands :-)

find /src/dir/ -mtime -10 -printf %P\\0|rsync --files-from=- --from0 /src/dir/ /dst/dir/
2011-01-18 22:23:47
User: pauli
Functions: find rsync
Tags: find rsync

'-mtime -10' syncs only files newer 10 days (-mtime is just one example, use whatever find expressions you need)

printf %P: File's name with the name of the command line argument under which it was found removed.

this way, you can use any src directory, no need to cd into your src directory first.

using \\0 in printf and a corresponding --from0 in rsync ensures that even filenames with newline characters work (thanks syssyphus for #3808).

both, #1481 and #3808 just work if you either copy the current directory (.) , or the filesystem root (/), otherwise the output from find and the source dir from rsync just don't match. #7685 works with an arbitrary source directory.

find . -xdev -path ./junk_dir -prune -o -type d -name "dir_name" -a -print
2011-01-16 10:08:10
Functions: find
Tags: find

Consider using this cmd when:

1. You are planning to traverse a big directory.

2. There is a subdir you don't want find to decend to. (entirely ignore)

3. You don't want find to decend to any mounted filesystems under this dir.

* The -xdev flag tells find do not go to other filesystems.

* -path ./junk_dir -prune is the pattern to ignore ./junk_dir entirely.

* The rest is the typical search and print.

To ignore multiple subdirs, you can just iterate the pattern, e.g.

find . -path ./junk1 -prune -o -path ./junk2 -prune ...

If you do want to include other filesystems, then remove -xdev flag.

If you want to search files, then change -type d to -type f.

find . -type f -name "*.tar" -printf [%f]\\n -exec tar -tf {} \; | grep -iE "[\[]|<filename>"
2011-01-06 13:01:38
Functions: find grep tar
Tags: find grep tar

A quick find command to identify all TAR files in a given path, extract a list of files contained within the tar, then search for a given string in the filelist. Returns to the user as a list of TAR files found (enclosed in []) followed by any matching files that exist in that archive. TAR can easily be swapped for JAR if required.

find /name/of/dir/ -name '*.txt' | xargs grep 'text I am searching for'
2011-01-05 15:20:40
User: erickb
Functions: find grep xargs
Tags: find xargs grep

recursively search dir for a a particular file type, search each file for a particular text.

find -type f -exec du -sh {} + | sort -rh | head
find -type f | xargs -I{} du -s "{}" | sort -rn | head | cut -f2 | xargs -I{} du -sh "{}"
2011-01-04 11:10:56
User: glaudiston
Functions: cut du find head sort xargs

Show the top file size in human readable form

find -type f | xargs -I{} du -sk "{}" | sort -rn | head
du -sk * | sort -rn | head
2011-01-03 10:49:40
User: EBAH
Functions: du sort


* find . -type f -exec ls -s {} \; | sort -n -r | head -5

* find . -type f -exec ls -l {} \; | awk '{print $5 "\t" $9}' | sort -n -r | head -5

find /deep/tree/ -type f -print0|xargs -0 -n1 -I{} ln -s '{}' .
2010-12-21 13:00:33
User: dinomite
Functions: find ln xargs
Tags: find xargs links

If you want to pull all of the files from a tree that has mixed files and directories containing files, this will link them all into a single directory. Beware of filesystem files-per-directory limits.

find . -depth -name .svn -type d -exec rm -fr {} \;
2010-12-16 17:16:23
User: tebeka
Functions: find rm
Tags: find rm

-depth argument will cause find to do a "depth first" tree search, this will eliminate the "No such file or directory" error messages

find . -name "*.php" -type f -exec sed -i "\$d" '{}' \;
2010-12-09 16:42:22
User: tedkulp
Functions: find sed
Tags: sed find text

Used this command recently to remove the trailing ?> from all the files in a php project, which has having some unnecessary whitespace issues. Obviously, change *.php to whatever you'd like.

find . -name '*.part1.rar' -exec unrar e \{\} -pPASSWORD \;
2010-12-01 10:21:15
User: arcanis
Functions: find
Tags: find unrar

Extract in the current directory the content of all parted archives.

Use the same password for each one.

rm **/*.htm
2010-11-25 17:28:55
Functions: rm
Tags: find rm

expands through shell and not find

but may hits the limit of max argument size for rm

(thus: for f in **/*.htm;do rm $f;done

but then I prefer the find command ;)

rm -rf *.htm