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 tagged find from sorted by
Terminal - Commands tagged find - 354 results
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
-1

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
3

Also:

* 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
1

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
5

-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
2

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
0

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
-2

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
find . -type f -print0 | xargs -0 perl -pi.save -e 'tr/A-Z/a-z/'
2010-11-25 13:55:34
User: depesz
Functions: find perl xargs
Tags: perl find regex
1

In this way it doesn't have problems with filenames with spaces.

find . -type f -name '*.htm' -delete
perl -e "tr/[A-Z]/[a-z]/;" -pi.save $(find . -type f)
rm -rf `find . -type f -name *.htm`
find | egrep "\.(ade|adp|bat|chm|cmd|com|cpl|dll|exe|hta|ins|isp|jse|lib|mde|msc|msp|mst|pif|scr|sct|shb|sys|vb|vbe|vbs|vxd|wsc|wsf|wsh)$"
2010-11-23 16:53:55
User: poulter7
Functions: egrep find
-1

Returns any file in the folder which would be rejected by Gmail, if you were to send zipped version.

(Yes, you could just zip it and knock the extension off and put it back on the other side, but for some people this just isn't a solution)

find . -type f | while read line; do NEW_TS=`date -d@$((\`stat -c '%Y' $line\` + <seconds> )) '+%Y%m%d%H%M.%S'`; touch -t $NEW_TS ${line}; done
2010-11-18 14:03:32
User: angleto
Functions: find read touch
1

Increase the modification date for the files selected with the find command.

find . -type f -size +500M -exec du {} \; | sort -n
2010-11-09 18:15:44
Functions: du find sort
Tags: size find
1

Greater than 500M and sorted by size.

find / -type f -size +500M
find / -type f -size +548576 -printf "%s:%h%f\n"
find -iname '*mp3' -exec mid3iconv {} \;
2010-10-29 05:35:46
User: schlaegel
Functions: find
5

Some MP3s come with tags that don't work with all players. Also, some good tag editors like, EasyTAG output tags that don't work with all players. For example, EasyTAG saves the genre as a numeric field, which is not used correctly in Sansa MP3 players.

This command corrects the ID3 tags in MP3 files using mid3iconv, which comes with mutagen. To install Mutagen on Fedora use "yum install python-mutagen"

find . -type f ! -name "*.foo" -name "*.bar" -delete
2010-10-07 20:17:38
User: sh1mmer
Functions: find
0

This command is recursive and will delete in all directories in ".". It will find and delete all files not specified with ! -name "pattern". In this case it's file extensions. -type f means it will only find files and not directories. Finally the -delete flag ask find to delete what it matches. You can test the command by running it first without delete and it will list the files it will delete when you run it.

find ./ ! -name 'excludepattern' | xargs -i cp --parents {} destdir
2010-09-27 21:36:50
User: starchox
Functions: cp find xargs
Tags: find xargs cp
3

Preserve file structure when coping and exclude some file o dir patterns

find -regextype posix-egrep -regex ".*/[A-Z]{3}_201009[0-9]{2}.*" -printf "%f %s\n" | awk '{ SUM += $2;COUNT++ } END { print SUM/1024 " kb in " COUNT " files" }'
for i in $(find . -iname '*.html'); do sed '/String/d' $i > $i-tmp; mv $i-tmp $i; done
2010-09-21 14:35:18
User: cadu
Functions: find mv sed
Tags: sed find
-3

Search in all html files and remove the lines that 'String' is found.

find . -name "*noticia*" -name "*jhtm*" -name "*.tpl" -exec grep -li "id=\"col-direita\"" '{}' \; | xargs -n1 mate
find . -iname '*.jpg' -type f -print0 |perl -0 -ne '$a+=-s $_;END{print "$a\n"}'
2010-09-12 13:14:12
Functions: find perl
1

This deals nicely with filenames containing special characters and can deal with more files than can fit on a commandline. It also avoids spawning du.