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,925 results
wget -qO - snubster.com|sed -n '65p'|awk 'gsub(/<span><br>.*/,"")&&1'|perl -p -e 's:myScroller1.addItem\("<span class=atHeaderOrange>::g;s:</span> <span class=snubFontSmall>::g;s:&quot;:":g;s:^:\n:g;s:$:\n:'
2009-02-18 15:05:13
User: sil
Functions: wget
-2

I've got this posted in one of my .bash_profiles for humor whenever I log in.

sudo dmidecode | grep Serial\ Number | head -n1
2009-02-18 14:54:28
User: nlinux
Functions: grep head sudo
14

This will give you the Dell Service tag number associated with your machine. Incredibly useful when you need that number for tech support or downloads.

tar zcf - user | pv /bin/gzip > /tmp/backup.tar.gz
2009-02-18 14:50:45
User: nlinux
Functions: tar
4

This command tar?s up a directory and sends the output to gzip, showing a rate of 223MB/s.

This may require you installing the pv command.

For debian based users out there:

sudo aptitude install pv
/usr/local/bin/OFPW -mode 1
2009-02-18 14:48:31
User: tomslick
0

Sets the Open Firmware to ask for password when selecting a boot volume other then the hd

watch -d "free -mt"
sed 's/\(..\)/\1:/g;s/:$//' mac_address_list
2009-02-18 14:38:37
User: sil
Functions: sed
6

I sometimes have large files of MAC addresses stored in a file, some databases need the information stored with the semicolon (makes for easier programming a device) others don't. I have a barcode to text file scanner which usually butchers MAC addresses so this was the fix> I initially did this in awk ;)

awk '{for(i=10;i>=2;i-=2)$0=substr($0,1,i)":"substr($0,i+1);print}' mac_address_list

find . -type d -exec chmod 0755 {} \;
2009-02-18 14:38:22
User: osantana
Functions: chmod find
-5

WARNING! This command may set an invalid permission under your current directory.

This command will set the 0755 permissions to all directories under your current directory. An alternative version of this command is: find ~/.ssh -type d -exec chmod 0700 {} \;

find . -type f -exec chmod 0644 {} \;
2009-02-18 14:36:39
User: osantana
Functions: chmod find
-7

WARNING! This command may set an invalid permission under your current directory.

This command will set the 0644 permissions to all files under your current directory. An alternative version of this command is: find ~/.ssh -type f -exec chmod 0600 {} \;

find . -name "*.py[co]" -exec rm -f {} \;
2009-02-18 14:32:28
User: osantana
Functions: find rm
3

This command will erase all bytecode versions of Python modules under the current directory.

apt-cache dotty apache2 | dot -T png | display
2009-02-18 14:27:31
User: raphink
Functions: apt dot
7

Requires: imagemagick and graphviz

On Debian systems, displays a graph of package dependencies. Works also with other image formats, like svg :

apt-cache dotty bash | dot -T svg | display
sudo -l
2009-02-18 14:17:39
User: raphink
Functions: sudo
8

List the commands you have the right to use with sudo.

find . -iname "*.cpp" -exec perl -ni -e 'chomp; print "$_\n"' {} \;
2009-02-18 14:12:24
User: grundprinzip
Functions: find perl
0

Adds a newline to the end of all cpp files in the directory to avoid warnings from gcc compiler.

ps -C thisdaemon || { thisdaemon & }
2009-02-18 14:12:17
User: sil
Functions: ps
3

This comes in handy if you have daemons/programs that have potential issues and stop/disappear, etc., can be run in cron to ensure that a program remains up no matter what. Be advised though, if a program did core out, you'd likely want to know why (gdb) so use with caution on production machines.

caff <keyid>
2009-02-18 14:09:03
User: raphink
Tags: GPG
-1

Requires: signing-party (on Debian).

Note: you need a working MTA on your machine.

sudo su
2009-02-18 14:03:27
User: Vulpine
Functions: sudo
-8

Opens a new shell as root. Useful if you want to run a lot of commands as superuser without needing to sudo each of them.

ls -d */
2009-02-18 14:00:42
User: starchox
Functions: ls
8

This command would be useful when it is desirable to list only the directories.

Other options

Hidden directory

ls -d .*/

Other path

ls -d /path/to/top/directory/.*/

Long format:

ls -ld */
echo "foo bar" | sudo tee -a /path/to/some/file
2009-02-18 13:54:25
User: raphink
Functions: echo sudo tee
3

This is the solution to the common mistake made by sudo newbies, since

sudo echo "foo bar" >> /path/to/some/file

does NOT add to the file as root.

Alternatively,

sudo echo "foo bar" > /path/to/some/file

should be replaced by

echo "foo bar" | sudo tee /path/to/some/file

And you can add a >/dev/null in the end if you're not interested in the tee stdout :

echo "foo bar" | sudo tee -a /path/to/some/file >/dev/null
emerge -e system && emerge -e system && emerge -e world && emerge -e world
2009-02-18 13:51:31
User: enlightend
-2

This is a command you see mentioned alot by Gentoo monkeys.

They say to use it after every update of GCC, any library you might use and glibc.

They argue that compiling and recompiling everything like this will optimize the system alot more because you are recompiling the entire system (gcc, glibc etc) with nativly compiled versions of themselves. Same goes for all libraries etc.

I doubt the difference in working speed is really worth the hours and hours you end up having your computer compile the same stuff again and again though.

update-alternatives --config java
2009-02-18 13:43:41
User: raphink
Tags: Debian Ubuntu
4

On Debian systems, choose which command provides java. Works for all alternatives listed in /etc/alternatives.

ls -l !* | /usr/bin/grep '^d'
curl http://example.com/foo.tar.gz | tar zxvf -
airmon-ng start <interface> <channel>
2009-02-18 11:46:36
User: jie
-1

First you need to instal aircrack-ng

Use this command if you need to put your wireless card into monitor mode.

interface = wlan0 || wifi0 || ath0 et ceatera...

channel = 6, 11, 10, 9 et ceatera

for i in *.tar.gz *.tgz; do tar -zxvf $i; done
2009-02-18 10:58:12
User: bohemicus
Functions: tar
-1

This is a little bash script that will take all files following the *gz pattern in the directory and apply the tar -zxvf command to them.

ssh user@host cat /path/to/some/file | xclip
2009-02-18 10:56:38
User: raphink
Functions: cat ssh
Tags: X X11
18

Have you ever had to scp a file to your work machine in order to copy its contents to a mail? xclip can help you with that. It copies its stdin to the X11 buffer, so all you have to do is middle-click to paste the content of that looong file :)

install -o user -g group -m 755 /path/to/file /path/to/dir/
2009-02-18 10:46:19
User: raphink
Functions: install
1

This is useful when you want to copy a file and also force a user, a group and a mode for that file.

Note: if you want to move that file instead of copying it, you can use

install -o user -g group -m 755 /path/to/file /path/to/dir/ && rm -f /path/to/file

which will remove the file only if the install command went fine.