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.

Universal configuration monitoring and system of record for IT.
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

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

Hide

Credits

All commands from sorted by
Terminal - All commands - 12,130 results
dpkg-deb -x $debfile $extractdir; dpkg-deb -e $debfile $extractdir/DEBIAN;
2009-08-07 20:33:43
User: flokra
1

extracts the debian-package $debfile to $extractdir, including all packaging-information. to repack the package, just type:

dpkg-deb -b $extractdir
sudo du -sh $(ls -d */) 2> /dev/null
nslookup commandlinefu.com|sed 's/[^0-9. ]//g'|tail -n 1|awk -F " " '{print $2}'
2009-08-07 17:32:55
User: thundernode
Functions: awk nslookup sed tail
1

I use this in a script on my openwrt router to check if my DynDNS needs to be updated, saves your account from being banned for blank updates.

ssh-copy-id user@host
dig commandlinefu.com | sed -nr 's/^[^;].*?\s([.0-9]{7,15})$/\1/ p'
2009-08-07 16:11:31
User: birnam
Functions: dig sed
0

Strips the non-ip information from the dig output. Could be combined with "head -1" to ensure a single ip is returned. Useful for outputting as a variable for use in scripts.

VBoxManage list vms
2009-08-07 12:43:04
2

A similar command that lists only the currently running VMs is thus:

VBoxManage list runningvms

...the above showing a list of VMs by name and UUID in the same format as the "$ VBoxManage list vms" command

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