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 - 12,000 results
VBoxHeadless -s <name|uuid>
2009-08-07 12:36:32
5

you can launch a VirtualBox VM from the command line using VBoxManage, but that invokes it in a gui environment.

If you want to just fire off your VM in the background, use VBoxHeadless as shown. To get the names and UUIDs of your VirtualBox VMs, type:

VBoxManage list
ips(){ for if in ${1:-$(ip link list|grep '^.: '|cut -d\ -f2|cut -d: -f1)};do cur=$(ifconfig $if|grep "inet addr"|sed 's/.*inet addr:\([0-9\.]*\).*/\1/g');printf '%-5s%-15s%-15s\n' $if $cur $(nc -s $cur sine.cluenet.org 128 2>/dev/null||echo $cur);done;}
2009-08-07 10:04:46
User: frozenfire
Functions: cut echo grep ifconfig link sed
-3

Gets the internal and external IP addresses of all your interfaces, or the ones given as arguments

perl -ne 'split /,/ ; $a+= $_[3]; END {print $a."\n";}' -f ./file.csv
randpw(){ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;}
2009-08-07 07:30:57
User: frozenfire
Functions: head tr
3

Generates password consisting of alphanumeric characters, defaults to 16 characters unless argument given.

ab -n 9000 -c 900 localhost:8080/index.php
2009-08-07 07:19:40
User: amaymon
10

-n 9000 : Number of requests to perform for the benchmarking session

-c 900 : Number of multiple requests to perform at a time

cd `dirname $_`
dd if=/dev/urandom count=200 bs=1 2>/dev/null | tr "\n" " " | sed 's/[^a-zA-Z0-9]//g' | cut -c-16
cd !$:h
2009-08-07 00:37:08
User: lingo
Functions: cd
25

Uses the last argument of the last executed command, and gets the directory name from it.

Use $!:t for the filename alone, without the dirname.

for I in $(mysql -e 'show databases' -s --skip-column-names); do mysqldump $I | gzip > "$I.sql.gz"; done
watch -n 1 nc localhost 80 '<<EOF GET / HTTP/1.1 Host: tux-ninja Connection: Close EOF'
2009-08-06 23:20:31
User: JustinHop
Functions: watch
1

Use the command watch, which is really hard to pass nested quotes to, and insert newlines where they are supposed to go in the HTTP request. that is after 1.1 after the host and two newlines at the end before the EOF.

i use this all day

what? no support for HEREDOCs on commandlinefu's interface? need more fu.

cat files.txt | xargs tar -cv | tar -x -c $DIR/
2009-08-06 22:55:21
User: lingo
Functions: cat tar xargs
0

If you want certain files out of a directory hierarchy, this will copy just the listed files, but will create the directory hierarchy in the new location ($DIR/)

ifconfig $devices | grep "inet addr" | sed 's/.*inet addr:\([0-9\.]*\).*/\1/g'
rm -d **/*(/^F)
2009-08-06 21:41:19
User: claytron
Functions: rm
Tags: find zsh glob
4

This command uses the recursive glob and glob qualifiers from zsh. This will remove all the empty directories from the current directory down.

The **/* recurses down through all the files and directories

The glob qualifiers are added into the parenthesis. The / means only directories. The F means 'full' directories, and the ^ reverses that to mean non-full directories. For more info on these qualifiers see the zsh docs: http://zsh.dotsrc.org/Doc/Release/Expansion.html#SEC87

find . -name "-help" -exec mv {} help.txt \;
sudo snmptrap -m ALL -v 2c -c public trapserver "" UCD-DEMO-MIB::ucdDemoPublic SNMPv2-MIB::sysLocation.0 s "Just here"
cp path/filename{,-$(date +%Y-%m-%d)}
2009-08-06 13:50:00
User: vutcovici
Functions: cp date
1

It will create a backup of the filename. The advantage is that if you list the folder the backups will be sorted by date. The command works on any unix in bash.

wget -O - http://checkip.dyndns.org|sed 's/[^0-9.]//g'
fetch -q -o - http://ipchicken.com | egrep -o '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}'
2009-08-06 11:57:44
User: spackle
Functions: egrep
-1

Same thing as above, just uses fetch and ipchicken.com

nmap -PN -d -p445 --script=smb-check-vulns --script-args=safe=1 IP-RANGES
curl -s 'http://checkip.dyndns.org' | sed 's/.*Current IP Address: \([0-9\.]*\).*/\1/g'
html2text http://checkip.dyndns.org | grep -i 'Current IP Address:'|cut -d' ' -f4
2009-08-06 11:30:32
User: adonis28850
Functions: cut grep
-2

The same as the other user, but smarter, using -d and -f

ulimit -s 64
2009-08-06 10:40:25
User: ioggstream
Functions: ulimit
Tags: Linux ulimit
1

default stack size is 10M. This makes your multithread app filling rapidly your memory.

on my PC I was able to create only 300thread with default stack size.

Lower the default stack size to the one effectively used by your threads, let you create more.

ex. putting 64k I was able to create more than 10.000threads.

Obviously ...your thread shouldn't need more than 64k ram!!!

ldapmodify -Y "dn:uid=rob,dc=example.com" -g -R -J 2.16.840.1.113730.3.4.16 ...
html2text http://checkip.dyndns.org | grep -i 'Current IP Address:'|cut -c21-36
curl -u yourusername:yourpassword -d status=?Your Message Here? https://twitter.com/statuses/update.xml