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,589 results
dlocate [ package | string ]
2009-04-19 20:19:06
User: udim
Tags: Debian
4

This is the fastest method to search the Debian package database.

Requires the dlocate package. The dlocate db updates periodically, but you may force an update with

# dlocate-update

awk 'BEGIN {srand()} {print int(rand()*1000000) "\t" $0}' FILE | sort -n | cut -f 2-
2009-04-19 20:04:58
User: udim
Functions: awk cut sort
-3

Replace FILE with a filename (or - for stdin).

find -type f -printf '%P\000' | egrep -iz '\.(avi|mpg|mov|flv|wmv|asf|mpeg|m4v|divx|mp4|mkv)$' | sort -z | xargs -0 ls -1
sl
emerge -epv world | grep USE | cut -d '"' -f 2 | sed 's/ /\n/g' | sed '/[(,)]/d' | sed s/'*'//g | sort | uniq > use && grep ^- use | sed s/^-// | sed ':a;N;$!ba;s/\n/ /g' > notuse && sed -i /^-/d use && sed -i ':a;N;$!ba;s/\n/ /g' use
2009-04-19 07:54:08
User: Keruspe
Functions: cut grep sed sort uniq
Tags: Gentoo emerge USE
1

This command puts all the flags of the USE variable actually used by the packages you emerged to the file "use", and those which are unused but available to the file "notuse"

mount --bind /old/directory/path /new/directory/path
2009-04-19 01:44:59
User: dryicerx
Functions: mount
4

Like symlinked directories, you can mount a directory at a different location. For example mounting a directory from one location in to the http root without having to make your program follow symlinks or change permissions when reading.

script /dev/null | tee /dev/pts/3
2009-04-19 00:29:45
Functions: script tee
10

can display the commands and their output to another user who is connected to another terminal, by example pts/3

dpkg -S /usr/bin/ls
2009-04-18 18:18:23
User: bwoodacre
38

'dpkg -S' just matches the string you supply it, so just using 'ls' as an argument matches any file from any package that has 'ls' anywhere in the filename. So usually it's a good idea to use an absolute path. You can see in the second example that 12 thousand files that are known to dpkg match the bare string 'ls'.

dd if=yourimage.img of=/dev/sdb1
2009-04-17 23:55:13
User: rissajeanne
Functions: dd
-9

where /dev/sdb1 is the name of your usb device

cdrecord dev=0,0,0 -v -eject yourimage.iso
2009-04-17 23:44:22
User: rissajeanne
Functions: cdrecord
2

cdrecord -scanbus will tell you the (x,y,z) value of your cdr (for example, mine is 3,0,0)

echo *
2009-04-17 21:40:58
User: kFiddle
Functions: echo
Tags: echo ls
-5

Sometimes "ls" is just too slow, especially if you're having problems with terminal scroll speed, or if you're a speed freak. In these situations, do an echo * in the current directory to immediately see the directory listing. Do an echo * | tr ' ' '\n' if you want a column. Do an alias ls='echo *' if you want to achieve higher echelons of speed and wonder. Note that echo * is also useful on systems that are so low in memory that "ls" itself is failing - perhaps due to a memory leak that you're trying to debug.

hostname -i
2009-04-17 21:26:56
User: kFiddle
Functions: hostname
Tags: IP hostname
-2

I've seen some versions of hostname that don't have the -i option, so this may not work everywhere. When available, it's a better alternative than using ifconfig and wasting eyeball muscle to search for the address, and it's definitely simpler than using awk/sed.

ssh user@server | tee logfilename
2009-04-17 19:17:02
User: bassu
Functions: ssh tee
6

Optionally, you can create a new function to do this with a custom command. Edit $HOME/.bashrc and add:

myssh () { ssh $1 | tee sshlog ; }

Save it.

At command prompt:

myssh user@server
cat [ENTER]^V^O[ENTER]^D
2009-04-17 13:16:56
User: minliu2k
Functions: cat
-3

^V means CTRL-V

[ENTER] means ENTER key

lsof -c dhcpd
2009-04-17 07:18:38
User: d4n3sh
25

List all file opened by a particular command based on it's command name.

lsof -p 15857
find /usr/ -type l ! -xtype f ! -xtype d -ok rm -f {} \;
xmlstarlet ed -d '//comment()' $XML_FILE
2009-04-16 23:00:47
User: minliu2k
Functions: ed
1

In Redhat, xmlstarlet is called just xml which can be found in xmlstarlet RPM.

xmms2 mlib search NOT +rating | grep -r '^[0-9]' | sed -r 's/^([0-9]+).*/\1/' | sort -R | head | xargs -L 1 xmms2 addid
2009-04-16 20:27:30
Functions: grep head sed sort xargs
3

If you're like me and want to keep all your music rated, and you use xmms2, you might like this command.

I takes 10 random songs from your xmms2 library that don't have any rating, and adds them to your current playlist. You can then rate them in another xmms2 client that supports rating (I like kuechenstation).

I'm pretty sure there's a better way to do the grep ... | sed ... part, probably with awk, but I don't know awk, so I'd welcome any suggestions.

sort -u filename > newfilename
2009-04-16 20:00:34
User: deijmaster
Functions: sort
-7

For users looking to simplify management of large entries in files and directories, this command is the key to fun and simplicity. Using the power sort, only a couple of seconds are necessary to accomplish what would take minutes or hours in ?standard? client applications.

svn list -R https://repository.com --xml >> svnxxmlinfo.xml
2009-04-16 18:58:18
User: iheartbash
4

I use this to pull the last commit date for everything in my repo, so I can tell the client which files haven't been touched or updated since the repo was created. Another way to do it is to use svn log, but that does not pull the "kind" attribute. It does, however, give you the commit message. Both are very useful.

ffmpeg -i movie.avi -y -f vcd -vcodec mpeg1video -map 0.0:0.0 -b 1150 -s 352x240 -r 29.97 -g 12 -qmin 3 -qmax 13 -acodec mp2 -ab 224 -ar 44100 -ac 2 -map 0.1:0.1 movie.mpg
lsof -i tcp:80
2009-04-16 14:51:53
User: ar_levi
32

Sometimes you need to use a port that is already opened by some program , and you don't know who to "kill" for it to release - so, now you do !

find /path/to/my/files/ -type f -name "*txt*" | xargs du -k | awk 'BEGIN{x=0}{x=x+$1}END{print x}'
2009-04-16 14:17:04
Functions: awk du find xargs
2

Use the find command to match certain files and summarise their total size in KBytes.

locate searchstring | xargs grep foo
2009-04-16 12:51:24
User: zimon
Functions: grep locate xargs
Tags: grep locate
-3

Greps located files for an expression.

Example greps all LaTeX files for 'foo':

locate *.tex | xargs grep foo

To avoid searching thousands of files with grep it could be usefull to test first how much files are returned by locate:

locate -c *.tex