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





All commands from sorted by
Terminal - All commands - 12,274 results
function t { ls -ltch $* | head -20 ; }
2009-03-25 20:05:52
User: totoro
Functions: head ls

Coming back to a project directory after sometime elsewhere?

Need to know what the most recently modified files are?

This little function "t" is one of my most frequent commands.

I have a tcsh alias for it also:

alias t 'ls -ltch \!* | head -20'

find . -type f -depth -3 -mtime -5
2009-03-25 19:54:06
User: totoro
Functions: find

Ever wanted to find the most recently modified files, but couldn't remember exactly where they were in a project directory with many subdirectories? The "find" command, using a combination of "-mtime -N" and "-depth -D" can be used to find those files. If your directory structure isn't very deep, just omit the "-depth -D", but if your directory structure is very deep, then you can limit the depth of the traversal using "-depth -D", where "D" is the maximum number of directory levels to descend.

perl -e 'print scalar localtime $ARGV[0],"\n" ' epoch
du -hS / | perl -ne '(m/\d{3,}M\s+\S/ || m/G\s+\S/) && print'
2009-03-25 18:06:53
User: Alioth
Functions: du perl

Finds all directories containing more than 99MB of files, and prints them in human readable format. The directories sizes do not include their subdirectories, so it is very useful for finding any single directory with a lot of large files.

curl -i -X HEAD http://localhost/
rpm -q --qf "%{VERSION}\n" redhat-release
2009-03-25 16:46:14
User: atoponce
Functions: rpm

In this case, I'm getting the package version for 'redhat-release', but of course, this can be applied to any package installed on the filesystem. This is very handy in scripts that need to determine just the version of the package, without the package name and all the sed and grep hackery to get to the data you want. To find out all the support format strings that 'rpm --qf' supports:

rpm --querytags
find /proc -regex '/proc/[0-9]+/smaps' -exec grep -l "$PATH_REGEX" {} \; | cut -d'/' -f2
2009-03-25 16:33:44
User: juddmaltin
Functions: cut find grep

faster than lsof by at least x2 on my box.

rm -rf `find . -type d -name .svn`
wc -l `find . -name *.php`
find . -wholename './.snapshot' -prune -o -print
2009-03-25 13:52:01
User: jeffaz
Functions: find

This can be useful for those who have mounted NetApp file-systems with snapshot activated.

netstat -antuwp | egrep "(^[^t])|(^tcp.*LISTEN)"
test.bat parm1 parm2 parm3
2009-03-25 12:27:18
User: lansa
Functions: test

I am using .bat commands to execute Curl commands for Twitter API

wget -q http://xyz.gpg -O- | sudo apt-key add -
2009-03-25 12:18:36
User: gnuyoga
Functions: sudo wget
Tags: wget apt-key

when we add a new package to a aptitude (the debian package manager) we need to add the gpg, otherwise it will show warning / error for missing key

wget -q http://xyz.gpg -O- | sudo apt-key add -
2009-03-25 12:18:29
User: gnuyoga
Functions: sudo wget
Tags: apt-key

when we add a new package to a aptitude (the debian package manager) we need to add the gpg, otherwise it will show warning / error for missing key

echo "obase=2; 27" | bc -l
2009-03-25 09:54:50
User: polar
Functions: bc echo
Tags: bc

Easily convert numbers to their representations in different bases. Passing

"ibase=16; obase=8; F2A"

to bc will convert F2A (3882 in decimal) from Hex to Octal, and so on.

arp -s $(route -n | awk '/^ {print $2}') \ $(arp -n | grep `route -n | awk '/^ {print $2}'`| awk '{print $3}')
echo "$math_expr" | bc -l
2009-03-25 09:46:01
User: polar
Functions: bc echo
Tags: bc

Useful for quick calculations at the command line. $math_expr is any arithmetic expression (see sample output):



More options in the bc man page.

ls /some/directory | sed -rn -e 's/input_file_regex/mv -v & output_file_name/p' | sh
2009-03-25 09:20:15
User: polar
Functions: ls sed
Tags: bash sed

Allows for quick mass renaming, assuming the user has some familiarity with regular expressions. Basically, it replaces the original_file_name in the output of ls with

"mv -v original_file_name new_file_name"

and passes the output to sh.

alias showip="ifconfig eth0 | grep 'inet addr:' | sed 's/.*addr\:\(.*\) Bcast\:.*/\1/'"
2009-03-25 07:50:12
User: dizzgo
Functions: alias
Tags: ifconfig alias IP

parses the output of ifconfig to show only the configured ip address (in this case from interface eth0).

the regexp is quick'n'dirty im sure it can be done in a better way.

--> this alias does not show your "internet ip" when you're in a nat-environment

cdrecord -v dev=/dev/cdrom yourimage.iso
2009-03-25 07:31:54
User: dizzgo
Functions: cdrecord

cdrecord must be installed.

usefull alias:

alias burniso='cdrecord -v dev=/dev/cdrom'

now iso burning is like.

burniso image.iso
2009-03-25 07:25:33
User: dizzgo
Tags: Ubuntu

release upgrades are major upgrades as from 8.04 to 8.10 or from 8.10 to 9.04

update-manager-core must be installed:

sudo apt-get install update-manager-core

in some cases you must edit '/etc/update-manager/release-upgrades' and set 'Prompt=normal'

gs -sDEVICE=pswrite -sOutputFile=- -q -dNOPAUSE With-Fonts.pdf -c quit | ps2pdf - > No-Fonts.pdf
2009-03-25 03:46:00
User: qubyte
Functions: gs

It's sometimes useful to strip the embedded fonts from a pdf, for importing into something like Inkscape. Be warned, this will increase the size of a pdf substantially.

I tried this with only gs writing with -sDEVICE=pdfwrite but it doesn't seem to work, so I just pipe postscript output to ps2pdf for the same effect.

swapoff -a ; swapon -a
2009-03-25 03:30:41
User: alperyilmaz
Functions: swapoff swapon
Tags: swapoff swapon

When you run a memory intensive application (VirtualBox, large java application, etc) swap area is used as soon as memory becomes insufficient. After you close the program, the data in swap is not put back on memory and that decreases the responsiveness. Swapoff disables the swap area and forces system to put swap data be placed in memory. Since running without a swap area might be detrimental, swapon should be used to activate swap again.

Both swapoff and swapon require root privileges.

watch -n 7 -d 'uptime | sed s/.*users,//'
2009-03-25 02:52:36
User: detert
Functions: sed watch

helps you keep watch on the load of a system, without having to stare constantly at the terminal. The -d argument to watch highlights the difference from the last run, making it easier to note how the load is fluctuating. The sed command just strips off the information about how long the box has been up, and how many users are logged in.

mount -t smbfs //$server/share /local/mount -o rw,username=$USER
2009-03-25 01:05:17
User: sufoo
Functions: mount

Mount an smb share with this command. other options -ousername=$USERr,gid=$groupname,scope=rw