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 using ls from sorted by
Terminal - Commands using ls - 469 results
ls /dev/disk* | xargs -n 1 -t sudo zdb -l | grep GPTE_
2012-10-06 20:19:45
User: grahamperrin
Functions: grep ls sudo xargs

Show the UUID-based alternate device names of ZEVO-related partitions on Darwin/OS X. Adapted from the lines by dbrady at http://zevo.getgreenbytes.com/forum/viewtopic.php?p=700#p700 and following the disk device naming scheme at http://zevo.getgreenbytes.com/wiki/pmwiki.php?n=Site.DiskDeviceNames

cd () { command cd $1 && ls ; }
ls -l | grep "\->"
2012-09-20 12:48:36
User: joernfranz
Functions: grep ls
Tags: readlink

Pretty lame to rely on grep and "\->"? Maybe. But it works ;)

ls -l /proc/*/fd/* | grep 'deleted'| grep "\/proc.*\file-name-part"
2012-09-13 09:54:16
User: totti
Functions: grep ls

Accidentally deleted some file while used by a program ? (Eg: a song)

Use this command to find the file handle and recover using

cp /proc/pid/fd/filehandle /new/recoverd-file.ext
ls -rt | tail -n 1
ln -s /base/* /target && ls -l /target
wget --no-use-server-timestamps $(curl $(curl http://wallbase.cc/random/23/eqeq/1920x1080/0/100/20 | grep 'wallpaper/' | awk -F'"' '{print $2}' | head -n1) | grep -A4 bigwall | grep img | awk -F'"' '{print $2}'); feh --bg-center $(ls -1t | head -n1)
alias ls='if [[ -f .hidden ]]; then while read l; do opts+=(--hide="$l"); done < .hidden; fi; ls --color=auto "${opts[@]}"'
2012-08-12 13:10:23
User: expelledboy
Functions: alias ls read
Tags: hidden ls alias

Sometimes I would like to see hidden files, prefix with a period, but some files or folders I never want to see (and really wish I could just remove all together).

ls | grep -Ze ".*rar" | xargs -d '\n' -I {} mv {} backup-folder
2012-08-06 09:07:03
User: crisboot
Functions: grep ls mv xargs

In the example suppose we want to move all *.rar files in the current folder to a backupfolder

ls -il; find * \( -type d -prune \) -o -inum <NUM> -exec rm -i {} \;
2012-08-04 00:22:33
User: yingw
Functions: find ls rm

Code to delete file with gremlins/special characters/unicode in file name.

Use ls -i to find the INODE number corresponding to the file and then delete it using that find statement.

detailed here:


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

ls *.png | while read line; do pngcrush -brute $line compressed/$line; done
2012-07-17 20:20:49
User: waffleboi9
Functions: ls read

Nothing too magical here, just uses pngcrush to losslessly compress all your pngs!

ls -al | sort +4n
2012-06-26 19:20:05
User: ankush108
Functions: ls sort
Tags: size sort files

ls -al gives all files, sort +4n sorts by 5th field numerically

ls -ltr |grep 'May 12'|awk '{print $9;}'|xargs rm -v
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
ls -l| sort +4n|tail -1| awk '{print $NF}'
ls -al | grep ^d
2012-05-21 17:39:23
User: christo
Functions: grep ls

Cleaner than adding -p to ls ( eg ls -alp ), this will tell ls to only output directories in the file listing, whilst maintaining all the usual other column elements of the ls output.

find -type l | xargs ls -l
ls "`defaults read com.apple.itunes NSNavLastRootDirectory`/iTunes/iTunes Music/Mobile Applications/" > filepath
ls "~/Music/iTunes/iTunes Media/Mobile Applications" > filepath
2012-05-04 09:51:59
User: minnmass
Functions: ls
Tags: ipad

This will generate the same output without changing the current directory, and filepath will be relative to the current directory.

Note: it will (still) fail if your iTunes library is in a non-standard location.

cd "~/Music/iTunes/iTunes Media/Mobile Applications";ls > filepath
ls -tl --time-style=full-iso
ls -l | sort +4n for ascending order or ls -l | sort +4nr for descending order
ls **/*.c(|pp)~(unit-test|android)/*