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,927 results
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 !}

git diff --cached
sort -bdf
2009-02-26 19:55:41
User: sysadmn
Functions: sort
2

Often, when sorting you want the sort to ignore extraneous characters. The b, d, and f tell sort to ignore leading blanks, use 'dictionary order' (ignore punctuation), and ignore (fold) case. Add a "u" if you only want one copy of duplicate lines.

This is a great command to use within vim to sort lines of text, using !}sort -bdf

perl -pi -e's/<what to find>/<what to replace it with>/g' `grep -Rl <what to find> /<dir>/*`
2009-02-26 19:14:39
User: adampbell
Functions: perl
2

Finds the string in every file in an entire directory and all its subdirectories and replaces it with a new string. Especially useful when changing a machine's IP address or hostname - run it on /etc.

time vmware-cmd -l | while read x; do printf "$x"; vmware-cmd "$x" removesnapshots; done
2009-02-26 18:51:29
User: jcgam69
Functions: printf read time
4

Old snapshots can cause problems. It's best to remove them when finished. I use this script to remove all snapshots. The "while read" command is necessary because my vm names contain spaces. The "time" command reports how long the process runs.

for vm in $(vmware-cmd -l);do echo -n "${vm} ";vmware-cmd ${vm} getstate|awk '{print $2 " " $3}';done
2009-02-26 16:45:04
User: dbart
Functions: echo
3

I use this command on my machines running VMware Server to print out the state of all registered Virtual machines.

rpm -qa | grep PACKAGENAME | xargs rpm -q --filesbypkg
2009-02-26 14:32:12
User: piscue
Functions: grep rpm xargs
1

rpm, sometimes, is not wildcard friendly. To search files installed from package this could be useful.

change PACKAGENAME to any package do you want to search