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,273 results
ntpdate ntp.ubuntu.com pool.ntp.org
ls -l | sort -nk5
'ALT+.' or '<ESC> .'
2009-03-20 11:36:04
User: atoponce

When typing out long arguments, such as:

cp file.txt /var/www/wp-content/uploads/2009/03/

You can put that argument on your command line by holding down the ALT key and pressing the period '.' or by pressing <ESC> then the period '.'. For example:

cd 'ALT+.'

would put '/var/www/wp-content/uploads/2009/03/ as my argument. Keeping pressing 'ALT+.' to cycle through arguments of your commands starting from most recent to oldest. This can save a ton of typing.

ropened='p4 opened | awk -F# "{print \$1}" | p4 -x - revert'
alias opened='p4 opened | awk -F# "{print \$1}"'
2009-03-20 11:06:41
User: Alexander
Functions: alias awk
Tags: p4 SCM Perforce

Just type 'opened' and get all files currently opened for edit.

date --date=yesterday
alias pst='pstree -Alpha'
2009-03-20 10:53:37
User: Alexander
Functions: alias
Tags: Linux

By 'pst' you can print out process tree with all details about all processes (including a command line, PID, and the current process you are running in).

By 'pst username' you can get an information about processes belonging to the particular user 'username'.

alias ..='cd ..'
2009-03-20 09:57:28
User: eimantas
Functions: alias
Tags: bash unix shell cd

Alias two dots to move to parent directory. Put it into your .bashrc or .profile file.

$mkdir mydir -> mv !$ yourdir -> $cd !$
if [ "${vote}" = "down" ]; then echo leave comment; fi
2009-03-20 00:31:13
Functions: echo

I think it would be wise if anyone voting down left a comment indicating the reason for that action. Don't keep it to yourself. Thanks.

cmp -l file1.bin file2.bin | wc -l
( IFS=:; for p in $PATH; do echo $p; done )
2009-03-19 22:45:47
User: haivu
Functions: echo
Tags: bash

The output of "echo $PATH" is hard to read, this is much easier. The parentheses ensure that the change to the input field separator (IFS) only happens the the sub shell and not affecting the current shell.

PLAYLIST=$(ls -1) ; mpg123 -C $PLAYLIST
2009-03-19 17:20:28
Functions: ls mpg123

On my music directory, I create variable that contains all mp3s files, then I play them with mpg123. -C options enable terminal control key, s for stop, p for pause, f for forward to next song.

echo 'loginname ALL=(ALL) ALL' >> /etc/sudoers
2009-03-19 13:23:43
User: refrax
Functions: echo

I am new to linux, and I was trying to figure out why I could not sudo with my username in Fedora 10. This command, when run as root, will add a line to the sudoers file allowing the loginname supplied to sudo. The above line will require a password when you sudo, if you wish to sudo without password, use:

echo 'loginname ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

instead. you have to run this command as su, and this is just an easier way of using visudo, just adds it right from the terminal.

# wc -l /var/log/security/writable.today
2009-03-19 12:25:52
User: mpb
Functions: wc

Mandriva Linux includes a security tool called "msec" (configurable via "draksec").

One of the many things it regularily checks for is world writeable files.

If any are found, it writes the list to /var/log/security/writable.today.

"wc -l" simply counts the number of lines in the file.

This number should be low.

Browse through /var/log/security/writable.today and consider if any of those files *need* to be world-writeable (and if not, modify the permissions. eg: "chmod o-w $file").

A large number of world-writeable files may indicate that umask is not correctly set in /etc/profile (or ${HOME}/.bash_profile) but could also indicate poor security configuration or even malicious activity.

history | perl -lane '$lsize{$_} = scalar(@F); if($longest<$lsize{$_}) { $longest = $lsize{$_}; print "$_"; };' | tail -n1
vi ~/journal/$(date +%F)
2009-03-18 23:31:13
User: ar
Functions: date vi


mkdir ~/journal
export PS1='\[\033[0;35m\]\h\[\033[0;33m\] \w\[\033[00m\]: '
2009-03-18 22:05:48
User: kamiller
Functions: export
Tags: color prompt

It colors the machine name and current directory different colors for easy viewing.

eject -x 4
2009-03-18 16:25:11
User: mrttlemonde
Functions: eject

Decreasing the cdrom device speed may be more comfortable to watch films (for example)

echo "- - -" > /sys/class/scsi_host/host0/scan
2009-03-18 15:26:42
User: angrox
Functions: echo

Issues a scan command on the given scsi host adapter (ex. a fibre channel adapter, in the example above on host0). Output can be watched in the messages log or in "dmesg"

rpm -qa --queryformat "%{NAME} %{ARCH}\n"
2009-03-18 15:19:21
User: angrox
Functions: rpm

Lists all installed RPM packages with name and architecture, which is useful to check for compability packages (+ required i386 packages) on a 64bit system.

^[c (ctrl-v esc-c)
2009-03-18 15:15:24
User: angrox

Resets a scrambled terminal into its orignal state.

echo '123/7' |bc -l |xargs printf "%.3f\n"