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.

Universal configuration monitoring and system of record for IT.
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

Top Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 12,065 results
< <infile> tr ' \t' '\n' | tr -s '\n' > <outfile>
2009-07-07 01:17:47
User: qubyte
Functions: tr
Tags: shell tr
-1

Puts words on new lines, removing additional newlines.

for x in *.ogg; do ffmpeg -i "$x" "`basename "$x" .ogg`.mp3"; done
2009-09-04 20:23:09
User: Superhuman
Tags: ffmpeg ogg mp3 for
-1

Converts all ogg files to mp3 files in the current directory.

rm -R `ls | egrep -v 'dir1|dir2|file1'`
netstat -an | grep --color -i -E 'listen|listening'
cat /etc/psa/.psa.shadow
2009-04-30 18:08:12
User: jigglebilly
Functions: cat
-1

I'm sure almost everybody knows this by now. This command will pull the password for the admin login of any plesk machine.

mencoder mf://image1.jpg,image2.jpg,image3.jpg -mf w=800:h=600:fps=25:type=jpeg -ovc copy -oac copy -o output.avi
2009-10-21 09:17:22
User: eastwind
-1

syntax :

mencoder mf://filemask -mf

option availble for mf :

* w=value : the width of the output, by d?fault : autodetected

* h=value : height of the output, by default : autodetected

* fps=value : framerate of the output, by default : 25

* type=value : file format type input , avaible: jpeg, png, tga, sgi

lynx -dump -head http://www.example.com/
2009-03-31 18:41:36
User: penpen
-1

Without the -dump option the header is displayed in lynx. You can also use w3m, the command then is

w3m -dump_head http://www.example.com/
file /usr/bin/* | grep ELF | cut -d":" -f1
2010-02-17 14:01:52
Functions: cut file grep
-1

This is a dirty raw way to simply list ELF objects in a folder.

The output is ready to be parsed i.e to the stripper or what else needs a path to an ELF object.

gmetric -n $METRIC_NAME -v foo -t string -d 10
2009-05-29 14:21:24
User: root
Tags: ganglia
-1

The -d flag sets the lifetime of a metric and defaults to 0 hence why old metrics continue to be graphed in the dashboard. Submitting a dummy value and short lifetime ensures that the metric is removed from the dashboard.

echo capitalize | { dd bs=1 count=1 conv=ucase 2> /dev/null; cat ;}
lsusb -v | grep -o "[0-9A-Z]{16}"
2009-11-22 00:58:00
User: matthewbauer
Functions: grep lsusb
Tags: ipod
-1

This is a bit of a hack, but it will get your fwguid which is needed sometimes when using your iPod.

cat video.ogg | nc -l -p 4232 & wget http://users.bshellz.net/~bazza/?nombre=name -O - & sleep 10; mplayer http://users.bshellz.net/~bazza/datos/name.ogg
members () { dscl . -list /Users | while read user; do printf "$user "; dsmemberutil checkmembership -U "$user" -G "$*"; done | grep "is a member" | cut -d " " -f 1; };
2012-05-20 11:34:33
User: eduo
Functions: cut grep printf read
-1

Group membership in OS X is a mish-mash of standards that end up meaning there's almost a half-dozen of ways to belong to a group, what with group inheritance and automatic assignment. This means there's no easy command to find out all groups a user belongs to. The only sensible way then is to list all users and then query each user for membership.

NOTE: This is a function. Once input you can execute it by calling with a groupname.

tree -ah --du . | ack '\[(\d{3,}M|\d+.*G)\]'
vlc $(curl -s http://twitter.com/statuses/user_timeline/18855500.rss|grep play|sed -ne '/<title>/s/^.*\(http.*\)<\/title/\1/gp'|awk '{print $1}')
2009-03-02 05:36:19
User: tomwsmf
Tags: twitter
-1

This will play the audio goodness posted up on PlayTweets via twitter right form the ever loving cmdline. You do not even need a twitter account. I hashed this out in a bit of a hurray as the kids need to get to sleep....I will be adding a loop based feature that will play new items as they come in...after what your are listening to is over.

http://twitter.com/playTweets for more info on playtweets

ioreg -lw0 | grep IODisplayEDID | sed "/[^<]*</s///" | xxd -p -r | strings -6
ac -d | awk '{h=int($NF); m=($NF-h)*60; s=int((m-int(m))*60); m=int(m); print $0" = "h"h "m"m "s"s "}'
2010-06-24 08:08:41
User: karpoke
Functions: awk
Tags: awk ac
-1

'ac' is included in the package 'acct', which is described as "The GNU Accounting utilities for process and login accounting". Other interesting flags are:

* print statistics for a specified user

ac -d username

* print statistics for all the users

ac -p

With my command, the output is also printed in a sexagesimal, more readable, style.

for lib in `readelf -d /usr/bin/abiword | grep NEEDED | cut -f2 -d[ | cut -f1 -d]`; do [ -e /usr/lib/$lib ] && j=/usr/lib/$lib || j=`locate -l 1 $lib`; readlink -f $j ; done
pidof httpd | wc -w
2011-02-24 16:46:46
User: eneko
Functions: pidof wc
Tags: httpd
-1

Returns the number of running httpd processes

pgrep -c 'httpd|apache2'
2011-02-24 18:03:00
Tags: httpd
-1

this version is going to work on redhat/centos/suse AND ubuntu/debian systems

echo $(find <directory> -name '*.<extension>' -exec du -s {} \; | tee $(tty) | cut -f1 | tr '\n' '+') 0 | bc
2012-09-17 22:46:50
User: ysangkok
Functions: cut du echo find tee tr
-1

Also shows files as they are found. Only works from a tty.

sudo netstat -tulpn | grep :8080
find . -name "*.py" -exec grep -n -H -E "^(import|from) math" {} \;
for kern in $(grep "initrd " /boot/grub/grub.conf|grep -v ^#|cut -f 2- -d-|sed -e 's/\.img//g'); do mkinitrd -v -f /boot/initrd-$kern.img $kern; done
free -m | awk '/Mem/ {print $4}'