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,605 results
if [ "${vote}" = "down" ]; then echo leave comment; fi
2009-03-20 00:31:13
Functions: echo
-10

I think it would be wise if anyone voting down left a comment indicating the reason for that action. Don't keep it to yourself. Thanks.

ls -l | grep ^d | sed 's:.*\ ::g'
2011-08-06 23:52:46
User: LinuxMan
Functions: grep ls sed
Tags: bash sed ls grep
-10

Normally, if you just want to see directories you'd use brianmuckian's command 'ls -d *\', but I ran into problems trying to use that command in my script because there are often multiple directories per line. If you need to script something with directories and want to guarantee that there is only one entry per line, this is the fastest way i know

iptables -A OUTPUT www.baidu.com -p tcp -j REJECT --reject-with tcp-reset
2011-06-26 03:12:22
User: kev
Functions: iptables
Tags: iptables
-10

To save all rules so that they are not lost in case of a server reboot:

/etc/init.d/iptables save

more /var/adm/messages
2009-05-29 12:10:18
User: miccaman
Functions: more
Tags: solaris
-10

read system logs of sun solaris 9

<ctrl-shift-t>
2009-09-05 18:01:32
User: tobiasboon
Tags: firefox
-10

This is really not cli but I think it's neat.

j mp3
cd / && touch ./\-i
2012-04-05 20:55:37
User: joedhon
Functions: cd touch
-10

Somehow, i prefer forcing to rm interactively to accidently rm'ing everything...

screen -d -m nautilus --no-desktop `pwd`
2009-05-07 00:49:07
User: windsurfer
Functions: screen
-10

This opens up nautilus in the current directory, which is useful for some quick file management that isn't efficiently done from a terminal.

find . -print -exec chmod 777 {} \;
2009-12-23 13:16:31
User: ringlerun
Functions: chmod find
-10

sometimes if directories are too deep, chmod -R fails... in those cases, a find comes in most handy :)

sudo chmod -x /usr/lib/notify-osd/notify-osd
2010-11-10 11:35:43
User: lokutus25
Functions: chmod sudo
-10

Quick and dirty way to disable the Ubuntu notifications that can be quite annoying. It prevent the notify-osd to start so you need to logout Gnome or kill it by hand to take effect.

...
kill -9 <replace this with pid you want to kill>
scp -P 2202 /$filelocation user@host:/$final/$location
2011-04-14 02:08:06
User: mancipar
Functions: scp
-10
scp

(port 2202)

unalias
rpm -qf /etc/*-release
2010-03-01 01:24:07
User: megacoder
Functions: rpm
-10

This should work on any RPM-based distribution. It's more reliable than trying to parse the content of the files.

pwd
2009-02-13 00:31:49
User: rothgar
Functions: pwd
-10

Simply displays your current working directory. Helps when you are buried deep in /etc or some other obscure place.

ls | grep .gz >> list.txt && cat list.txt | while read x ; do gunzip -d $x ; done && rm -rf list.txt
cat /dev/cdrom > ~/mydisk.iso
2009-03-26 05:54:41
User: sata
Functions: cat
Tags: Linux
-10

Generate the iso from the disk, easily.

same as "dd if=/dev/cdrom of=~/mydisk.iso"

apt-get moo
pwd
2013-09-17 20:14:15
User: fhh
Functions: pwd
Tags: xdg-open
-10

exactly same effect as echo "$PWD" ...

wget -q -nd http://www.biranchi.com/ip.php; echo "Your external ip is : `cat ip.php`"
2010-12-20 09:53:59
User: pebkac
Functions: echo wget
-10

This is a convinient way to do it in scripts. You also want to rm the ip.php file afterwards

scp -P 1837 <path_to_loca_file> <remote_user>@<remote_ip>:<remote_ip>
2011-08-31 13:08:16
User: tkembo
Functions: scp
-10

when ssh is running on a different port

grep -r <searchterm> *
init 6
2009-05-29 07:44:05
User: miccaman
Functions: init
Tags: solaris Reboot
-11

init states on solaris are numbered

init 0 boot with prompt

init 5 shutdown

init 6 reboot

yum -y install bind bind-chroot caching-nameserver