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 using ls from sorted by
Terminal - Commands using ls - 461 results
touch file{1..10}.txt ; ls *txt| sed -e "p;s/\.txt$/\.csv/"|xargs -n2 mv
for x in `ps -u 500 u | grep java | awk '{ print $2 }'`;do ls /proc/$x/fd|wc -l;done
cd $(ls -1 | sed -n '<N>p')
for i in `pfiles pid|grep S_IFREG|awk '{print $5}'|awk -F":" '{print $2}'`; do find / -inum $i |xargs ls -lah; done
2013-01-24 13:57:19
User: giorger
Functions: awk find grep ls xargs

Executing pfiles will return a list of all descriptors utilized by the process

We are interested in the S_IFREG entries since they are pointing usually to files

In the line, there is the inode number of the file which we use in order to find the filename.

The only bad thing is that in order not to search from / you have to suspect where could possibly be the file.

Improvements more than welcome.

lsof was not available in my case

ls -lhR | grep -e "total\|:$"
2013-01-22 04:58:51
User: Sebasg
Functions: grep ls
Tags: ls grep

ls -lhR

Lists everithing using -l "long listing format" wich includes the space used by the folder. Displays it in -h "human readable form" (i.e. 2.2G, 32K), and -R recurses subfolders.

grep -e using a regex, show lines containing the word "total" or a ":" at the end of the line (those with the name of the folder) only.

ls | wc -l
2013-01-22 03:35:35
User: Sebasg
Functions: ls wc

ls -1 shows one file per line (update: -1 was not really needed)

wc -l counts the lines received from the previous command

ls -l /dev/disk/by-id/ | grep '/sda$' | grep -o 'ata[^ ]*'
2013-01-16 17:28:11
User: michelsberg
Functions: grep ls
Tags: ls grep drive

Substitute for #11720

Can probably be even shorter and easier.

man ls | egrep "^([A-Z]| [A-Z])"
2013-01-09 17:12:03
User: bartonski
Functions: egrep ls man

Uses the formatting of a man page to show an outline of its headers and sub-headers.

ls -l /dev/disk/by-id | egrep ata-.*`hdparm -i /dev/sda | grep SerialNo | sed 's/.*SerialNo=//' | tr -d "\n"`.*sda$ | sed -e 's/.*ata-/ata-/' -e 's|[ ].*||' | tr -d "\n"
2013-01-07 10:20:25
Functions: egrep grep ls sed tr
Tags: Ubuntu

This was tested on Ubuntu 12.04 (Precise) LTS Server. It returns the name of the symlink within /dev/disk/by-id for the physical drive you specify. Change /dev/sda to the one you want, and replace ata- with scsi- or the appropriate type for your drive.

I used this to pre-configure grub-pc during a non-interactive install because I had to tell it which disk to install grub on, and physical disks don't have a UUID such as that blkid provides.

ls -lSr
ls -l !(*.part)
2012-12-07 23:07:53
User: quacky
Functions: ls

works nice if you're only interested in files that are completed downloading from a torrent

ls -altr | grep ^d
for I in $(find . -depth -type d -not -path "*/.svn*" -print) ; do N="$(ls -1A ${I} | wc -l)"; if [[ "${N}" -eq 0 || "${N}" -eq 1 && -n $(ls -1A | grep .svn) ]] ; then svn rm --force "${I}"; fi ; done
find / -xdev \( -perm -4000 \) -type f -print0 | xargs -0 ls -l
ls /var/log/sa/sa[0-9]*|xargs -I '{}' sar -u -f {}|awk '/^[0-9]/&&!/^12:00:01|RESTART|CPU/{print "%user: "$4" %system: "$6" %iowait: "$7" %nice: "$5" %idle: "$9}'|sort -nk10|head
ls /var/log/sa/sa[0-9]*|xargs -I '{}' sar -q -f {}| awk '/Average/'|awk '{runq+=$2;plist+=$3}END{print "average runq-sz:",runq/NR; print "average plist-sz: "plist/NR}'
ls|wc -l
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).