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,857 results
pbpate | sort | pbcopy
pbpaste | say -v Alex -o /tmp/say.aiff && sox /tmp/say.aiff say.mp3
git log master...feature-a | grep -o -E '\b([A-Z]+)-[0-9]+\b' | sort | uniq
2014-07-07 18:51:01
User: westonruter
Functions: grep sort
0

To get the list of tickets in a comma-separated list, pipe the above into:

sort | uniq | perl -pe 's/\n/, /' | sed 's/, $//'
wget -r -nd -q -A "*.ext" http://www.example.org/
wget www.google.com
csi -R uri-common -p '(uri-decode-string (read-line))'
powershell -Command "while (\$true){Try{\$process=Get-Process firefox -ErrorAction Stop}Catch [Microsoft.PowerShell.Commands.ProcessCommandException]{break;}if (\$process) {\$whateva=\$process.CloseMainWindow()}else {break;}Start-Sleep -m 500}"
2014-07-04 11:06:22
User: adanisch
0

This command will loop until the process no longer exists, calling closemainwindow() this is as if the user clicked the close window x in the upper right hand corner and gives the user an opportunity to save work in many applications like notepad and other things. The $'s are escaped for Cygwin, if you want to run the same command from the RUN box or cmd.exe shell then just unescape the $'s:

powershell -Command "while ($true){Try{$process=Get-Process calc -ErrorAction Stop}Catch [Microsoft.PowerShell.Commands.ProcessCommandException]{break;}if ($process) {$whateva=$process.CloseMainWindow()}else {break;}Start-Sleep -m 500}"

# dstat
macdst="5873b856445f";macsrc="d2a791e1715a";pkt="d4c3b2a1020004000000000000000000ffff000001000000e3eab353fa1f 0b007400000074000000$macdst $macsrc 0842ffffffffffff";for i in {1..16}; do pkt="$pkt $macdst"; done; echo "$pkt" | xxd -r -p > magicpacket.pcap
2014-07-02 17:37:44
Functions: echo
0

just set macdst to the mac address of the system

you wish to wake up, the macsrc is optional but helps

use tcpreplay to broadcast or wireshark to view

sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
ssh <user>@<ip address> $(echo wmic process where \"name like \'%<process to kill>%\'\" delete)
2014-07-02 04:41:05
User: adanisch
Functions: echo ssh
0

Tested on Windows 8 w/SSH, Cygwin - it can be tricky to quote if you dont use the $(..) syntax to echo it back out

perl -M URI::Escape -lne 'print uri_unescape($_)'
echo "btrfs checksum error(s) on: " && grep "btrfs: checksum error at logical" /var/log/messages | sed -e 's/^.*\( dev .*\)\(, sector.*\)\(path\: .*\))/\t\1, \3/' | sort | uniq
grep "btrfs: checksum error at logical" /var/log/messages | egrep -o "[^ ]+$" | tr -d ')' | sort | uniq
2014-07-01 08:15:26
User: jcoll
Functions: egrep grep sort tr
0

Filter entries in OpenSuse /var/log/messages like:

timestamp servername kernel: [83242.108090] btrfs: checksum error at logical 1592344576 on dev /dev/sda5, sector 5223584, root 5, inode 2652, offset 282624, length 4096, links 1 (path: log/warn)

echo -e '\x2Hello, folks\t!\r' | sed "y/\x2\x9\xD\x20/&#9218;&#9225;&#9229;&#9248;/"
2014-06-30 14:42:15
User: hermannsw
Functions: echo sed
0

Not better, but more lightweight (sed instead of perl).

Above command is reduced due to length restriction of less than 256 characters and entity encoding of "Save" command on this page. This is complete command (best without entity encoding):

echo -e '\x2Helo folks\t!\r' | sed "y/\x0\x1\x2\x3\x4\x5\x6\x7\x8\x9\xA\xB\xC\xD\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20/&#9216;&#9217;&#9218;&#9219;&#9220;&#9221;&#9222;&#9223;&#9224;&#9225;&#9226;&#9227;&#9228;&#9229;&#9230;&#9231;&#9232;&#9233;&#9234;&#9235;&#9236;&#9237;&#9238;&#9239;&#9240;&#9241;&#9242;&#9243;&#9244;&#9245;&#9246;&#9247;&#9248;/"

␂Helo␠folks␉!␍

/bin/echo -e '\002Hello, Folks\t!\r' | perl -pwle 'use v5.14; s/([\N{U+0000}-\N{U+0020}])/chr(9216+ord($1))/ge;'
2014-06-30 01:45:40
User: scruss
Functions: perl
1

Converts control codes and spaces (ASCII code ≤ 32) to visible Unicode Control Pictures, U+2400 ? U+2420. Skips \n characters, which is probably a good thing.

puppet cert -la
echo -e "a\na\nb\nc\nd" | awk '{x[$0]++}END{for (z in x){if(x[z]==1){print z}}}'
for a in $(find . -maxdepth 1 -name "*.mp4" -type f -printf "%f\n" | rev | cut -d '.' -f2- | rev | sort -u); do if [ ! -f "$a.mp3" ]; then avconv -i "$a."* -vn -ab 128 "$a.mp3"; fi done
2014-06-27 05:13:53
User: adanisch
Functions: cut find rev sort
0

Good for when you download youtube videos and want the mp3 for your mp3 player.

aws ec2 describe-snapshots --filter 'Name=volume-id,Values=vol-abcd1234' | jq '.[]|max_by(.StartTime)|.SnapshotId'
2014-06-26 20:26:23
User: thatinstant
Tags: aws EC2 jq elb
0

Uses the python-based AWS CLI (https://aws.amazon.com/cli/) and the JSON query tool, JQ (https://stedolan.github.io/jq/)

aws ec2 describe-instances --query "Reservations[*].Instances[*]" | jq '.[]|.[]|(if .Tags then (.Tags[]|select(.Key == "Name").Value) else empty end)+", " +.InstanceId'
2014-06-26 20:01:12
User: thatinstant
Tags: aws EC2 jq
0

Uses the python-based AWS CLI (https://aws.amazon.com/cli/) and the JSON query tool, JQ (https://stedolan.github.io/jq/)

du -ch `cat test_file.txt`
2014-06-26 08:59:05
User: mase
Functions: du
0

in test_file.txt:

/var/img/1/368/ID_2012MTH03DT15.zip

/var/img/1/368/ID_2012MTH03DT16.zip

/var/img/1/368/ID_2012MTH03DT16N.zip

/var/img/1/368/ID_2012MTH03DT16E.zip

/var/img/1/368/ID_2012MTH03DT17M.zip

/var/img/1/368/ID_2012MTH03DT17N.zip

/var/img/1/368/ID_2012MTH03DT17E.zip

/var/img/1/368/ID_2012MTH03DT18M.zip

/var/img/1/368/ID_2012MTH03DT18N.zip

/var/img/1/368/ID_2012MTH03DT19M.zip

/var/img/1/368/ID_2012MTH03DT19N.zip

/var/img/1/368/ID_2012MTH03DT19E.zip

/var/img/1/368/ID_2012MTH03DT20M.zip

/var/img/1/368/ID_2012MTH03DT20N.zip

/var/img/1/368/ID_2012MTH03DT20E.zip

/var/img/1/368/ID_2012MTH03DT21M.zip

FOR /F "delims==" %%A IN ('type ips.txt') DO wmic /Node:%%A wmic /user:username /password:yourpassword /FAILFAST:ON process where "name like '%.exe'" call getowner
2014-06-26 01:53:29
User: operat0r
Tags: wmic hacking
0

This is used during pentest to quickly poll all the processes running on a set of systems you have common credentials for the /FAILFAST:ON speeds up the scans.

ls /EMRCV5/
ssh -D 8080 -f -N srv1
2014-06-25 12:46:44
User: fr00tyl00p
Functions: ssh
0

Provides a SOCKS5 proxy on localhost port 8080 which will tunnel all connections through srv1 and run in the background.