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,858 results
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.

nmap -sS -P0 -sV -O <target>
2009-02-18 07:32:03
User: starchox
Tags: Network net
18

Where < target > may be a single IP, a hostname or a subnet

-sS TCP SYN scanning (also known as half-open, or stealth scanning)

-P0 option allows you to switch off ICMP pings.

-sV option enables version detection

-O flag attempt to identify the remote operating system

Other option:

-A option enables both OS fingerprinting and version detection

-v use -v twice for more verbosity.

nmap -sS -P0 -A -v < target >
tar cvzf - /directory/ | ssh root@host "cat > /dev/nst0"
2009-02-18 07:12:54
User: Tuxmania
Functions: ssh tar
3

I use this all the time for taking manual backups of stuff i want to keep but not important enough to backup regularly.

tr -d "\n" < file1 > file2
CONVERT D: /FS:NTFS
2009-02-18 05:56:07
User: starchox
-1

You can convert a FAT or FAT32 volume to an NTFS volume without formatting the drive, though it is still a good idea to back up your data before you convert.

host `hostname`
2009-02-18 05:48:29
User: rommelsharma
Functions: host
-2

This is a useful command that gives the hostname and the IP Address of your machine, on many OS. Tested on Linux and Solaris.

host command here is followed by `hostname`. Note the ` in the command is a back quote (or grave accent or back tic that usually shares the space with the ~ key). No other options are specified. See sample output.

xawtv -remote -bpp 16 -noxv-video -geometry 160x120 -device /dev/video0
2009-02-18 04:47:52
User: my0pic
0

This command lets you view the cam on remote machine whilst connected via ssh. Note: must connect to remote machine with ssh -Y.

ps -e
killall -9 wineserver
find . | grep deleteme | while read line; do rm $line; done
2009-02-18 00:55:57
User: tec
Functions: find grep read rm
-3

This command deletes all files in all subfolders if their name or path contains "deleteme".

To dry-run the command without actually deleting files run:

find . | grep deleteme | while read line; do echo rm $line; done
On PC1: nc -l -p 6666 > /dev/dsp On PC2: cat /dev/dsp | nc <PC1's IP> 6666
2009-02-18 00:39:32
User: someguy
Functions: cat
6

Sends the microphone input from PC1 to the speakers of PC2. Do the same in reverse to have an actual conversation ;) ... maybe with another port tough

dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev
2009-02-17 23:36:24
User: TyIzaeL
Functions: cut dd rev
0

I know there are a lot of random password generators out there, but I wanted something that put out something besides hex. Set count equal to the number of bytes you want.

defaults write com.apple.dashboard mcx-disabled -boolean YES; killall Dock
2009-02-17 23:22:24
User: starchox
Functions: killall write
0

Dashboard is OS X utility application. When you hit F12, Dashboard springs forward, dimming the background, some people have claimed memory or performance problems. In my case, I just don't use it, there may be other reasons you?d rather not have Dashboard available.

Change YES to NO to restore the previous functionality.

defaults write com.apple.finder NSUserKeyEquivalents -dict 'New Finder Window' '@$N' 'New Folder' '@N'; killall Finder
2009-02-17 23:20:53
User: Vulpine
Functions: killall write
-1

In Mac OS 9, the "New Folder" keyboard shortcut was Command+N, but in Mac OS X this was changed to "New Finder Window" instead, with "New Folder" taking the more awkward shortcut of Command+Shift+N. This command reverses their mappings.

defaults write com.apple.Dock no-glass -boolean YES; killall Dock
2009-02-17 23:01:58
User: Vulpine
Functions: killall write
1

Mac OS X 10.5 (Leopard) introduced a new, 3D, reflective Dock. For those of us who prefer the Dock to be a little less distracting, this command is the answer. The Dock will be rendered in the same style as when pinned to the left- or right-hand side of the screen. Replace YES with NO to restore the 3D Dock.

find . -name ".svn" -exec rm -rf {} \;
2009-02-17 23:00:30
User: mihaibojin
Functions: find rm
0

If you need to delete all redundant ".svn" directories from a given path and all its subdirectories, use this command !

Particulary useful if you want to upload to an ftp server, but don't use svn or if you need to update/backup some source code to another directory.

You can also try "svn export . /new/path/without/svn/dirs" (also from the CLI)

wget --random-wait -r -p -e robots=off -U mozilla http://www.example.com
2009-02-17 22:53:07
User: starchox
Functions: wget
153

-p parameter tells wget to include all files, including images.

-e robots=off you don't want wget to obey by the robots.txt file

-U mozilla as your browsers identity.

--random-wait to let wget chose a random number of seconds to wait, avoid get into black list.

Other Useful wget Parameters:

--limit-rate=20k limits the rate at which it downloads files.

-b continues wget after logging out.

-o $HOME/wget_log.txt logs the output

msiexec.exe /i product.msi /l* c:\folder\LogFileName.txt