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,379 results
ls -1 | rename 's/\ /_/'
2009-03-17 17:33:41
Functions: ls rename

Substitute spaces in filename with underscore, it work on the first space encountered.

for i in `find /sys/devices/*/*/usb* -name level` ; do echo -n "$i: " ; cat $i ; done
rpm -qa --queryformat '%{installtime} \"%{vendor}\" %{name}-%{version}-%{release} %{installtime:date}\n' | grep "Thu 05 Mar"
2009-03-17 13:38:20
User: mpb
Functions: grep rpm

Find out which RPMs were installed on a particular date.

These would (naturally) include update RPMs.

This example shows searching for "Thu 05 Mar" (with grep).

Alternatively, pipe it to less so you can search inside less (with less's neat text highlighting of the search term):

rpm -qa --queryformat '%{installtime} \"%{vendor}\" %{name}-%{version}-%{release} %{installtime:date}\n' | less # (this example) search term: Thu 05 Mar

play $audio_file
2009-03-17 11:30:02
User: mpb

"play" is part of "SoX"

SoX - Sound eXchange, the Swiss Army knife of audio manipulation.

For details, see: man sox

find -maxdepth 1 -type d -print0 | xargs -0 -I {} tar -cvzf {}.tar.gz {}
2009-03-17 11:12:53
User: piemme
Functions: find tar xargs

Create backup (.tar.gz) for all first-level directory from current dir.

lynx -accept_all_cookies -cmd_script=/your/keystroke-file
2009-03-17 00:38:36
User: Alanceil

This command will tell lynx to read keystrokes from the specified file - which can be used in a cronjob to auto-login on websites that give you points for logging in once a day *cough cough* (which is why I used -accept_all_cookies).

For creating your keystroke file, use:

lynx -cmd_log yourfile
:!cp % %-
2009-03-17 00:34:24
User: mpb

At the start of a vi session and *before* saving any changes use ":!cp % %-" to make a backup of the current file being edited.

example: vi /data/some/long/path/file

:!cp% %-

creates /data/some/long/path/file-

# indicates a comment in shell
2009-03-16 23:15:33
User: mpb

Using the "#" in shell is surprisingly useful.

Some of the uses I found:

a) As a visible copy buffer in shell history (caveat: do not use for passwords :-)

b) To build complex commands until ready then hit the HOME, DEL, ENTER keys to run it

c) Placing reference data into shell history (search for tags with CTRL-R TAGNAME)

d) Putting aside a "work in progress" command to focus on another task (HOME # ENTER)

2009-03-16 20:58:31
User: mallegonian
Tags: bash hotkey

Hold ctrl and press z to pause the current thread. Run


to resume it.

convert -font -misc-fixed-*-*-*-*-*-*-*-*-*-*-*-* -fill black -draw "text 270,260 \" `cal` \"" testpic.jpg newtestpic.jpg
2009-03-16 16:09:58
User: dasmna
Tags: ImageMagick

Add calendar to desktop wallpaper , mess with the coordinates to place where you like

alias lvim="vim -c \"normal '0\""
cp ./* .[!.]* ..?* /path/to/dir
2009-03-16 13:27:36
User: ako
Functions: cp

./* is for copying files starting with -

.[!.]* is for copying hidden files and avoiding copying files from the parent directory.

..?* is for copying files starting with .. (avoids the directory ..)

/path/to/dir the path to the directory where the files should be copied

Can also be used as a script. Input argument is /path/to/dir

in tcsh, replace .[!.]* with .[^.]*

ffmpeg -vcodec copy -acodec copy -i orginalfile -ss 00:01:30 -t 0:0:20 newfile
2009-03-16 12:58:07
User: ako


-vcodec, you choose what video codec the new file should be encoded with. Run ffmpeg -formats E to list all available video and audio encoders and file formats.

copy, you choose the video encoder that just copies the file.

-acodec, you choose what audio codec the new file should be encoded with.

copy, you choose the audio encoder that just copies the file.

-i originalfile, you provide the filename of the original file to ffmpeg

-ss 00:01:30, you choose the starting time on the original file in this case 1 min and 30 seconds into the film

-t 0:0:20, you choose the length of the new film

newfile, you choose the name of the file created.

Here is more information of how to use ffmpeg:


detox -r -s utf_8 /path/to/old/win/files/dir
2009-03-16 07:50:36
User: renich
Tags: ut

This command is a powerful "detoxifier" that eliminates special chars, spaces and all those little chars we don't like. It support several "sequences" so be sure to check your /usr/local/etc/detoxrc while at it... and maybe define your own

cat count.txt | awk '{ sum+=$1} END {print sum}'
2009-03-16 00:22:13
User: duxklr
Functions: awk cat
Tags: awk

Takes a input file (count.txt) that looks like:






It will add/sum the first column of numbers.

less textfile.gz
2009-03-15 23:51:17
User: allbad
Functions: less

There is no need to 'zcat textfile.gz | less' with newer distros. This is useful for reading archived log files without having to extract, read, and zip when done.

openssl pkcs12 -export -in /dir/CERTIFICATE.pem -inkey /dir/KEY.pem -certfile /dir/CA-cert.pem -name "certName" -out /dir/certName.p12
less file.tar.gz
2009-03-15 23:00:05
User: allbad
Functions: less

This will print out the files and directories in a gzipped tarball.

rpm -qa --qf '%{SIZE} %{NAME}\n' | sort -nr | nl | head -6 # six largest RPMs
2009-03-15 22:18:17
User: mpb
Functions: head nl rpm sort

Low on disk space? Check the largest installed RPMs for delete canditates.

ls -1 | grep " " | awk '{printf("mv \"%s\" ",$0); gsub(/ /,"_",$0); printf("%s\n",$0)}' | sh # rename filenames: spaces to "_"
2009-03-15 18:42:43
User: mpb
Functions: awk grep ls rename sh

This command converts filenames with embedded spaces in the current directory replacing spaces with the underscore ("_") character.

echo "encryptedpassword"|openssl passwd -1 -stdin
for name in larry moe schemp; do useradd $name; echo 'password' | passwd --stdin $name; chage -d 0 $name; done
2009-03-15 12:02:39
User: atoponce
Functions: chage echo passwd useradd

This command is a bit Linux specific, as --stdin doesn't exist for passwd on many Unix machines. Further, useradd is high level in most distributions and Unix derivatives except for the Debian family of distros, where adduser would be more appropriate. The last bit, with chage, will force the user to change their password on new login.

gcal -K -q GB_EN 2009 # display holidays in UK/England for 2009 (with week numbers)
2009-03-15 10:19:52
User: mpb

NB when you run this gcal command in your shell, holidays are highlighted

but this highlighting does not show in the sample output (above).

To find full details on gcal options: gcal --long-help | less

Example for United States, Pennsylvania:

gcal -K -q US_PA 2009 # display holidays in USA/Pennsylvania for 2009 (with week numbers)

Example for Hong Kong:

gcal -K -q HK 2009 # display holidays in Hong Kong for 2009 (with week numbers)

sort file1.txt | uniq > file2.txt
2009-03-14 03:39:32
User: atoponce

'visudo' is installed by default on most Unix-like systems. If not installed, you can get it from the 'sudo' package. 'visudo' will use the text editor found in your $EDITOR variable, whether it's vi, vim, emacs, nano or gedit. After making changes to the /etc/sudoers file, visudo will check for syntax errors, and notify you of them. This is better than 'vi /etc/sudoers', because of this capability. Rule #1 of system administration- if there is a tool that exists for editing config files, use the tool.