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

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

Hide

Credits

Commands by goodevilgenius from sorted by
Terminal - Commands by goodevilgenius - 12 results
find -L -type l
2014-07-22 19:52:18
Functions: find
6

-L tells find to follow symbolic links, so -type l will only return links it can't follow (i.e., those that are broken).

curl -s http://www.census.gov/popclock/data/population/world | jshon -e world -e population -u
2013-07-28 00:52:00
Tags: curl jshon
1

Fetches the world population JSON data from the US census and parses it uses jshon

sudo youtube-dl -U
2010-10-02 12:51:46
Functions: sudo
3

If you update youtube-dl from the repos, it becomes out-of-date quickly. Luckily, it can auto-update.

man $(ls /bin | shuf | head -1)
2010-08-20 23:12:51
Functions: head ls man
Tags: man
1

I'm not sure why you would want to do this, but this seems a lot simpler (easier to understand) than the version someone submitted using awk.

echo $[RANDOM%X+1]
2010-08-07 02:43:46
Functions: echo
26

If X is 5, it will about a number between 1 and 5 inclusive.

This works in bash and zsh.

If you want between 0 and 4, remove the +1.

find . -type f -exec ls -tr {} +
2010-05-27 14:52:28
Functions: find ls
-2

List all files from the current directory and subdirectories, sorted by modification time, oldest first.

curl -sI http://slashdot.org/ | sed -nr 's/X-(Bender|Fry)(.*)/\1\2/p'
2009-07-31 19:55:17
Functions: sed
0

I'm pretty sure everyone has curl and sed, but not everyone has lynx.

find -name '*oldname*' -print0 | xargs -0 rename 's/oldname/newname/'
2009-07-27 00:44:06
Functions: find rename xargs
0

This is better than doing a "for `find ...`; do ...; done", if any of the returned filenames have a space in them, it gets mangled. This should be able to handle any files.

Of course, this only works if you have rename installed on your system, so it's not a very portable command.

find -L /path/to/check -type l -delete
2009-06-06 16:07:04
Functions: find
15

If you don't want to delete them, but just want to list them, do

find -L /path -type l

If you want to delete them with confirmation first, do

find -L /path -type l -exec rm -i {} +

Using the -L flag follows symlinks, so the -type l test only returns true if the link can't be followed, or is a symlink to another broken symlink.

tar -tf file.tar | tar -T - -uf file.tar
2009-05-22 00:28:13
Functions: tar
2

This will update the tarball, adding files that have changed since the last update.

This assumes that the tarball is in the same directory as the files being archived.

N.B. This command can't be used on compressed tarballs.

N.B. This will add the updated files to the tarball, so that the tarball will have two versions of each file. This will make the tarball larger, but doesn't have any other significant effect.

pi 66 | number
2009-05-03 22:10:58
0
pi 66

This prints out the first 66 digits of pi.

number

This takes any number (no more than 66 digits long) from stdin (or on the command line), and tells you how to say it. E.g

number 365

outputs "three hundred sixty-five"

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.