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,925 results
netstat -tlpn | sort -t: -k2 -n
2014-07-22 14:08:01
User: hute37
Functions: netstat sort
Tags: netstat
4

Show TCP Listen ports sorted by number

(bugs: IPV6 addresses not supported)

tar -cj / -X /tmp/exclude.txt | cstream -v 1 -c 3 -T 10 | ssh user@host 'tar -xj -C /backupDestination'
2014-07-21 18:52:19
User: fantleas
Functions: ssh tar
0

The files are automatically uncompressed when they reach the destination machine. This is a fast way to backup your server to your local computer while it's running (shutting down services is recommended).

A file named "exclude.txt" is needed at /tmp/ containing the following :

/dev/*

/media/*

/mnt/*

/proc/*

/sys/*

/tmp/*

/home/*/.local/share/Trash

/home/*/.gvfs

/home/*/.cache

/home/*/.thumbnails

/etc/fstab

/lib/modules/*/volatile/.mounted

/var/run/*

/var/lock/*

/var/tmp/*

/var/cache/apt/archives/*

/lost+found/*

mount -t cifs -o username=SlackerMojo,domain=BIGGREEDY,rw //192.168.4.24/f /mnt/storage
mknod replypipe p; nc -k -lp 1234 < replypipe| nc -U /var/run/mysocket.sock > replypipe
2014-07-19 18:17:35
User: adimania
Functions: mknod
-1

* Make a FIFO file named replypipe

* listen on 1234

* pass the request to unix socket

* unix socket will reply to replypipe

* replypipe will write reply to the client

subl $(pwd)
du -sch .[!.]* * |sort -h
2014-07-17 21:45:46
User: krizzo
Functions: du sort
0

This command sorts the content including hidden files in human readable format of the current directory.

cat h.txt| while read line; do curl -s -X POST 'https://www.virustotal.com/vtapi/v2/file/report' --form apikey="APIKEY" --form resource="$line"|awk -F'positives\":' '{print "VTHits"$2}'|awk -F' ' '{print $1" "$2$5$6}'|sed 's/["}]//g' && sleep 15; done
man -Pcat urxvt | \ # see description for full command
2014-07-16 23:14:14
User: malathion
Functions: man
0

man -Pcat urxvt | sed -n '/th: b/,/^B/p'|sed '$d'|sed '/^ \{7\}[a-z]/s/^ */^/g' | sed -e :a -e 'N;s/\n/@@/g;ta;P;D' | sed 's,\^\([^@]\+\)@*[\t ]*\([^\^]\+\),! \2\n! URxvt*\1\n\n,g' | sed 's,@@\( \+\),\n\1,g' | sed 's,@*$,,g' | sed '/^[^!]/d' | tr -d "'\`"

Prints a precompiled list of options to add to your Xresources.

Provided by Charles Torvalds here: http://www.askapache.com/linux/rxvt-xresources.html#Output_RXVT_Resources

blkid
sed -i "s/:\([a-zA-Z_]*\) =>/\1:/g" **/*.rb
2014-07-16 02:12:09
Functions: sed
0

Before: :key => 'value'

After: key: 'value'

I have only tested this a little, so please don't run this on anything important unless you have version control or other backups!

feh --scale-down --auto-zoom
git log --graph --decorate --pretty=oneline --abbrev-commit
git commit --allow-empty-message --message ""
2014-07-16 02:06:39
0

This is especially useful for adding changes to a temporary repo, such as a Gist. Avoid using this when collaborating with others.

find . -name "*.DS_Store" -type f -delete
gem install -g
ping -c 3 google.com
fn() { find . -iname "*$1*" -print; }
2014-07-15 05:30:59
User: suprjami
Functions: find
0

A simple bash function to the find command. I use this much more than find itself.

ethtool -S eth0 | egrep "(drop|disc|err|fifo|buf|fail|miss|OOB|fcs|full|frags|hdr|tso).*: [^0]"
2014-07-15 05:27:34
User: suprjami
Functions: egrep
0

A grep against ethtool to look for common errors and packet loss statistics which network drivers report in their private data, which is queried with ethool -S. This is the current grep used in xsos (https://github.com/ryran/xsos), which I originally contributed and has been improved by the community over time.

watch -n1 iptables -vnL
watch -n1 iptables -vnL
cut -f 2 -d ':' oclHashcat.pot | egrep -oi '[a-z]{1,20}' | sort | uniq > base.pot
php -r 'echo json_encode( unserialize( file_get_contents( "php://stdin" ) ) );'
pssh -h RemoteHosts.txt -P -I < ~/LocalScript.sh
2014-07-14 16:02:12
User: zlemini
1

Runs a local script over ssh assuming ssh keys are in place.

-P argument prints results to stdout.

# Uses - https://code.google.com/p/parallel-ssh/

postqueue -p | grep -A 1 "over quota" | grep @ | sort | uniq | tr --delete ' '