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,492 results
sudo update-rc.d -f nomemioscript start 99 2 3 4 5
sftp -p port user@host
sudo update-rc.d -f nomescript stop 90 0 6
for dir in ~/git/*; do (cd "$dir" && git pull); done
scutil --dns
for file in $( vmrun list | grep 'vmx$' | sort ); do printf "% 40s %s M\n" $(echo "$( echo -n ${file}:\ ; grep memsize $file )" | sed -e 's/.*\///' -e 's/"//g' -e 's/memsize.=//'); done;
2010-11-19 06:14:11
Functions: echo file grep printf sed sort
Tags: vmware
-1

So your boss wants to know how much memory has been assigned to each virtual machine running on your server... here's how to nab that information from the command line while logged in to that server

VBoxManage modifyvm "vm-name" --vrdp on --vrdpport 3389 --vrdpauthtype external
2012-02-03 18:36:04
User: 0disse0
-1

--vrdp on enables VirtualBox RDP server for the VM

--vrdpport 3389 ndicates the TCP port that the server will accept RDP connections direct to the VM (for each VM is assigned a different port)

--vrdpauthtype external RDP console gives access to the VM Host physical users via authentication

In fact, in the 3.1.x version of VirtualBox, the external value for the parameter --vrdpauthtype allows access via RDP only to the user who started the VM.

The workaround is to add the user that runs the VM to shadow group, using the command

cat infile | while read str; do echo "$((++i)) - $str" ; done;
2009-12-09 14:05:09
User: glaudiston
Functions: cat echo read
-1

Yep, is hard, but is a way more flexible using pipe.

ip -4 addr show eth0 | awk ' /inet/ {print $2}'
2011-10-05 11:38:55
User: kadu
Functions: awk
-1

Shows the first IP on named interface including the network size

find . -maxdepth 1 -iname '*jpg' -exec convert -quality 60 {} lowQ/{} \;
2009-02-15 19:34:38
User: abhinay
Functions: find
-1

* lowQ/ is the output directory

* pass quality level from 1 to 100

date --iso
2009-02-25 23:50:40
User: raphink
Functions: date
-1

Useful to archive files once a day:

cp file file.$(date --iso)
echo "import random; print(random.choice(['heads', 'tails']))" | python
convert -bordercolor Transparent -border 1x1 in.png out.png
2009-02-15 19:42:17
User: jimmac
-1

Requires either imagemagick or graphicsmagic utility.

/usr/local/bin/OFPW -pass thepassword
while read str; do echo "$((++i)) - $str"; done < infile
2009-12-09 15:11:25
User: putnamhill
Functions: echo read
Tags: bash
-1

Hi glaudiston, you can save a few chars by leaving out cat and pipe and still enjoy the added flexibility.

tw translate.google.com.de-en `xsel`
2010-06-11 22:28:28
User: dbbolton
-1

Translate the X selection from German to English. The tw program is available from Savannah: http://mirror.its.uidaho.edu/pub/savannah/twandgtw/

I'm posting this because the base Debian system also does not include curl.

/usr/local/bin/OFPW -mode 1
perl -wlne 'print $1 if /(([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5]))/' iplist
2009-09-17 16:14:52
User: salparadise
Functions: perl
-1

if you want to only print the IP address from a file.

In this case the file will be called "iplist" with a line like "ip address 1.1.1.1"

it will only print the "1.1.1.1" portion

<ctrl+s>|<alt+s>
2011-05-02 14:44:41
User: Nbeker
-1

Learning cardinal and ordinal numbers in Spanish, with the best sounds files, try to get the best way to improve youLearning cardinal and ordinal numbers in Spanish, with the best sounds files, try to get the best way to improve your vocabulary.

xpath () { xmllint --format --shell "$2" <<< "cat $1" | sed '/^\/ >/d' }
2011-12-20 08:34:11
User: sharfah
Functions: sed
Tags: xml xmllint xpath
-1

This function uses xmllint to evaluate xpaths.

Usage: xpath /path/to/element XMLfile

copy /b part.1 + part.2 + part.n file.extension
echo 127.0.0.1 | egrep -e '^(([01]?[0-9]{1,2}|2[0-4][0-9]|25[0-4])\.){3}([01]?[0-9]{1,2}|2[0-4][0-9]|25[0-4])$'
2009-09-17 17:40:48
User: arcege
Functions: echo egrep
-1

Handles everything except octets with 255. Ran through ip generator with variable octet lengths.

sudo usermod -p $(mkpasswd '') user_id
2010-05-06 20:39:58
User: ckclark
Functions: sudo usermod
-1

It is safe when there is

"PermitEmptyPasswords no"

in /etc/ssh/sshd_config.

This command is useful when there is no need to have a password.

awk '{print $0/60;}' /proc/uptime
2011-08-31 10:41:21
User: ioggstream
Functions: awk
-1

Get info directly from /proc/uptime