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,490 results
yum install fortune-firefly; fortune
mkntfs /dev/hda1
2011-07-02 17:43:16
User: 0disse0
Tags: windows ntfs
-3

With this command you can create an empty NTFS partition. The command is useful if, for example, we want to format a previous installation of Windows and reinstall before you want to restore some files on the partition.

open -a /Applications/Safari.app $1
puppetd -t
sudo mount -t vfat /dev/sdb1 /mnt/sdb1
ls *[^p][^a][^t]* ; # or shopt -s extglob; ls !(*pattern*)
ifconfig | sed '/.*addr.*Bcast.*/ ! d'| sed 's/.*addr:\([0-9\.]*\).*/\1/'
2010-03-26 08:13:13
User: Haegin
Functions: ifconfig sed
-3

This doesn't make any assumptions about your IP address and prints out one IP address per line if you have multiple network interfaces.

echo -e "o\nn\np\n1\n\n\nw\n" | fdisk /dev/sdX
for /F "DELIMS=""" %i in ('dsquery group -name SourceGroupName ^| dsget group -members') do dsquery group -name TargetGroupName | dsmod group -addmbr %i
2009-09-25 16:32:33
User: miketheman
-3

Interacting with Active Directory to add users from one group to another group.

This prevents from having to deal with long DNs and copying, pasting problems. It executes once per returned object.

ifconfig | awk '/inet addr/ &&! /127.0.0.1/{ gsub(/addr:/,""); print $2 }'
if [ $(synclient -l | grep TouchpadOff | awk '{print $3}') = "2" ]; then synclient TouchpadOff=1; elif [ $(synclient -l | grep TouchpadOff | awk '{print $3}') == "1" ]; then synclient TouchpadOff=2; else synclient TouchpadOff=2; fi
2010-01-26 07:52:55
User: GinoMan2440
Functions: awk grep
-3

This command toggles the touchpad on and off, when it's on, the right side scroll strip (annoying) and the tap-clicking are disabled, you can change this by changing occurances of 2 in the command to 0. this whole command can then be given a keyboard shortcut so that the touchpad is disableable without using a special fn key (which linux doesn't recognize on some computers) or a seperate button.

PS1="$BLUE[$CYAN\u$BLUE@$CYAN\h$WHITE-bash \v:$GREEN\w$BLUE]$WHITE \$ "
2009-05-06 08:01:06
User: P17
Tags: bash
-3

The colors are defined as variables.

e.g.

RED="\[\033[01;31m\]"

BLUE="\[\033[01;34m\]"

ifconfig eth0 down hw ether (newmacaddresshere) && ifconfig eth0 up && ifconfig eth0 (newipaddresshere) netmask 255.255.255.0 up && /bin/hostname (newhostnamehere)
2009-06-04 20:25:49
User: localGhost
Functions: ifconfig
-3

The command above has been changed due to very good constructive criticism - thanks x 2! This command can be used after acquiring mac's, ip's and hostname's or any of the above from a freshly scanned LAN. User must be root, and remember to change your settings on your network managing software manually (Fedc10 NetworkManager Applet 0.7.1 is mine) instead of 'auto DHCP'. You can also substitute eth0 for wlan0 etc - be good and ENJOY!

cat aaaaaa 2>&-
sar -g 5 5
find . -name *.php | xargs grep -i -n 'TERM'
yes | tr 'y' 'n'
find . -iname "*.jar" -exec cp '{}' /tmp/ \;
2010-01-26 12:19:15
Functions: cp find
-3

Useful for Maven multimodule projects, where you want to extract all packaged jar files.

find . -type f -print0 | grep -vzZ '.svn' | xargs -0 grep --color -nEHi "SEARCHTERM"
2009-02-05 10:27:15
User: troelskn
Functions: find grep xargs
-3

Variant of find grep that ignores files with .svn in the name. Useful for searching through a local repository of source code.

set -o vi
2009-12-22 20:40:10
User: andykazmaier
Functions: set
-3

Once issuing the command, hit "esc" and then "k" (not together) to enter the search mode at the shell prompt (each time), and invoke the search with "/" as if you would in vi. Type a command and see the most recently used instance of that command. Use "n" and "N" to go forward and backwards through other instances of that command.

sfdisk /dev/sdb <(sfdisk -d /dev/sda| perl -pi -e 's/sda/sdb/g')
2009-12-22 22:45:41
Functions: perl
-3

*as long as the drives are exactly the same* then this command copies the partition table on /dev/sda to /dev/sdb

vboxmanage clonehd --format VMDK <source image|uuid> <destination image>
2010-10-04 16:42:12
User: dreffed
-3

This is based on the Windows Version of VirtualBox.

From the /? ...

VBoxManage clonehd |

[--format VDI|VMDK|VHD|RAW|]

[--variant Standard,Fixed,Split2G,Stream,ESX]

[--type normal|writethrough|immutable|shareable]

[--remember] [--existing]

From the online help..

http://www.virtualbox.org/manual/ch08.html#id2676537

VBoxManage clonehd

This command duplicates a registered virtual hard disk image to a new image file with a new unique identifier (UUID). The new image can be transferred to another host system or imported into VirtualBox again using the Virtual Media Manager; see the section called ?The Virtual Media Manager? and the section called ?Cloning disk images?. The syntax is as follows:

VBoxManage clonehd |

[--format VDI|VMDK|VHD|RAW|]

[--variant Standard,Fixed,Split2G,Stream,ESX]

[--type normal|writethrough|immutable]

[--remember]

where the parameters mean:

format

Allow to choose a file format for the output file different from the file format of the input file.

variant

Allow to choose a file format variant for the output file. It is a comma-separated list of variant flags. Not all combinations are supported, and specifying inconsistent flags will result in an error message.

type

Only honored if --remember is also specified. Defines what kind of hard disk type this image should be.

remember

Keep the destination image registered after it was successfully written.

curl ifconfig.me
2011-03-02 23:04:00
User: Honeypuck
-3

It takes a few seconds until it has figured out your public ip address. You need to have 'curl' installed of course.

vi -R filename
2009-03-04 06:56:40
User: haivu
Functions: vi
Tags: vim
-3

The -R flag prevents you from making changes to a file, useful when you only want to view the file. This command is nicer than the 'more' or 'less' commands because for source codes, vi shows syntax highlight.

for i in `find . | grep jar$`; do echo $i; jar tvf $i | grep 'search-string'; done;