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,605 results
tail -1f /var/opt/fds/logs/TraceEventLogFile.txt.0 | grep <msisdn> | tee <test-case-id>.trace | tr '|' '\n'
2014-08-21 19:29:07
User: neomefistox
Functions: grep tail tee tr
0

This command allows to follow up a trace on SDP (CS5.2), at the same time as the trace records are stored in the file with "raw" format.

Trace files in native format are useful to filter the records before to translation from '|' to '\n'.

Example:

grep -v OP_GET <raw-records>.trace | tr '|' '\n'
ffmpeg -acodec copy -vcodec copy -ss 00:05:00 -t 00:20:00 -i file.mp4 file_cropped.mp4
curl -L https://gist.github.com/westonruter/ea038141e46e017d280b/download | tar -xvz --strip-components=1
2014-08-19 22:19:44
User: westonruter
Functions: tar
Tags: gist
0

https://twitter.com/westonruter/status/501855721172922369

tr -dc '\x15-\x7e' < /dev/urandom| head -c 16 | paste
xclip -selection clipboard -o -t text/html | pandoc -f html -t markdown_github -
2014-08-18 20:47:46
User: keymon
2

I always wanted to be able to copy formatted HTML, like from emails, on trello cards or READMEs... but the formatting is always wrong... But from this two links:

* https://jeremywsherman.com/blog/2012/02/08/pasting-html-into-markdown/

* http://stackoverflow.com/questions/3261379/getting-html-source-or-rich-text-from-the-x-clipboard

For instance, to to copy an formatted email to a trello card, just:

1. Select the email body

2. run: xclip -selection clipboard -o -t text/html | pandoc -f html -t markdown_github - | xclip -i -t text/plain

3. Paste in your trello card

4. Profit!

8-)

YEAR=2015; echo Jul $(ncal 7 $YEAR | awk '/^Fr/{print $NF}')
2014-08-17 11:12:09
User: andreasS
Functions: awk echo
Tags: awk date
0

Calculate the date of Sysadmin day (last Friday of July) of any given year

YEAR=2015; date -d${YEAR}0801-$(date -d${YEAR}0801+2days +%u)days +%b\ %e
2014-08-17 11:06:25
User: andreasS
Functions: date
Tags: date
0

Calculate Sysadmin day of any given year using 2 `date`. Code based on http://stackoverflow.com/a/5656859/196133

YEAR=2015; ncal 7 $YEAR | sed -n 's/^Fr.* \([^ ]\+\) *$/Jul \1/p'
2014-08-17 11:04:02
User: andreasS
Functions: sed
Tags: sed date
0

Calculate the date of Sysadmin day (last Friday of July) of any given year

awp () { awk '{print $'$1'}'; }
echo 1 > /proc/sys/sunrpc/nfs_debug
2014-08-12 14:40:55
User: harpo
Functions: echo
0

echo 1 > /proc/sys/sunrpc/nfs_debug && tail -f /var/log/messages

to debug NFS issues.

eval echo $(echoprint-codegen "/path/to/file.mp3"| jq ' .[0].metadata | "mp3info -a \"" + .artist + "\" -t \"" + .title + "\" -l \"" + .release + "\" \"" + .filename + "\"" ' ) | bash
2014-08-08 21:14:53
User: glaudiston
Functions: echo eval
0

echoprint identify your song, then return artist, song name and album name(release) in a JSON. jq parse it and mp3info set the data in your mp3 file.

of course it depends on:

mp3info

jq

echoprint

You need to set the environment variable

export CODEGEN_NEST_API_KEY='YOUR_ECHONEST_KEY_HERE'

You can use it with find, but probably will bypass the 120 request/minute of developer account key. So, use a sleep to do it.

Something like:

find -name \*.mp3 | while read $f; do eval echo $(echoprint-codegen "$f" | jq ' .[0].metadata | "mp3info -a \"" + .artist + "\" -t \"" + .title + "\" -l \"" + .release + "\" \"" + .filename + "\"" ' ) | bash; sleep 1; done
[ `curl 'http://crl.godaddy.com/gds5-16.crl' 2>/dev/null | openssl crl -inform DER -noout -nextupdate | awk -F= '{print $2}' | xargs -I{} date -d {} +%s` -gt `date -d '8 hours' +%s` ] && echo "OK" || echo "Expires soon"
2014-08-07 17:18:38
User: hufman
Functions: awk date echo xargs
Tags: openssl
0

Downloads a CRL file, determines the expiration time, and checks when it will expire

sudo dpkg -P $(dpkg -l yourPkgName* | awk '$2 ~ /yourPkgName.*/ && $1 ~ /.i/ {print $2}')
2014-08-06 22:40:32
User: wejn
Functions: awk sudo
Tags: dpkg purge
0

Recently in Debian Wheezy the dpkg command refuses to work with wildcards, so this is the one-liner alternative. (alternative to #13614)

svn merge -r 854:853 l3toks.dtx
(echo -e '\x06\x00\x00\x00\x00\x00\x01\x01\x00'; sleep 1)|nc -c $host 25565
sudo dpkg -P $(sudo dpkg -l yourPkgName* | awk '$2 ~ /yourPkgName.*/' | awk '$1 ~ /.i/' | awk '{print $2}')
2014-08-02 18:14:02
User: woohoo
Functions: awk sudo
Tags: dpkg purge
0

Recently in Debian Wheezy the dpkg command refuses to work with wildcards, so this is the one-liner alternative.

Mac OSX: ping -oc 30 8.8.4.4 > /dev/null && say "Google name server is up" || say "This host is down"
2014-08-01 15:44:57
User: raulyca
Functions: ping
Tags: ping beep
4

Audio acknowledgement for host availability.

When running the command from a Linux systems, you can use "festival" or "espeak" instead of "say".

tar cvzf - dir | ssh my_server 'tar xzf -'
find /var/log -type f -iregex '.*[^\.][^0-9]+$' -not -iregex '.*gz$' 2> /dev/null | xargs tail -n0 -f | ccze -A
2014-07-29 17:11:17
User: rubo77
Functions: find tail xargs
Tags: unix ccze logging
3

This will show all changes in all log files under /var/log/ that are regular files and don't end with `gz` nor with a number

awk -F: '{print $2}' access_log | sort | uniq -c
for a in $(seq 15); do (xset led 3);(xset -led 3);sleep .9;done
docker ps -q | xargs -n 1 docker inspect | jq '.[0].NetworkSettings.Ports +{} | map(select(. != null)[0].HostPort) | map("-L \(.):localhost:\(.)") ' | sed -n 's/.*"\(.*\)".*/\1/p' |xargs boot2docker ssh -N
for i in {1..100}; do convert -background lightblue -fill blue -size 100x100 -pointsize 24 -gravity center label:$i $i.jpg; done
grep -r "<script" | grep -v src | awk -F: '{print $1}' | uniq
2014-07-23 06:24:31
User: sucotronic
Functions: awk grep
Tags: PHP javascript
2

Useful to crawl where the javascript is declared, and extract it a common file. You can redirect it to a file to review item by item.

find -L -type l
2014-07-22 19:52:18
Functions: find
6

-L tells find to follow symbolic links, so -type l will only return links it can't follow (i.e., those that are broken).