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
wget -N --content-disposition http://www.adminer.org/latest.php
ps -efL | grep <Process Name>
ifconfig | egrep -A2 "eth|wlan" | tr -d "\n"| sed 's/\-\-/\n/g'|awk '{print "mac: "$5 " " $7}' | sed 's/addr:/addr: /g'
EXT=MOV; for i in *.$EXT; do HandBrakeCLI -Z Normal --optimize --use-opencl --width 1280 --height 720 -i "${i}" -o "${i//.$EXT}.mp4"; done
for I in *.CR2; do if [ `exiv2 pr -p a -u $I | grep 'xmp.Rating' | awk '{ print $4 }'` == "1" ]; then echo $I; fi; done
perl -MPOSIX -le 'print strftime "%F", localtime 1234567890'
iptables -L -vnx --line-numbers; iptables -t nat -D <chain-name> <number>
mysql -u{user} -p{password} -Ne "select distinct concat( \"SHOW GRANTS FOR '\",user,\"'@'\",host,\"';\" ) from user;" mysql | mysql -u {user} -p{password} | sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}'
dbus-send --system --print-reply --dest="org.freedesktop.login1" /org/freedesktop/login1 org.freedesktop.login1.Manager.Suspend boolean:true
alias noc="awk 'NF && ! /^[[:space:]]*#/'"
2014-09-07 00:50:57
User: pooderbill
Functions: alias
0

The shortest and most complete comment/blank line remover...

Any line where the first non-whitespace character is # (ie, indented # comments), and all null and blank lines are removed. Use the alias as a filter:

noc /etc/hosts

or

grep server /etc/hosts | noc

Change to nawk depending awk versions.

convert input.png -alpha set -channel A -fx 0.5 output.png
tar -cpf - ./sourceFile | tar -xpf - -C ./targetDir/
ifconfig | head -n 2 | tr -d '\n' | sed -n 's/.*\(00:[^ ]*\).*\(adr:[^ ]*\).*/mac:\1 - \2/p'
git stash save --keep-index
( eval $(grep -z '^DBUS_SESSION_BUS_ADDRESS' /proc/$(pgrep -u $USER plasma-overlay)/environ); export DBUS_SESSION_BUS_ADDRESS; kquitapp plasma-overlay )
2014-09-01 12:49:58
User: mig_hg
Functions: eval export grep
0

So this first obtains address of the DBUS session, as it's not available by default over SSH. Then it tells plasma-overlay to exit. `kquitapp` is pretty much an equivalent of the qdbus calls.

SIZE=1; dd if=/dev/zero bs=1M count=$((SIZE*1024)) | pv -pters $((SIZE*1024*1024*1024)) | openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt > randomfile
2014-08-30 01:46:51
User: kennethjor
Functions: dd
0

SIZE is the number of gigabytes and the file name is at the end. Random data is generated by encrypting /dev/zero, similar to other techniques posted on here.

find -type f -exec ffprobe -i "{}" -show_entries format=duration -v quiet -of csv="p=0" \; | paste -sd+ | bc
2014-08-29 23:45:09
User: Hype
Functions: find paste
0

Recursive. Ignores non-media files. Requires ffprobe, paste, and bc.

function findOlderThan () { find . -mmin -$((($(date "+%s") - $(stat -c %Y $1))/60)) -type f ; }
2014-08-29 17:52:34
User: RobertDeRose
Functions: date find stat
Tags: find date stat
0

This function will find the modification time in unix_time of the given file, then calculate the number of minutes from now to then and then find all files modified in that range.

while true; do ps aux | sort -rk 3,3 | head -n 11 | cut -c -120 | netcat -l -p 8888 2>&1 >/dev/null; done &
2014-08-29 07:10:57
User: manumiu
Functions: cut head ps sort
0

If you want to see your top ten cpu using processes from the browser (e.g. you don't want to ssh into your server all the time for checking system load) you can run this command and browse to the machines ip on port 8888. For example 192.168.0.100:8888

for i in chmod chown; do sudo "$i" --reference=/home/user/copyfromfile /tmp/targetfile; done
2014-08-28 15:08:32
User: zlemini
Functions: chmod sudo
2

Copy both perms and owner group from one file to another.

curl -sSi <URL> | sed '/^\r$/q'
2014-08-27 15:47:05
User: cbuckley
Functions: sed
Tags: curl http
0

Similar to the following:

curl -I <URL>

but curl -I performs a HEAD request, which can yield different results.

ogr2ogr -f GeoJSON output.geojson input.shp
finfd./ -name logs -type f -size 50
wget -qO- http://whatthecommit.com/index.txt | cowsay
2014-08-26 18:56:06
User: optyler
Functions: wget
1

No need to parse html page, website gives us a txt file :)