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,848 results
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/␂␉␍␠/"
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/␀␁␂␃␄␅␆␇␈␉␊␋␌␍␎␏␐␑␒␓␔␕␖␗␘␙␚␛␜␝␞␟␠/"

␂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.

echo "some cool message from terminal" | mail -s "test" email@address.com
git verify-pack -v .git/objects/pack/pack-*.idx | grep blob | sort -k3nr | head | while read s x b x; do git rev-list --all --objects | grep $s | awk '{print "'"$b"'",$0;}'; done
mco ping | head -n -4 | awk '{print $1}' | sort
ffmpeg -i input.ogv -qscale 0 output.wmv # convert .ogv to .wmv
2014-06-24 16:23:18
User: mpb
0

I needed to convert a screen capture when using Gnome's "recordmydesktop" and convert it to a .wmv for playback in Windows.

find . -type f -size +50000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
xcowsay "$(cowsay smile)"
mkfifo /tmp/view; nc -l 9876 < /tmp/view& script -f /tmp/view
2014-06-23 05:06:13
User: snipertyler
Functions: mkfifo script
Tags: Network nc fifo
4

connect to it with any network command (including web browser - if you don't mind weird formatting)

curl 127.0.0.1:9876

nc 127.0.0.1 9876

echo "Dave" | grep -o "bob" | sed 's/D/f/'; echo ${PIPESTATUS[1]};
2014-06-21 04:00:53
User: davethomas11
Functions: echo grep sed
Tags: PIPESTATUS
0

Using the $PIPESTATUS array you can get the results of a command in a sequence of commands piped together. The command above returns the result of grep -o "bob", which is exit result of 1 since no match was made.

message="I have a nice easy typing pace"; for ((i=0; i<${#message}; i++)); do echo "after 200" | tclsh; printf "${message:$i:1}"; done; echo;
curl 'LINK' | pdftotext - - | less
2014-06-21 00:47:02
User: snipertyler
Tags: less pdf convert
4

Probably will not work very well with scanned documents.

wbinfo - Get all users group membership, with primary group starred (Red description for full command)
2014-06-20 20:45:52
User: jaimerosario
Functions: users
Tags: samba wbinfo
0

###

for ADUSER in $(wbinfo -u --domain="$(wbinfo --own-domain)" | sort); do WBSEP=$(wbinfo --separator); ADUNAME=$(wbinfo -i "$ADUSER" | cut -d ":" -f5); UINFO=$(wbinfo -i "$ADUSER" | cut -d ":" -f4); SIDG=$(wbinfo -G "$UINFO"); GROUPID=$(wbinfo -s "$SIDG" | sed 's/.\{1\}$//' | cut -d "$WBSEP" -f2); echo -e "$ADUSER ($ADUNAME)\n$(printf '%.s-' {1..32})\n\t[*] $GROUPID"; for GID in $(wbinfo -r "$ADUSER"); do SID=$(wbinfo -G "$GID"); GROUP=$(wbinfo -s "$SID" | cut -d " " -f1,2); echo -e "\t[ ] $(echo -e "${GROUP/%?/}" | cut -d "$WBSEP" -f2)"; done | sed '1d'; echo -e "$(printf '%.s=' {1..32})\n"; done

###

echo "I am $BASH_SUBSHELL levels nested";
php -v