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,493 results
dumpe2fs -h /dev/sdX
2011-01-22 23:50:03
User: dmmst19
Functions: dumpe2fs
-2

You are probably aware that some percent of disk space on an ext2/ext3 file system is reserved for root (typically 5%). As documented elsewhere this can be reduced to 1% with

tune2fs -m 1 /dev/sdX (where X = drive/partition, like /dev/sda1)

but how do you check to see what the existing reserved block percentage actually is before making the change? You can find that with

dumpe2fs -h /dev/sdX

You get a raw block count and reserved block count, from which you can calculate the percentage. In the example here you can easily see that it's currently 1%, so you won't get any more available space by setting it to 1% again.

FYI If your disks are IDE instead of SCSI, your filesystems will be /dev/hdX instead of /dev/sdX.

mkdir -p /cdrom/unnamed_cdrom ; mount -F hsfs -o ro `ls -al /dev/sr* |awk '{print "/dev/" $11}'` /cdrom/unnamed_cdrom
2009-05-31 08:42:20
User: felix001
Functions: awk mkdir mount
-2

This will allow you to mount a CD-ROM on Solaris SPARC 9 or lower. This will not work on Solaris 10 due to void and the volume management daemons.

www.fir3net.com

sudo mount -t cifs //$ip_or_host/$sharename /mnt
2009-11-23 14:24:02
User: sb
Functions: mount sudo
-2

Mount a Windows share. Usually the IP is needed for the $ip_or_host option. Getting hostnames working on a local network never seems to work.

/sbin/ifconfig eth0 | grep 'inet6 addr:' | awk {'print $3'}
ls -ltp | sed '1 d' | head -n1
2011-10-17 16:21:15
Functions: head ls sed
-2

wrap it in a function if you like...

lastfile () { ls -ltp | sed '1 d' | head -n1 }
cat /proc/cpuinfo
rsync -avvvz -e "ssh -i /root/.ec2/id_rsa-gsg-keypair" --archive --progress /root/.ec2/id_rsa-gsg-keypair root@ec2-75-101-212-113.compute-1.amazonaws.com:/root
2010-01-22 16:53:42
User: svnlabs
Functions: rsync
-2

Connect EC2 server with public keys "/root/.ec2/id_rsa-gsg-keypair" or "/root/.ec2/keypair.pem"

alias cd='pushd'; alias cd-='popd'
2010-11-30 16:44:46
User: conan
Functions: alias
-2

You know there 'cd -' to go to the previous directory you were standing before, but it will no record more than one. With these alias you can now record all your directory changes and go back whenever you need it. However you will have to get accustomed to use 'cd ~' from now on to go to your home directory.

for fn in xkcd*.png xkcd*.jpg; do echo $fn; read xw xh <<<$(identify -format '%w %h' $fn); nn="$(echo $fn | sed 's/xkcd-\([^-]\+\)-.*/\1/')"; wget -q -O xkcd-${nn}.json http://xkcd.com/$nn/info.0.json; tt="$(sed 's/.*"title": "\([^"]\+\)",.*/\1/' ...
2012-01-06 20:26:11
User: fpunktk
Functions: echo read wget
-2

full command:

for fn in xkcd*.png xkcd*.jpg; do; echo $fn; read xw xh <<<$(identify -format '%w %h' $fn); nn="$(echo $fn | sed 's/xkcd-\([0-9]\+\)-.*/\1/')"; wget -q -O xkcd-${nn}.json http://xkcd.com/$nn/info.0.json; tt="$(sed 's/.*"title": "\([^"]*\)", .*/\1/' xkcd-${nn}.json)"; at="$(sed 's/.*alt": "\(.*\)", .*/\1/' xkcd-${nn}.json)"; convert -background white -fill black -font /usr/share/fonts/truetype/freefont/FreeSansBold.ttf -pointsize 26 -size ${xw}x -gravity Center caption:"$tt" tt.png; convert -background '#FFF9BD' -border 1x1 -bordercolor black -fill black -font /usr/share/fonts/truetype/freefont/FreeSans.ttf -pointsize 16 -size $(($xw - 2))x -gravity Center caption:"$at" at.png; th=$(identify -format '%h' tt.png); ah=$(identify -format '%h' at.png); convert -size ${xw}x$(($xh+$th+$ah+5)) "xc:white" tt.png -geometry +0+0 -composite $fn -geometry +0+$th -composite at.png -geometry +0+$(($th+$xh+5)) -composite ${fn%\.*}_cmp.png; echo -e "$fn $nn $xw $xh $th $ah \n$tt \n$at\n"; done

