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

Commands by syssyphus from sorted by
Terminal - Commands by syssyphus - 19 results
[ $(df / | perl -nle '/([0-9]+)%/ && print $1') -gt 90 ] && df -hP | mutt -s "Disk Space Alert -- $(hostname)" admin@example.com
2009-10-15 21:11:54
User: syssyphus
Functions: df perl
3

put it in crontab to get an alert when / is over 89% utilization.

find . -name "whatever.*" -print0 | rsync -av --files-from=- --from0 ./ ./destination/
sitepass() { echo -n "$@" | md5sum | sha1sum | sha224sum | sha256sum | sha384sum | sha512sum | gzip - | strings -n 1 | tr -d "[:space:]" | tr -s '[:print:]' | tr '!-~' 'P-~!-O' | rev | cut -b 2-11; history -d $(($HISTCMD-1)); }
2009-10-01 20:14:57
User: syssyphus
Tags: Security
14

usage: sitepass MaStErPaSsWoRd example.com

description: An admittedly excessive amount of hashing, but this will give you a pretty secure password, It also eliminates repeated characters and deletes itself from your command history.

tr '!-~' 'P-~!-O' # this bit is rot47, kinda like rot13 but more nerdy

rev # this avoids the first few bytes of gzip payload, and the magic bytes.

(crontab -l; echo '* * * * * dmesg -c'; ) | crontab -
2009-09-30 18:13:38
User: syssyphus
Functions: crontab dmesg echo
5

this is helpful because dmesg is where i/o errors, etc are logged to... you will also be able to see when the system reboots or someone attaches a thumb drive, etc.

don't forget to set yourself up in /etc/aliases to get roots email.

dhclient -r && rm -f /var/lib/dhcp3/dhclient* && sed "s=$(hostname)=REPLACEME=g" -i /etc/hosts && hostname "$(echo $RANDOM | md5sum | cut -c 1-7 | tr a-z A-Z)" && sed "s=REPLACEME=$(hostname)=g" -i /etc/hosts && macchanger -e eth0 && dhclient
2009-09-28 22:07:31
User: syssyphus
Functions: hostname rm sed
Tags: privacy
7

this string of commands will release your dhcp address, change your mac address, generate a new random hostname and then get a new dhcp lease.

find -type f -name "*.avi" -print0 | xargs -0 mplayer -vo dummy -ao dummy -identify 2>/dev/null | perl -nle '/ID_LENGTH=([0-9\.]+)/ && ($t +=$1) && printf "%02d:%02d:%02d\n",$t/3600,$t/60%60,$t%60' | tail -n 1
2009-09-24 15:50:39
User: syssyphus
Functions: find perl printf tail xargs
8

change the *.avi to whatever you want to match, you can remove it altogether if you want to check all files.

ps -C program_name || { program_name & }
%! perl -MO=Deparse | perltidy
2009-09-24 03:32:04
User: syssyphus
Functions: perl
3

the command show can be run in vim, here is the same thing on the command line

cat script.pl | perl -MO=Deparse | perltidy
perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'
(echo "set terminal png;plot '-' u 1:2 t 'cpu' w linespoints;"; sudo vmstat 2 10 | awk 'NR > 2 {print NR, $13}') | gnuplot > plot.png
timeout 10 sleep 11
find -not -empty -type f -printf "%s\n" | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate
2009-09-21 00:24:14
User: syssyphus
Functions: find md5sum sort uniq xargs
53

This dup finder saves time by comparing size first, then md5sum, it doesn't delete anything, just lists them.

display "$(wget -q http://dynamic.xkcd.com/comic/random/ -O - | grep -Po '(?<=")http://imgs.xkcd.com/comics/[^"]+(png|jpg)')"
2009-09-14 18:40:14
User: syssyphus
Tags: wget xkcd
6

i sorta stole this from

http://www.shell-fu.org/lister.php?id=878#MTC_form

but it didn't work, so here it is, fixed.

---

updated to work with jpegs, and to use a fancy positive look behind assertion.

for db in $(mysql -e 'show databases' -s --skip-column-names); do mysqldump $db | gzip > "/backups/mysqldump-$(hostname)-$db-$(date +%Y-%m-%d-%H.%M.%S).gz"; done
perl -lne '$l{$_}=length;END{for(sort{$l{$a}<=>$l{$b}}keys %l){print}}' < /usr/share/dict/words | tail
find ~/.mozilla/firefox/ -type f -name "*.sqlite" -exec sqlite3 {} VACUUM \;
wget -nv http://en.wikipedia.org/wiki/Linux -O- | egrep -o "http://[^[:space:]]*.jpg" | xargs -P 10 -r -n 1 wget -nv
2009-08-31 18:37:33
User: syssyphus
Functions: egrep wget xargs
10

xargs can be used in this manner to download multiple files at a time, and xargs will in this case run 10 processes at a time and initiate a new one when the number running falls below 10.

find . -depth -type d -empty -exec rmdir -v {} +
2009-08-05 13:48:13
User: syssyphus
Functions: find rmdir
Tags: find
7

this will show the names of the deleted directories, and will delete directories that only no files, only empty directories.

unset HISTFILE
2009-05-20 14:46:18
User: syssyphus
Functions: unset
13

this will cause any commands that you have executed in the current shell session to not be written in your bash_history file upon logout