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,858 results
find $HOME -type f -print | perl -wnlaF'/' -e 'BEGIN{ print "#EXTM3U"; } /.+\.wmv$|.+\.mpg$|.+\.vob$/i and print "#EXTINF:$F[-1]\nfile://$&";' > movies.m3u
svn status | grep '^\?' | sed -e 's/^\?//g' | xargs svn add
2009-02-28 03:00:28
User: dollyaswin
Functions: grep sed xargs
0

These part of the command:

svn status | grep '^\?' => find new file or directory on working copy

sed -e 's/^\?//g' => remove "^" character on the first character of file name

xargs svn add => add file to subversion repository

You can modify above command to other circumtances, like revert addition files or commit files that have been modified. ^_^

e2label /dev/vg0/lv0 MyFiles
v=/dev/vg0/lv0; lvextend -L+200G $v && resize2fs $v
2009-02-28 02:30:49
User: wwest4
Functions: resize2fs
4

Live extension of an ext3 file system on logical volume $v by 200GB without the need to unmount/remount.

Requires that you have 1) a version of resize2fs that contains code merged from ext2online, and 2) kernel support for online resizing. (e.g. RHEL 5)

pkill -n firefox
2009-02-28 01:19:59
User: Williebee
3

Kills the most recently created firefox process.

aptitude show $PROGRAM | grep Vers
2009-02-27 23:24:37
User: aabilio
Functions: grep
-1

Output: Version 3.2-0 (for example if you type # aptitude show bash | grep Vers

Depends on the language of your distribution, because the name of the word "Version" in other languages may be different.

sudo dd if=/dev/sda of=/media/disk/backup/sda.backup
2009-02-27 20:23:37
User: bandit36
Functions: dd sudo
Tags: backup dd
14

This will create an exact duplicate image of your hard drive that you can then restore by simply reversing the "if" & "of" locations.

sudo dd if=/media/disk/backup/sda.backup of=/dev/sda

Alternatively, you can use an SSH connection to do your backups:

dd if=/dev/sda | ssh user@ssh.server.com dd of=~/backup/sda.backup
rsync -vazuK --exclude "*.mp3" --exclude "*.svn*" * user@host:/path
2009-02-27 19:58:02
User: sudopeople
Functions: rsync
Tags: svn exclude
2

rsyncs files to a server excluding listed files

also a file can be used to exclude common exclude rules and/or to exclude a ton of files, like so:

rsync --exclude-from '~/.scripts/exclude.txt'

where exclude.txt has one rule per line:

*.mp3

*.svn*

write user anytext
ifconfig | awk '/inet / {print $2}'
2009-02-27 17:05:08
User: haivu
Functions: awk ifconfig
1

On the Mac, the format ifconfig puts out is little different from Linux: the IP address is space separated, instead of colon. That makes parsing the IP address easier. See releated command for Linux/Unix:

http://www.commandlinefu.com/commands/view/651/getting-the-ip-address-of-eth0

xmodmap -e "remove Lock = Caps_Lock"
2009-02-27 16:44:22
User: mzandrew
2

a quick one-line way to disable caps lock while running X.

vim -p file1 file2 ...
2009-02-27 16:43:59
User: haivu
Functions: vim
Tags: vim
8

Edit the files, each in a separate tab. use gT and gt to move to the left- and right-tab, respectively. to add another tab while editing, type ':tabe filename'

ls -1 | while read a; do mv "$a" `echo $a | sed -e 's/\ /\./g'`; done
grep "FOUND" /var/log/squidclamav.log | awk '{print $5"-"$2"-"$3","$4","$11}' | sed -e 's/\,http.*url=/\,/g' | sed -e 's/&/\,/g' | sed -e 's/source=//g' |sed -e 's/user=//g' | sed -e 's/virus=//g' | sed -e 's/stream\:+//g' | sed -e 's/\+FOUND//g'
2009-02-27 13:28:18
User: nablas
Functions: awk grep sed
0

This command will list a CSV list of infected files detected by clamav through squidclamav redirector.

awk 'BEGIN {FS=","} {loc = $4, val=$5; getline < "f0001ch1.csv"; print loc,val,$5}' f0001ch2.csv > data
2009-02-27 13:01:16
User: Masse
Functions: awk
0

Parses tektronic given csv files for both channel 1 and channel 2 and joins them together. Can be easily used by gnuplot after that.

rpm -qif `which more`
2009-02-27 08:59:07
User: alcik
Functions: rpm
Tags: rpm which
3

Replace 'more' command with any command which is in your PATH.

ls -ld **/*(/)
ls -ld *(/)
git commit --amend
2009-02-27 04:42:44
Tags: git
14

It's pretty common to forgot to commit a files, be it a modification, or a brand new file.

If you did forget something, git add the files you want, and then git commit --amend. It will essentially redo the last commit, with the changes you just added. It seeds the commit message with the last commit message by default.

You probably shouldn't do this if you've already pushed the commit.

alias trash="rm -fr ~/.local/share/Trash"
2009-02-27 01:55:30
Functions: alias
-4

Force empties the user trash

dpkg-reconfigure -phigh xserver-xorg
git rm $(git ls-files --deleted)
2009-02-26 21:21:02
Functions: rm
Tags: git
19

This command handles git rm'ing files that you've deleted.

$ cat /etc/*-release
ls -l | grep ^d
2009-02-26 20:28:10
User: sysadmn
Functions: grep ls
1

Show only the subdirectories in the current directory. In the example above, /lib has 135 files and directories. With this command, the 9 dirs jump out.

sort -nt . -k 1,1 -k 2,2 -k 3,3 -k 4,4
2009-02-26 20:22:57
User: sysadmn
Functions: sort
14

Sort a list of IPV4 addresses in numerical order. Great as a filter, or within vim using !}