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,925 results
for i in `screen -ls | perl -ne'if(/^\s+\d+\.([^\s]+)/){print $1, " "}'`; do gnome-terminal -e "screen -x $i"; done
2009-04-25 22:39:24
User: hank
Functions: perl
Tags: screen Linux perl
2

There was another line that was dependent on having un-named screen sessions. This just wouldn't do. This one works no matter what the name is. A possible improvement would be removing the perl dependence, but that doesn't effect me.

for img in $( ls *.CR2 ); do convert $img $img.jpg; done
for i in /sys/class/net/*; do e=`basename $i`; echo "# $e"; sudo ethtool $e | grep -E "Link|Speed" ; done
2009-04-25 14:32:08
User: hank
Functions: echo grep sudo
Tags: Network Linux
0

Basically an improvement on an earlier ethtool command line.

lsof -i
mkdir $(date +%Y%m%d)
2009-04-25 14:16:45
User: thebodzio
Functions: date mkdir
Tags: alias date mkdir
11

Not a discovery but a useful one nontheless.

In the above example date format is 'yyyymmdd'. For other possible formats see 'man date'.

This command can be also very convenient when aliased to some meaningful name:

alias mkdd='mkdir $(date +%Y%m%d)'
lndir sourcedir destdir
2009-04-24 18:30:29
4

Lndir create from source directory to destination directory a full symlink tree of all contents of source directory, really useful for propagate changes from a directory to another.

look mysql /etc/group
2009-04-24 18:20:20
Functions: look
-2

Look search for lines in a file that beginning with a given string.

Same as $ grep ^n /etc/passwd

echo "A great password" | md5sum
2009-04-24 14:32:56
User: ubersoldat
Functions: echo
-5

You can also use sha1sum and variants for longer passwords

/usr/local/bin/OFPW -mode 1
/usr/local/bin/OFPW -pass thepassword
hwinfo --block --short
2009-04-24 11:13:31
13

Yields entries in the form of "/dev/hda1" etc.

Use this if you are on a new system and don't know how the storage hardware (ide, sata, scsi, usb - with ever changing descriptors) is connected and which partitions are available.

Far better than using "fdisk -l" on guessed device descriptors.

for i in `ls *xml`; do sed -e 's,oldpassword,newpassword,g' $i > $i.2 && mv -f $i.2 $i ; done
sed 's/\o0/\n/g' /proc/INSERT_PID_HERE/environ
mvn deploy:deploy-file -DgroupId=groupId -DartifactId=artifactId -Dversion=1.0 -Dpackaging=jar -Dfile=pathtolib -DrepositoryId=repository -Durl=url
meld <(antiword microsoft_word_a.doc) <(antiword microsoft_word_b.doc)
find ./ -type f -exec chmod 644 {} \;
m-a a-i open-vm
2009-04-22 20:08:00
User: m03hr3
-4

compile and install openvm-tools module in debian lenny

smbclient -U userbob //10.1.1.75/Shared
2009-04-22 19:58:51
User: ethanmiller
3

Under Ubuntu smbclient is part of the samba package. With the version I use (3.0.28a) cd-ing into folders with spaces in the name is a drag. You have to put the folder name in quotes:

smb: \Shared\> cd "Marketing and PR"

for M in 0 1 2 3 ; do echo eth$M ;/sbin/ethtool eth$M | grep -E "Link|Speed" ; done
2009-04-22 19:32:41
User: Wubby
Functions: echo grep
6

Give the Speed and Link status of eth# 0-3. This is sort of what mii-tool does, but eth-tool is better, yet lacks device discovery.

yes '' | cat -n
. ~/.profile
2009-04-22 16:56:12
User: ruchi
-5

If you edit your .profile you need to refresh it for changes to take place. Simple way to refresh is logout and login. This command is the quickest way to do it.

If you're deleting some variables, they would not get nulled with this command but just removed.

ps -L -p <pid> | wc -l
screen -ls | grep pts | gawk '{ split($1, x, "."); print x[1] }' | while read i; do gnome-terminal -e screen\ -dx\ $i; done
2009-04-22 10:36:39
User: microft
Functions: gawk grep read screen
3

connects to all the screen instances running.

sudo cat /dev/mem > /dev/dsp
vrms
2009-04-22 06:54:20
User: eastwind
-3

tell you how many Non free software is on your machine, which package it is and which restriction on freedom it has . require vrms package , vrms mean virtual Richard M. Stallman :)