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,364 results
tree -d
2009-10-10 21:40:56
User: bsussman

tree has lots of parms - man is your friend

find / -name FILENAME
find . -type d -print | sed -e 's;[^/]*/;..........;g'|awk '{print $0"-("NR-1")"}'
:set scroll=0
2009-10-10 07:38:27
User: tmsh

Resets the scroll parameter to the default (half the rows in the current window). The scroll parameter can be inadvertently set to 1, e..g., if you type '1 Ctrl-D' or '1 Ctrl-U' in normal mode.

( trap '' 1; ( nice -n 19 sleep 2h && command rm -v -rf /garbage/ &>/dev/null && trap 1 ) & )

Check out the usage of 'trap', you may not have seen this one much. This command provides a way to schedule commands at certain times by running them after sleep finishes sleeping. In the example 'sleep 2h' sleeps for 2 hours. What is cool about this command is that it uses the 'trap' builtin bash command to remove the SIGHUP trap that normally exits all processes started by the shell upon logout. The 'trap 1' command then restores the normal SIGHUP behaviour.

It also uses the 'nice -n 19' command which causes the sleep process to be run with minimal CPU.

Further, it runs all the commands within the 2nd parentheses in the background. This is sweet cuz you can fire off as many of these as you want. Very helpful for shell scripts.

ps -ef | grep pmon
find . -type f -printf "%h\n" | cut -d/ -f-2 | sort | uniq -c | sort -rn
2009-10-09 23:49:53
User: ivancho
Functions: cut find sort uniq
Tags: file count

counts the total (recursive) number of files in the immediate (depth 1) subdirectories as well as the current one and displays them sorted.

Fixed, as per ashawley's comment

2009-10-09 21:39:35

arping sends ARP requests to a neighboring host. This won't work if there is an ARP subnet gateway in the middle. If there is, you'll just get the gateway's MAC address not the host's address you are really trying to get to.

watch -n60 du /var/log/messages
2009-10-09 18:37:45
User: matrixguy
Functions: du watch

use "watch" instead of while-loops in these simple cases

while [ 1 ]; do du /var/log/messages;sleep 60; done
2009-10-09 17:22:19
User: savanik
Functions: du

Got a file you're generating and you want the size without typing in 'ls -l file' all the time? Use this instead.

head -c10 <(echo $RANDOM$RANDOM$RANDOM)
2009-10-09 15:09:02
User: jgc
Functions: echo head
Tags: HEAD random

Makes use of $RANDOM environment variable.

if [ "$testnum" -eq "$testnum" 2>/dev/null ]; then echo It is numeric; fi
2009-10-09 14:57:27
User: jgc
Functions: echo

Using the standard numeric comparison but suppressing the STDERR output acts as the simplest way to check a value is numeric. See sample output for some examples.

echo $X | egrep "^[0-9]+$"
tr -c -d 0-9 < /dev/urandom | head -c 10
netstat -an|grep -ci "tcp.*established"
2009-10-09 01:08:18
User: romulusnr
Functions: grep netstat

If you want prepend/append text just wrap in echo:

echo Connected: `netstat -an|grep -ci "tcp.*established"`
for USER in `ls /var/spool/cron`; do echo "=== crontab for $USER ==="; echo $USER; done
grep $'\t' file.txt
2009-10-08 23:06:00
User: felix001

Shows the status of SElinux.

-- fir3net.com --

ls -d */
2009-10-08 22:07:22
User: brianmuckian
Functions: ls

-d: list directory entries instead of contents, and do not dereference symbolic links

rm ~/.bash_history; ln -s /dev/null ~/.bash_history
2009-10-08 17:40:48
Functions: ln rm

Remove your BASH history and then link it to /dev/null

tput smcup; echo "Doing some things..."; sleep 2; tput rmcup
2009-10-08 16:48:04
User: jgc
Functions: echo sleep tput

Very useful for interactive scripts where you would like to return the terminal contents to its original state before the script was run. This would be similar to how vi exits and returns you to your original terminal screen.

Save and clear the terminal contents with:

tput smcup

Execute some commands, then restore the saved terminal contents with:

tput rmcup
ls -F|grep /
2009-10-08 16:35:15
User: romulusnr
Functions: grep ls

No need for -l and the output can be sent directly into another function expecting directory names.

perl -pi -e 's/([[:lower:]]+)/uc $1/gsex' file
2009-10-08 14:18:50
Functions: perl
Tags: perl

same, except it works on any OS with Perl installed. DOS, Windose, whatever

export HISTFILE=/dev/null && kill -9 $$
rm ~/.bash_history && kill -9 $$
2009-10-08 12:25:47
User: Velenux
Functions: kill rm

Best way I know to get rid of .bash_history and don't allow bash to save the current one on exit

Edit: added ~/ before .bash_history, just in case... ;)