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.


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:



2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.




All commands from sorted by
Terminal - All commands - 11,485 results
mencoder -ovc copy -oac copy -of avi -o remuxed.avi original.avi
2009-03-23 10:15:36
User: iain

When playback of AVI files (containing a video format like XviD or DivX) is stuttering, it in 90% of the files is caused by a poorly or wrongly interleaved file. The issue can be permanently resolved by RE-MUXING the AVI video-files that have this problem

vimdiff file{1,2}
2009-03-23 10:08:16
User: H4rpy

vim will open both files side by side and show colored diffs

gst-launch v4l2src
2009-03-23 05:45:00
User: samliu

Cheese or other webcam software not working? Try this.

ls | while read ITEM; do echo "$ITEM"; done
2009-03-22 23:33:13
User: fletch
Functions: echo ls read
Tags: bash

If you want to operate on a set of items in Bash, and at least one of them contains spaces, the `for` loop isn't going to work the way you might expect. For example, if the current dir has two files, named "file" and "file 2", this would loop 3 times (once each for "file", "file", and "2"):

for ITEM in `ls`; do echo "$ITEM"; done

Instead, use a while loop with `read`:

ls | while read ITEM; do echo "$ITEM"; done
svn status app/models/foo.rb; svn commit -m "Changed file" !$
2009-03-22 23:14:06
User: ggoodale

After a command is run in bash, !$ is set to the last (space-delimited) argument of the command. Great for running several commands against the same file in a row.

for f in `find . \( ! -name . -prune \) -type d -print`; do zip $f.zip $f; done
2009-03-22 22:33:46
User: njoubert

Creates a zip file out of each subdirectory in a directory. Great if you have 40 000+ text files in folders, and you want to stick it in SVN without the hours of uploading while retaining some level of version control.

find . -name "*.EXT" | xargs grep -n "TODO" | wc -l
grep '' -m X file1 > file2
2009-03-22 04:34:43
User: sardanapalos
Functions: grep

It extracts X number of lines from file1 and dumps them to file2.Using grep with the empty string '' extracts the complete lines (i.e. no filtering takes place) and the -m flag indicates how many lines to extract out from the given file. Then using the redirect > operator we send the extracted lines to a new file.

for i in {1..15}; do echo $i; done
2009-03-21 23:08:41
User: haivu
Functions: echo
Tags: bash

The brace expansion also allows you to count backward:

for i in {15..1}; do echo $i; done

You can also use this construct to create new file or new directory:

mkdir dir{1..3} # Same as mkdir dir1 dir2 dir3

mysql --database=dbname -B -N -e "SHOW TABLES" | awk '{print "ALTER TABLE", $1, "CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"}' | mysql --database=dbname &
2009-03-21 18:45:15
User: root
Functions: awk
Tags: mysql

This loops through all tables and changes their collations to UTF8. You should backup beforehand though in case some data is lost in the process.

watch -n 1 uptime\;myqladmin --user=<user> --password=<password> --verbose processlist
2009-03-21 18:29:28
User: root
Functions: watch
Tags: mysql

Useful for monitoring both MySQL and the server load at the same time.

cat file.txt | sort | uniq -dc
2009-03-21 18:15:14
User: Vadi
Functions: cat sort uniq

Displays the duplicated lines in a file and their occuring frequency.

j mp3
sudo zcat /var/log/auth.log.*.gz | awk '/Failed password/&&!/for invalid user/{a[$9]++}/Failed password for invalid user/{a["*" $11]++}END{for (i in a) printf "%6s\t%s\n", a[i], i|"sort -n"}'
2009-03-21 06:41:59
Functions: awk printf sudo zcat

Show the number of failed tries of login per account. If the user does not exist it is marked with *.

echo 'wget url' | at 01:00
2009-03-21 06:19:40
User: Vlad003
Functions: at echo

Replace "url" with the correct address of what your're downloading. Replace 01:00 with what time you want. (24-hour clock).

cat /proc/acpi/battery/BAT1/info
2009-03-21 06:09:37
User: Vlad003
Functions: cat
Tags: bash battery

Displays all information about your battery. for just capacity, try replacing cat with

grep -F capacity:

Battery number might be BAT0 instead of BAT1. Just run

cd /proc/acpi/battery; ls

and find out what folder is in that directory and replace that name with BAT1

ls -hog
2009-03-21 05:24:49
User: haivu
Functions: ls
Tags: shell

I often deal with long file names and the 'ls -l' command leaves very little room for file names. An alternative is to use the -h -o and -g flags (or together, -hog).

* The -h flag produces human-readable file size (e.g. 91K instead of 92728)

* The -o suppresses the owner column

* The -g suppresses the group column

Since I use to alias ll='ls -l', I now do alias ll='ls -hog'

time read (ctrl-d to stop)
2009-03-20 22:50:06
User: mrttlemonde
Functions: read time

time read -sn1 (s:silent, n:number of characters. Press any character to stop)

ls -1 static/images/ | while read line; do echo -n $line' '[; grep -rc $line *|grep -v ".svn"|cut -d":" -f2|grep -vc 0| tr "\n" -d; echo -n ]; echo ; done
2009-03-20 20:33:36
User: psytek
Functions: cut echo grep ls read tr

This command will grep the entire directory looking for any files containing the list of files. This is useful for cleaning out your project of old static files that are no longer in use. Also ignores .svn directories for accurate counts. Replace 'static/images/' with the directory containing the files you want to search for.

curl -s -u user:password http://twitter.com/statuses/friends_timeline.rss | grep title | sed -ne 's/<\/*title>//gp' | head -n 4 | say -v Bruce
2009-03-20 20:14:13
User: sixtus
Functions: grep head sed

You need curl.. and a Mac of course.

xvkbd -xsendevent -text "Hello world"
2009-03-20 18:58:05
User: Alanceil

This is a (last resort) way to automate applications that provide no other ways for automation, it would send 'Hello world' to the currently active window. See the manpage (and the -text and -window entries) for how to send special characters and target specific windows.

An example:

Using xwininfo, I get the id of my XPlanet background window:

alanceil@kvirasim:19:51:0:~> xwininfo

xwininfo: Please select the window about which you

would like information by clicking the

mouse in that window.

xwininfo: Window id: 0x3600001 "Xplanet 1.2.0"

Absolute upper-left X: 0


Now I use xvkbd to tell it to close itself:

xvkbd -xsendevent -window 0x3600001 -text "Q"

Obviously, the best way is to put these commands in a shellscript - just make sure to include a short sleep (sleep .1 should suffice) after each xvkbd call, or some programs will become confused.

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging> -DgeneratePom=true
2009-03-20 16:29:08
User: virtualshock
Tags: maven java

If you have a JAR that is not in a central Maven repository this will add it to your repository.

set -o vi
2009-03-20 16:29:03
User: Viaken
Functions: set
Tags: readline vi

This lets you use your favorite vi edit keys to navigate your term.

To set it permanently, put "set editing-mode vi" in your ~/.inputrc or /etc/inputrc.