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,620 results
xclip -o -selection clipboard | sort | xclip -i -selection clipboard
2014-07-07 19:04:02
User: gumnos
Functions: sort
1

Does the same thing in environments where you have "xclip" instead of "pbpaste"/"pbpate" and "pbcopy".

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/, $//'
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
/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.

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.

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.

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.

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

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";
for file in *.pdf; do convert -verbose -colorspace RGB -resize 800 -interlace none -density 300 -quality 80 "$file" "${file//.pdf/.jpg}"; done
2014-06-19 15:52:42
User: malathion
Functions: file
Tags: pdf convert
2

Without the bashisms and unnecessary sed dependency. Substitutions quoted so that filenames with whitespace will be handled correctly.

alias echourl="wget -qO -"
2014-06-14 00:23:07
User: Sepero
Functions: alias
Tags: wget
1

Directly send the content of a url to standard out. This command is most convenient for sending the output of a download directly to another command.

for DOMAIN in $(wbinfo -m); do WBSEP=$(wbinfo --separator); ADSERVER=$(wbinfo ... (Read description for full command)))
2014-06-13 21:03:23
User: jaimerosario
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 ":" -f3); GINFO=$(wbinfo -i "$ADUSER" | cut -d ":" -f4); SIDU=$(wbinfo -U "$UINFO"); SIDG=$(wbinfo -G "$GINFO"); USERID=$(wbinfo -s "$SIDU" | sed 's/.\{1\}$//' | cut -d "$WBSEP" -f2); GROUPID=$(wbinfo -s "$SIDG" | sed 's/.\{1\}$//' | cut -d "$WBSEP" -f2); echo -e "$ADUSER:$USERID:$ADUNAME:$GROUPID"; done | column -tx -s:

###

rename 's/result_([0-9]+)_([0-9]+)_([0-9]+)\.json\.txt/sprintf("%d%02d%02d.txt",$3,$2,$1)/ge' result_*.txt
2014-06-13 07:34:32
User: sucotronic
Functions: rename
Tags: perl rename
0

Given a bunch of files with "wrong" date naming, it renames them in a "good" format.

watch -n10 --no-title "w3m http://www.livescore.com/ |egrep 'live [0-9H]+[^ ]'"
2014-06-12 21:44:26
Functions: watch
Tags: bash livescore
1

World Cup Live Score of the ongoing match.

Alternative to have the live score with the match statistics:

watch -n10 --no-title "w3m http://www.livescore.com/ |awk '/live [0-9H]+[^ ]/,/red cards/'"
translate () {lang="ru"; text=$*; wget -U "Mozilla/5.0" -qO - "http://translate.google.com/translate_a/t?client=t&text=$text&sl=auto&tl=$lang" | sed 's/\[\[\[\"//' | cut -d \" -f 1}
2014-06-10 12:08:51
User: klisanor
Functions: cut sed wget
2
translate some text

Change lang from ru to something else.

tcpdump -nni eth0 -e icmp[icmptype] == 8
2014-06-08 18:13:24
User: siamware
Functions: tcpdump
2

capture only ping echo requests with tcpdump

ncat -vlm 5 --ssl --chat 9876
2014-06-07 19:17:29
User: snipertyler
11

Client ~$ ncat --ssl localhost 9876

Change localhost to the correct ip address.

find . -type d -d 1 -print0 | xargs -0 du -sm | sort -nr
iotop
free -m