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,620 results
convert image123.png -colors 14 -resize 640x480 grubimg.xpm
2009-03-12 22:55:10
User: starchox
Tags: Linux grub boot
3

* size must be 640?480 pixels

* only has 14 colors

* save it in XPM format

Edit /boot/grub/menu.lst and add

splashimage=(hd0,0)/boot/grub/grubimg.xpm

make sure for your path name and hard disk

find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
2009-03-12 22:25:26
Functions: find sed
-1

NOT MINE! Taken from hackzine.com blog.

It creates a tree-style output of all the (sub)folders and (sub)files from the current folder and down(deeper)

Quoting some of hackzine's words

"Murphy Mac sent us a link to a handy find/sed command that simulates the DOS tree command that you might be missing on your Mac or Linux box. [..split...] Like most things I've seen sed do, it does quite a bit in a single line of code and is completely impossible to read. Sure it's just a couple of substitutions, but like a jack in the box, it remains a surprise every time I run it."

lsof|grep /somemount/| awk '{print $2}'|xargs kill
2009-03-12 18:42:19
User: archlich
Functions: awk grep xargs
4

This command will kill all processes using a directory. It's quick and dirty. One may also use a -9 with kill in case regular kill doesn't work. This is useful if one needs to umount a directory.

[[ -d dir ]] || mkdir dir ; cd dir
2009-03-12 17:19:13
User: voyeg3r
Functions: cd dir mkdir
1

For use in scripts this command is very usefull

mkdir -p doc/{text/,img/{wallpaper/,photos/}}
2009-03-12 17:15:58
User: voyeg3r
Functions: mkdir
15

create tree of dir's in one command

alias path='echo $PATH | tr ":" "\n"'
2009-03-12 17:07:58
User: voyeg3r
Functions: alias tr
-1

change ":" in path for new line and associate word path to var $PATH

find . -maxdepth 1 -type f -print0 | xargs -0 -i cp ./{}{,.bak}
2009-03-12 16:02:13
User: voyeg3r
Functions: cp find xargs
-2

"." is current dir, maxdepth is the level, -print0 | xargs -0 fix spaces in names, -i interactive , ./ is the current dir {} actual name , and {,.bak} is the atual name + bak

function dpan () { PKG=`perl -e '$_=lc($ARGV[0]); s/::/-/g; print "lib$_-perl\n"' $1`; apt-get install $PKG; }
2009-03-12 15:39:38
User: dave0
Functions: install
1

Running 'cpan Module::Name' will install that module from CPAN. This is a simple way of using a similar command to install a packaged Perl module from a Debian archive using apt-get.

$EDITOR `perldoc -l Module::Name`
2009-03-12 15:31:37
User: dave0
3

Ever needed to look at the Perl source of an installed module on your system? This works in 90% of cases.

perl -e 'print map { $_ . "\n" } @INC;'
svn status | grep "^\?" | awk '{print $2}' | xargs svn add
2009-03-12 15:06:12
User: unixfu73000
Functions: awk grep xargs
Tags: svn
-1

This adds all new files to SVN recursively. It doesn't work for files that have spaces in their name, but why would you create a file with a space in its name in the first place?

convert -adjoin -page A4 *.jpeg multipage.pdf
2009-03-12 14:49:18
User: johnquail
Tags: ImageMagick
8

The linux package imagmagick is required for this command

sudo dmidecode --type 17 | more
VARIABLE="VALUE" COMMAND
2009-03-12 07:04:44
User: magmax
-4

Allows you to change the value of an environment variable only for the execution of the command in the line. (corrected)

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
403

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>