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,049 results
find . |xargs grep '<html\|<body\|<table' |sed '/~/d;s/:.*//' |sed 's/.*/mv & &.html/' |uniq >run.sh; sh run.sh
for a in $(find . -maxdepth 1 -name "*.mp4" -type f -printf "%f\n" | rev | cut -d '.' -f2- | rev | sort -u); do if [ ! -f "$a.mp3" ]; then avconv -i "$a."* -vn -ab 128 "$a.mp3"; fi done
2014-06-27 05:13:53
User: adanisch
Functions: cut find rev sort
0

Good for when you download youtube videos and want the mp3 for your mp3 player.

find . -type f -size +50000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
find -type f -exec bash -c 'if ffmpeg -i "{}" 2>&1 | grep -qi h264 ; then echo "{}"; fi' \;
find -type f -iregex '.*\.\(mkv\|mp4\|wmv\|flv\|webm\|mov\|dat\|flv\)' -print0 | xargs -0 mplayer -vo dummy -ao dummy -identify 2>/dev/null | perl -nle '/ID_LENGTH=([0-9\.]+)/ && ($t +=$1) && printf "%02d:%02d:%02d\n",$t/3600,$t/60%60,$t%60' | tail -n 1
2014-06-07 15:50:41
User: powerinside
Functions: find perl printf tail xargs
0

Use case insensitive regex to match files ending in popular video format extensions and calculate their total time. (traverses all files recursively starting from the current directory)

find . -type d -d 1 -print0 | xargs -0 du -sm | sort -nr
cd <mntpoint>; find . -xdev -size +10000000c -exec ls -l {} \; | sort -n -k 5
2014-05-20 14:13:54
User: deritchie
Functions: cd find ls sort
0

This is a quick way to find what is hogging disk space when you get a full disk alert on your

monitoring system. This won't work as is with filesystems that allow embedded spaces in user

names or groups (read "Mac OS X attached to a Windows Domain"). In those cases, you will need to change the -k 5 to something that works in your situation.

find . -name '*.phtml' | xargs perl -pi -e 's/(?!(<\?(php|xml|=)))<\?/<\?php/g;'
2014-05-07 14:33:19
User: crashspeeder
Functions: find perl xargs
1

Tired of front end developers using short open tags in your views? This will replace all instances of

find . -regex ".*\(avi\|mp4\|wmv\)$" -print0 | xargs -0 sha1sum
find . -exec rename 's/_/\ /g' {} +
2014-05-05 02:47:19
User: KlfJoat
Functions: find rename
1

Everyone wants to take spaces out of filenames. Forget that. I want to put them back in. We've got tools and filesystems that support spaces, they look better, so I'm going to use them.

Because of how find works I find I need to run this multiple times, if it's renaming subdirs. But it can be re-run without issues.

I got this version of the command from a comment in this underscore-generating command. http://www.commandlinefu.com/commands/view/760/find-recursively-from-current-directory-down-files-and-directories-whose-names-contain-single-or-multiple-whitespaces-and-replace-each-such-occurrence-with-a-single-underscore. All I did was change the regex.

find directory -type l -lname string
2014-05-02 14:44:24
User: gumption
Functions: find
Tags: find
1

Finds all symbolic links in the specified directory which match the specified string pattern.

I used this when upgrading from an Apple-supported version of Java 6 (1.6.0_65) to an Oracle-supported version (1.7.0_55) on Mac OS X 10.8.5 to find out which executables were pointing to /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands (Apple version) vs. /Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/bin (Oracle version). However, it appears the current JDK installation script already takes care of modifying the links.

find /some/directory/* -prune -type f -name *.log
2014-05-02 00:14:32
User: bigstupid
Functions: find
0

This find syntax seems a little easier to remember for me when I have to use -prune on AIX's find. It works with gnu find, too.

Add whatever other find options after -prune

for file in $(find . -name *.mp4); do ogv=${file%%.mp4}.ogv; if test "$file" -nt "$ogv"; then echo $file' is newer then '$ogv; ffmpeg2theora $file; fi done
find . -name \*.svg -print0 | xargs -0 -n1 -P4 -I{} bash -c 'X={}; convert "$X" "${X%.svg}.png"'
2014-04-11 14:30:30
User: flatcap
Functions: bash find xargs
2

Convert some SVG files into PNG using ImageMagick's convert command.

Run the conversions in parallel to save time.

This is safer than robinro's forkbomb approach :-)

xargs runs four processes at a time -P4

find -type f -exec grep -q "regexp" {} \; -delete
2014-04-06 19:06:50
User: gumnos
Functions: find grep
Tags: find grep
3

Deletes files in the current directory or its subdirectories that match "regexp" but handle directories, newlines, spaces, and other funky characters better than the original #13315. Also uses grep's "-q" to be quiet and quit at the first match, making this much faster. No need for awk either.

find . | xargs grep -l "FOOBAR" | awk '{print "rm -f "$1}' > doit.sh
2014-04-06 15:48:41
User: sergeylukin
Functions: awk find grep xargs
Tags: awk find grep
-3

After this command you can review doit.sh file before executing it.

If it looks good, execute: `. doit.sh`

for output in $(find . ! -name movie.nfo -name "*.nfo") ; do rm $output ; done
2014-04-01 17:41:50
User: analbeard
Functions: find rm
-1

Finds all nfo files without the filename movie.nfo and deletes them.

find directory -maxdepth 1 -iname "*" | awk 'NR >= 2'
2014-04-01 00:09:12
User: chilicuil
Functions: awk find
-3

find . -maxdepth 1 -iname ".*" | awk 'NR >= 2'

Can be used to list only dotfiles without . nor ..

find . -name '*.mp3' | sort | while read -r mp3; do echo -e "<h3>$mp3</h3>\n<audio controls src=\"$mp3\"></audio>"; done > index.html; python -m http.server
2014-03-24 15:01:49
User: hendry
Functions: echo find python read sort
Tags: audio browser
1

I tried a few curses based mp3 players for playing back choir practice songs for my wife.

Unfortunately none of the ones I tried were capable of scrubbing a track.

Firefox saves the day.

dmesg | grep -Po 'csum failed ino\S* \d+' | awk '{print $4}' | sort -u | xargs -n 1 find / -inum 2> /dev/null
2014-03-22 12:22:46
User: Sepero
Functions: awk dmesg find grep sort xargs
Tags: find inode btrfs
1

Btrfs reports the inode numbers of files with failed checksums. Use `find` to lookup the file names of those inodes. The files may need to be deleted and replaced with backups.

find ./ -type l -ls
find ./ -type l -print0 | xargs -0 ls -plah
2014-03-20 20:36:39
Functions: find ls xargs
0

shows you the symlinks in the current directory, recursively, but without following them

dmesg | grep -Po 'csum failed ino\S* \d+' | sort | uniq | xargs -n 3 find / -inum 2> /dev/null
2014-03-20 06:27:15
User: Sepero
Functions: dmesg find grep sort uniq xargs
Tags: find inode btrfs
-1

Btrfs reports the inode numbers of files with failed checksums. Use `find` to lookup the file names of those inodes.

dsquery computer DC=example,DC=com -limit 150 | find /c /v ""
find . -name "*.txt" -exec WHATEVER_COMMAND {} \;