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.

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



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

All commands from sorted by
Terminal - All commands - 12,380 results
Printing portion of a big file
2009-03-30 11:08:38
User: acirulli
Tags: sed

If you need to print some portion of a huge file, let's say you want to print from line 200 to 300, you can use this command to print the line from LINE1 to LINE2 of file FILE.

pinfo date
2009-03-30 10:05:56
User: atoponce

The pinfo package makes info pages much more bearable. It is a ncurses-based POSIX utility for viewing info and man pages using lynx style keyboard shortcuts and rendering. Links are highlighted blue, the current location of your cursor is red. Navigating and searching are easy. Worth the install.

Convert UNIX time to human readable date
find ~/.thumbnails/ -type f -atime +30 -print0 | xargs -0 rm
2009-03-30 04:23:07
User: alperyilmaz
Functions: find xargs

By time thumbnail images in ~/thumbnails take up too much space, this command will help deleting old ones.

Find options explained:

-type f : find files only, not directories

-atime +30 : last accessed more than 30 days ago

alias up="cd .."; alias upp="cd ../.."; alias uppp="cd ../../.."; alias upppp="cd ../../../.."; alias uppppp="cd ../../../../.."
acpi -tc
watch -tn1 'bc<<<"`date -d'\''friday 21:00'\'' +%s`-`date +%s`"|perl -ne'\[email protected]=gmtime($_);printf("%dd %02d:%02d:%02d\n",@p[7,2,1,0]);'\'
2009-03-29 19:53:36
User: penpen
Functions: perl watch
Tags: Linux unix date

An improved version of http://www.commandlinefu.com/commands/view/1772/simple-countdown-from-a-given-date that uses Perl to pretty-print the output. Note that the GNU-style '--no-title' option has been replaced by its one-letter counterpart '-t'.

svn rm `svn status | grep "\!" | cut -c 8-`
2009-03-29 13:28:55
User: benschw
Functions: cut grep rm
Tags: svn

If (when) you forget to "svn rm" files from your repository, use this to let your repository know you want those files gone. Of course this works with adding and reverting too.

find /home/user/doc/ -type d -printf "mkdir -vp '/home/user/Dropbox%p'\n" -o -type f -printf "ln -vs '%p' '/home/user/Dropbox%p'\n" | sh
2009-03-29 09:25:12
User: jnash
Functions: find

Extremely useful to maintain backups if you're using Dropbox. This mirrors the entire directory structure and places symlinks in each to the original file. Instead of copying over the data again to the ~/Dropbox folder creating a symbolic link tree is much more sensible in terms of space usage.

This has to be supplemented by another script that removes dead symlinks in the Dropbox folder which point to files that have been moved/removed.

find -L ./ -type l -delete

And then removing empty directories

find ./ -type d -exec rmdir 2>/dev/null {} \;

**Actually after some finding I found lndir which creates symbolic trees but it wasn't in the Arch repos so.. ;)

yelp info:foo
yelp man:foo
2009-03-29 07:13:44
User: renich
Tags: man yelp

A great way of viewing some man page while using gnome.

sftp -s "sudo /usr/lib/sftp-server" [email protected]
2009-03-29 07:02:58
User: mrtheplague
Functions: sftp

This requires that your sudo not prompt for a password, as sftp cannot allocate the terminal necessary to ask.

watch --no-title -d -n 1 'echo `date -d "next Thursday" +%s` "-" `date +%s` | bc -l'
2009-03-29 06:53:09
User: jnash
Functions: bc watch

Might be more useful if you were able to print it in Days HH:MM:SS format as:

perl -e [email protected]=gmtime(234234);printf("%d Days %02d:%02d:%02ds\n",@p[7,2,1,0]);'

But I'm not exactly sure how to replace the 234234 with the output of the countdown time. (Having some problems with nested quoting/command substitution). Help would be appreciated :)

dscacheutil -flushcache
< /path/to/file.txt grep foo
2009-03-29 02:43:40
User: atoponce
Functions: grep

Several times, I find myself hitting my up arrow, and changing the search term. Unfortunately, I find myself wasting too much time typing:

grep kernel /var/log/messages

Redirecting STDIN allows me to put the search term at the end so I less cursor movement to change what I'm searching for:

< /var/log/messages grep kernel

If you're using the emacs keyboard binding, then after you press your up arrow, press CTRL+w to erase the word.

If this has already been submitted, I couldn't find it with the search utility.

rpm -q kernel-2* | grep -v $(uname -r) | xargs yum erase -y
2009-03-28 21:41:15
User: Nick
Functions: grep rpm uname xargs

On Fedora clean the boot directory; erase older kernel

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
2009-03-28 21:02:26
User: tiagofischer
Functions: awk cut netstat sort uniq

Here is a command line to run on your server if you think your server is under attack. It prints our a list of open connections to your server and sorts them by amount.

BSD Version:

netstat -na |awk '{print $5}' |cut -d "." -f1,2,3,4 |sort |uniq -c |sort -nr
dpkg --get-selections > LIST_FILE
2009-03-28 17:45:29
User: cammarin

This command is useful when you want to install the same packages on another fresh OS install for example. To do that, use:

sudo dpkg --set-selections < LIST_FILE
urpmi --auto-update --force # apply all pending updates (Mandriva Linux)
2009-03-28 14:59:26
User: mpb

Update a Mandriva Linux system with any pending updates.

This command needs to be run with root privilege.

Using the "--force" option answers "yes" to any interactive prompts

thus allowing the updates to be left unattended to completion.

NB if there is an update for glibc and/or a new kernel then the system

would need to be rebooted for these to take effect.

A prerequisite for running "urpmi --auto-update" is to have correctly defined

urpmi media sources (which can be done by visiting http://easyurpmi.zarb.org/).

If there are no new updates the the message "Packages are up to date" is shown.

awk '/start_pattern/,/stop_pattern/' file.txt
2009-03-28 14:28:59
User: atoponce
Functions: awk

I find this terribly useful for grepping through a file, looking for just a block of text. There's "grep -A # pattern file.txt" to see a specific number of lines following your pattern, but what if you want to see the whole block? Say, the output of "dmidecode" (as root):

dmidecode | awk '/Battery/,/^$/'

Will show me everything following the battery block up to the next block of text. Again, I find this extremely useful when I want to see whole blocks of text based on a pattern, and I don't care to see the rest of the data in output. This could be used against the '/etc/securetty/user' file on Unix to find the block of a specific user. It could be used against VirtualHosts or Directories on Apache to find specific definitions. The scenarios go on for any text formatted in a block fashion. Very handy.

mount.gmailfs none /mount/path/ [-o username=USERNAME[,password=PASSWORD][,fsname=VOLUME]] [-p]
2009-03-28 13:00:47
User: cammarin
Functions: mount
Tags: gmailfs fuse

Packages: gmailfs fuse-utils libfuse2 gvfs-fuse

Config files: /etc/gmailfs/gmailfs.conf; ~/.gmailfs.conf (make a copy from the another one)


fusermount -u /mount/path/

/etc/fstab (Optional):

none /mount/path/ gmailfs

noauto,user[,username=USERNAME,password=PASSWORD,fsname=VOLUME] 0 0


- The options between [] are optional since they already setuped on the config files.

- The '-p' flag shows a prompt for the password entry.

- It's necessary to add the user to the 'fuse' group. You can do that with:

sudo chgrp fuse /dev/fuse


sudo usermod -a -G fuse USER

- The volume name is not needed but highly recommended to avoid file corruption. Also choose a non-trivial name.

- Google doesn't approve the use of Gmail account other than e-mail purposes. So, I recommend the creation of a new account for this.

host -la domain.com
2009-03-28 12:15:16
Functions: host

Perform a dns zone transfer (if is allowed on target dns server) and print result.

2009-03-28 11:43:21
User: mpb

See: "man pwgen" for full details.

Some Linux distros may not have pwgen included in the base distribution

so you maye have to install it (eg in Mandriva Linux: "urpmi pwgen").

sudo firefox -install-global-extension /path/to/add-on
2009-03-28 11:11:12
User: cammarin
Functions: sudo
Tags: firefox

To install a theme use:

sudo firefox -install-global-theme /path/to/theme

You can get the .xpi or .jar file from the versions history on the add-on/theme page.

NOTE: may not work in your system (Debian-based is an example).