this assumes that all comics are saved as xkcd-[number]-[title].{png|jpg}.

it will then download the title and alt-text, create pictures from them, and put everything together in a new png-file.

it's not perfect, but it worked for nearly all my comics.

it uses the xkcd-json-interface.

though it's poorly written, it doesn't completely break on http://xkcd.com/859/

ifconfig eth0 | grep 'HWaddr' | awk '{print $5}'
ip -f inet addr show eth0
netstat -an | grep -i listen
2009-02-19 19:27:49
User: scubacuda
Functions: grep netstat
-2

From 'man netstat'

"netstat -i | -I interface [-abdnt] [-f address_family] [-M core] [-N system]

Show the state of all network interfaces or a single interface

which have been auto-configured (interfaces statically configured

into a system, but not located at boot time are not shown). An

asterisk (``*'') after an interface name indicates that the

interface is ``down''. If -a is also present, multicast

addresses currently in use are shown for each Ethernet interface

and for each IP interface address. Multicast addresses are shown

on separate lines following the interface address with which they

are associated. If -b is also present, show the number of bytes

in and out. If -d is also present, show the number of dropped

packets. If -t is also present, show the contents of watchdog

timers."

rsync -avvvz -e "ssh -i /root/.ec2/id_rsa-gsg-keypair" --archive --progress /root/.ec2/id_rsa-gsg-keypair root@ec2-75-101-212-113.compute-1.amazonaws.com:/root
2010-01-22 17:21:58
User: lalit241
Functions: rsync
-2

Connect EC2 server with public keys "/root/.ec2/id_rsa-gsg-keypair" or "/root/.ec2/keypair.pem"

function fur () { curl -sL 'http://www.commandlinefu.com/commands/random/plaintext' | grep -v "^# commandlinefu" }
IFS=?" ; for i in * ; do mv -v $i `echo $i|tr ???????????????????\ aaaeeiooAAAEEIOOOcC_` ; done
ls -lFart |tail -n1
2011-10-17 19:49:14
User: jambino
Functions: ls tail
Tags: tail pipe ls
-2

List all files in a directory in reverse order by modified timestamp. When piped through tail the user will see the most recent file name.

cat /dev/zero > /dev/null &
2009-03-02 18:18:52
User: gustavold
Functions: cat
-2

Just waste some resources in a philosophical way

history | sed -e 's/^sudo //' | awk '{print $2}' | sort | uniq -c | sort -rn | head
2012-01-07 22:29:54
User: bibe
Functions: awk sed sort uniq
-2

I make an extensive use of sudo, so I had to exclude the sudo part of the command history

lynx -source http://www.commandlinefu.com/commands/random | sed 's/<[^>]*>//g' | head -1037 | tail -10 | sed -e 's/^[ \t]*//' | sed '/^$/d' | head -2
watch -tn1 'date -u +%T -d @$(expr $(date -d HH:MM +%s) - $(date +%s)) | toilet -f bigmono12'
2010-06-26 11:56:11
User: prayer
Functions: date expr watch
Tags: date time
-2

Change HH:MM with your target time.

This is for a Debian/Ubuntu GNU system. You need bash (package bash), date (package coreutils) and toilet (package toilet). Install with:

# apt-get install bash coreutils toilet toilet-fonts

find . -depth \( -path '*/*.java.orig' -o -path '*/*.java.orig/*' \) -delete
find . -name "*.pyc" -exec rm {} \;
2009-02-16 17:15:58
User: nsmgr8
Functions: find rm
-2

For a python project, sometimes I need to clean all the compiled python files. I have an alias 'rmpyc' to this command. This really saves me a lot of typing and hunting throughout the folders to delete those files.

grep -r 'keyword keyword2' your/path/ | grep -v svn
2009-07-08 20:48:11
User: anis
Functions: grep
-2

this command searches for a keyword or an expression in a path and avoids versionned files

mount | grep : | tr -s ' ' -d 3 | xargs umount -v
ls -F | sed -n 's/@$//p'