Hide

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.

Hide

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:

Hide

News

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.
Hide

Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 11,588 results
ffmpeg -i file.flv -r 15 -b 128k -s qcif -acodec amr_nb -ar 8000 -ac 1 -ab 13 -f 3gp -y out.3gp
2009-03-23 14:30:45
User: jjclarkson
Tags: video ffmpeg
5

Download YouTube videos as .flv and convert them to .3gp for your mobile phone.

find . -name *.php | xargs grep -i -n 'TERM'
convert -colorspace gray face.jpg gray_face.jpg
2009-03-23 14:18:04
User: medina
Tags: ImageMagick
4

Use ImageMagick to create a "black and white" copy of an image.

addfunction () { declare -f $1 >> ~/.bashrc ; }
2009-03-23 12:55:04
User: dagh
Tags: bash
6

Example: To store the function addfunction after you have defined it:

addfunction addfunction
alias mux='clear && cd ~/Music/ && ls && echo -n "File> " && read msi && mplayer ~/Music/$msi'
2009-03-23 10:45:27
User: Noxn
Functions: alias cd echo ls read
-2

An alias i made for myself to play music in a faster way.

Works great when you have Guake / Tilda installed (Console that drops down like in the game QUAKE)

---

I put this in my bash_alias file (I'm on ubuntu, the bash_alias file does autostart with the right config) but it works putting it in bashrc too. Or anything that autostarts when the console is opened.

---

Needs Mplayer and music files to work. With out music theres nothing to play!

Oh, and also, without modification, this alias will try to play stuff from your ~/Music folder! (case sensitive). Make sure that folder exists and has music OR edit this alias to fit your needs.

for x in *.ogg; do ffmpeg -i "$x" "`basename "$x" .ogg`.mp3"
mencoder -ovc copy -oac copy -of avi -o remuxed.avi original.avi
2009-03-23 10:15:36
User: iain
6

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
2

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

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

Cheese or other webcam software not working? Try this.

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

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
-4

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
0

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
-4

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
0

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
17

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
-6

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
1

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
22

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
16

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
-1

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
20

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'