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,485 results
cp --backup=t source.file target.file
2009-03-12 06:46:13
User: magmax
Functions: cp
3

Allows you to preserve your files when using cp, mv, ln, install or patch. When the target file exists, it will generate a file named XXX.~N~ (N is an auto-incremental number) instead of deleting the target file.

diff <(nmap -sP 192.168.1.0/24 | grep ^Host | sed 's/.appears to be up.//g' | sed 's/Host //g') auth.hosts | sed 's/[0-9][a-z,A-Z][0-9]$//' | sed 's/</UNAUTHORIZED IP -/g'
2009-03-12 05:28:08
User: bandit36
Functions: diff grep sed
Tags: diff sed nmap grep
1

populate the auth.hosts file with a list of IP addresses that are authorized to be in use and when you run this command it will return the addresses that are pingable and not in the authorized list.

Can be combined with the "Command line Twitter" command to tweet unauthorized access.

ln -s /destinationTarget /sourceTarget/newFolder
2009-03-12 01:56:34
User: topgun553
Functions: ln
-3

if you wanted to create a new folder called "red" that was a symbolic link from /home/music/ to /home/hobbies/art then you would type:

ln -s /home/hobbies/art /home/music/red

unlink <linkname>
2009-03-12 01:52:24
User: topgun553
Functions: unlink
-4

if you had a symbolic link called "oldLink" in the current folder then you would want to do

unlink oldLink

rpm -qa \*code\*
2009-03-11 21:16:23
User: alcik
Functions: rpm
Tags: rpm
2

You can use wildcard with rpm search but you have to do 2 things:

1. use "-a" switch (means "all") with query ("-q") switch - argument is a pattern to use while searching for package names of all installed packages

2. protect wildcards, so that shell could not eat them - escape it with backslash ("\") or enclose all pattern between apostrophes ("'"):

rpm -qa 'co*de'

As you can see above it is possible to insert wildcards into middle of the pattern.

If you want, you can add "-i" or another rpm query options, "-i" will print package information for all installed packages matching pattern.

manview() { lynx -dump -accept_all_cookies 'http://www.csuglab.cornell.edu/cgi-bin/adm/man.cgi?section=all&topic='"$1" | less; }
2009-03-11 19:02:11
User: Ben
0

manview searches man pages on the internets in case the man command doesn't work for some reason or if you think the man pages in Cornell's flavor of Solaris might differ from yours. It dumps the manpage info from lynx to less, so it ends up looking remarkably like a real manpage. Put it in your .bash_profile or .bashrc, and then you can use it like a regular command: typing "manview ssh" will give you the manpage for ssh.

echo -n $HEXBYTES | xxd -r -p | dd of=$FILE seek=$((0x$OFFSET)) bs=1 conv=notrunc
2009-03-11 17:02:24
User: zombiedeity
Functions: dd echo
2

Replace (as opposed to insert) hex opcodes, data, breakpoints, etc. without opening a hex editor.

HEXBYTES contains the hex you want to inject in ascii form (e.g. 31c0)

OFFSET is the hex offset (e.g. 49cf) into the binary FILE

instfix -icq | grep 5300-07_AIX_ML | grep ":-:"
2009-03-11 12:34:18
User: deltwalrus
Functions: grep
0

This will let you know what filesets or fixes (if any) are missing in order to be considered "at" a given technology level in AIX.

find . -name *DS_Store -exec echo rm {} \;
2009-03-11 11:30:55
User: dgomes
Functions: echo find rm
-3

This is quite usefull in Unix system share via NFS or AppleTalk with OSX clients that like to populate your filesystem with these pesky files

ctrl-x e
2009-03-11 09:26:05
User: fool
385

Next time you are using your shell, try typing ctrl-x e (that is holding control key press x and then e). The shell will take what you've written on the command line thus far and paste it into the editor specified by $EDITOR. Then you can edit at leisure using all the powerful macros and commands of vi, emacs, nano, or whatever.

sudo lsof -i :<port>
vim $( ls -t | head -n1 )
rpm2cpio /path/to/file.rpm | cpio -i -d
2009-03-10 21:02:14
User: atoponce
Functions: cpio
0

This assumes you have the 'rpm', 'rpm2cpio' and 'cpio' packages installed. This will extract the contents of the RPM package to your current directory. This is useful for working with the files that the package provides without installing the package on your system. Might be useful to create a temporary directory to hold the packages before running the extraction:

mkdir /tmp/new-package/; cd /tmp/new-package
echo -n "string" | md5sum -
2009-03-10 21:01:36
User: cryptema
Functions: echo md5sum
0

A useful way to generate the MD5 hash for a string by command line

for i in $(ls *.od{tp}); do unoconv -f pdf $i; done
function cdls { cd $1; ls; }
2009-03-10 19:13:47
User: joem86
Functions: cd
Tags: terminal
7

After typing cd directory [enter] ls [enter] so many times, I figured I'd try to make it into a function. I was surprised how smoothly I was able to integrate it into my work on the command line.

Just use cdls as you would cd. It will automatically list the directory contents after you cd into the directory. To make the command always available, add it to your .bashrc file.

Not quite monumental, but still pretty convenient.

for x in *s.yml; do mv $x `echo $x | sed 's/s\.yml/\.yml/'`; done
2009-03-10 17:51:19
Functions: mv sed
-1

Jan Nelson from Grockit came up with this for us when we needed to rename all of our fixtures.

svn status | grep ^? | awk '{print $2}' | xargs rm -rf
2009-03-10 17:01:40
User: Highwayman
Functions: awk grep rm xargs
1

Removes all unversioned files and folders from an svn repository. Also:

svn status --no-ignore | grep ^I | awk '{print $2}' | xargs rm -rf

will remove those files which svn status ignores. Handy to add to a script which is in your path so you can run it from any repository (a la 'svn_clean.sh').

grep Mar/2009 /var/log/apache2/access.log | awk '{ print $1 }' | sort -n | uniq -c | sort -rn | head
echo "\"\e[5~\": history-search-backward" >> ~/.inputrc
2009-03-10 15:32:52
User: silbermm
Functions: echo
0

What this does is, if I type ?ssh ? then hit the page-up key, it will complete the line to the last time in my history file that I typed ssh. Hitting page up again will go to the 2nd to last time I typed it. Incredibly handy if you ever type the same commands more than once.

credit goes to http://www.sharms.org/blog/2009/03/10/make-your-bash-shell-cool-again/

echo "\"\e[6~\": history-search-forward" >> ~/.inputrc
ssh -NL 2000:remotehost:22 remotehost
rename .JPG .jpg *.JPG
2009-03-10 15:07:24
User: psytek
Functions: rename
3

This will change all files ending in .JPG to .jpg and will work with any file extension

ssh -fX <user>@<host> <program>
2009-03-10 15:02:35
User: prayer
Functions: ssh
Tags: ssh
15
ssh -X example.org xeyes

The SSH server configuration requires:

X11Forwarding yes # this is default in Debian

And it's convenient too:

Compression delayed

gconftool-2 -t bool -s /desktop/gnome/interface/can_change_accels true
2009-03-10 14:53:33
User: prayer
Tags: gtk
-1

Then, you can assign new accels to GTK menu actions pressing the keys while the option is active.