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.

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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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:



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!

Top Tags



Commands by jnash from sorted by
Terminal - Commands by jnash - 12 results
curl -s --data-urlencode 'longUrl='$1 --data-urlencode 'login='$login --data-urlencode 'apiKey='$apikey 'http://api.bit.ly/shorten?version=2.0.1&format=xml' | xmlstarlet sel -T -t -m "//shortUrl" -v "." | line
2010-01-02 11:32:42
User: jnash

It uses curl --url-encode to encode long URLs *properly* and parses XML with xmlstarlet.

If ~/.bitlyrc were to contain


then a script could read the apiKey and login from ~/.bitlyrc like so:

login=$(sed 's/:.*//' < $HOME/.bitlyrc)

apikey=$(sed 's/[^:]*://' < $HOME/.bitlyrc)

curl -s --data-urlencode 'longUrl='$1 --data-urlencode 'login='$login --data-urlencode 'apiKey='$apikey 'http://api.bit.ly/shorten?version=2.0.1&format=xml' | xmlstarlet sel -T -t -m "//shortUrl" -v "." | line

git remote add origin [email protected]:<USER>/<REPOSITORY>.git
2009-11-19 06:57:50
User: jnash

If you are behind a restrictive proxy/firewall that blocks port 22 connections but allows SSL on 443 (like most do) then you can still push changes to your github repository.

Your .ssh/config file should contain:

Host *

ForwardX11 no

TCPKeepAlive yes

ProtocolKeepAlives 30

ProxyCommand /usr/local/bin/proxytunnel -v -p -d %h:443


User git

Hostname ssh.github.com

ChallengeResponseAuthentication yes

IdentityFile ~/.ssh/id_rsa

IdentitiesOnly yes

Basically proxytunnel "tunnels" your ssh connection through port 443.

You could also use corkscrew or some other tunneling program that is available in your distro's repository.

PS: I generally use "github.com" as the SSH-HOST so that urls of the kind [email protected]:USER/REPO.git work transparently :) You

for item in *;do echo -n "$item - ";find "$item" -type f -print0 | xargs -0 file -iNf - | grep video | cut -d: -f1 | xargs -d'\n' /usr/share/doc/mplayer/examples/midentify | grep ID_LENGTH | awk -F= '{sum+=$2} END {print(sum/60)}'; done | grep -v ' - 0$'
2009-11-19 06:28:15
User: jnash
Functions: awk cut echo file grep xargs

I know this has been beaten to death but finding video files using mime types and printing the "hours of video" for each directory is (IMHO) easier to parse than just a single total. Output is in minutes.

Among the other niceties is that it omits printing of non-video files/folders

PS: Barely managed to fit it within the 255 character limit :D

find ./ -type f -print0 | xargs -0 file -iNf - | grep video | cut -d: -f1
2009-11-19 06:05:36
User: jnash
Functions: cut file find grep xargs

Uses mime-type of files rather than relying on file extensions to find files of a certain type.

This can obviously be extended to finding files of any other type as well.. like plain text files, audio, etc..

In reference to displaying the total hours of video (which was earlier posted in command line fu, but relied on the user having to supply all possible video file formats) we can now do better:

find ./ -type f -print0 | xargs -0 file -iNf - | grep video | cut -d: -f1 | xargs -d'\n' /usr/share/doc/mplayer/examples/midentify | grep ID_LENGTH | awk -F "=" '{sum += $2} END {print sum/60/60; print "hours"}'
shuf -n1 /usr/share/dict/words | tee >(sed -e 's/./&\n/g' | shuf | tr -d '\n' | line) > /tmp/out
< /dev/urandom tr -dc A-Za-z0-9_ | head -c $((1024 * 1024)) | tee >(gzip -c > out.gz) >(bzip2 -c > out.bz) > /dev/null
man beep | sed -e '1,/Note/d; /BUGS/,$d' | awk '{print $2}' | xargs -IX sudo beep -f X -l 500
2009-04-01 06:48:48
User: jnash
Functions: awk man sed sudo xargs

Are there any creative pieces of music that can be created using beep and the shell? I'd love to hear it!

date -d @$(echo $((2 ** 31 - 1)))
2009-03-30 19:42:20
User: jnash
Functions: date echo


Some other notable dates that have passed:

date [email protected] date [email protected]
find /home/user/doc/ -type d -printf "mkdir -vp '/home/user/Dropbox%p'\n" -o -type f -printf "ln -vs '%p' '/home/user/Dropbox%p'\n" | sh
2009-03-29 09:25:12
User: jnash
Functions: find

Extremely useful to maintain backups if you're using Dropbox. This mirrors the entire directory structure and places symlinks in each to the original file. Instead of copying over the data again to the ~/Dropbox folder creating a symbolic link tree is much more sensible in terms of space usage.

This has to be supplemented by another script that removes dead symlinks in the Dropbox folder which point to files that have been moved/removed.

find -L ./ -type l -delete

And then removing empty directories

find ./ -type d -exec rmdir 2>/dev/null {} \;

**Actually after some finding I found lndir which creates symbolic trees but it wasn't in the Arch repos so.. ;)

watch --no-title -d -n 1 'echo `date -d "next Thursday" +%s` "-" `date +%s` | bc -l'
2009-03-29 06:53:09
User: jnash
Functions: bc watch

Might be more useful if you were able to print it in Days HH:MM:SS format as:

perl -e [email protected]=gmtime(234234);printf("%d Days %02d:%02d:%02ds\n",@p[7,2,1,0]);'

But I'm not exactly sure how to replace the 234234 with the output of the countdown time. (Having some problems with nested quoting/command substitution). Help would be appreciated :)

2009-03-27 18:56:36
User: jnash

Python comments begin with a #. Modify to suit other languages.

Other uses: Instead of m0 use m$ for end of file or d for deleting all comments.

find ./ -iname "*.mp3" -type f -printf "mv '%p' '%p'\n" | sed -e "s/mp3'$/mp3'/I" | sh
2009-03-27 13:42:40
User: jnash
Functions: find sed

Extensible to other ugly extensions like *.JPG, *.Jpg etc..

Leave out the last pipe to sh to perform a dry run.