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.

Universal configuration monitoring and system of record for IT.

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



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Commands tagged bash from sorted by
Terminal - Commands tagged bash - 733 results
wget `lynx -dump http://www.ebow.com/ebowtube.php | grep .flv$ | sed 's/[[:blank:]]\+[[:digit:]]\+\. //g'`
2009-08-02 14:09:53
User: spaceyjase
Functions: grep sed wget

I wanted all the 'hidden' .flv files from the http link in the command line; wget seemed appropriate, fed with output from lynx, grep the flv files and the normalised via sed (to remove the numeric bullet). Similar to the 'Grab mp3 files' fu. Replace link with your own, grep arg with something more interesting ;) See here for something along the same lines...


Hope you find it useful! Improvements welcome, naturally.

no_of_files=10; counter=1; while [[ $counter -le $no_of_files ]]; do echo Creating file no $counter; dd bs=1024 count=$RANDOM skip=$RANDOM if=/dev/sda of=random-file.$counter; let "counter += 1"; done
2009-07-31 16:34:47
User: rajaseelan
Functions: dd echo file
Tags: bash dd

Create a bunch of random files with random binary content. Basically dd dumps randomly from your hard disk to files random-file*.

[[ "$WINDOW" ]] && PS1="\u@\h:\w[$WINDOW]\$ "
2009-07-23 06:46:19
User: recursiverse
Tags: bash screen shell

Add this to your $HOME/.bashrc file. It will only set this prompt if it is running inside screen ($WINDOW var is set)

Looks like this...

[email protected]:~[2]$
lynx -dump http://www.ip-adress.com/ip_tracer/?QRY=$1|sed -nr s/'^.*My IP address city: (.+)$/\1/p'
ls -drt /var/log/* | tail -n5 | xargs sudo tail -n0 -f
2009-07-22 14:44:41
User: kanaka
Functions: ls sudo tail xargs
Tags: bash tail log watch

This command finds the 5 (-n5) most frequently updated logs in /var/log, and then does a multifile tail follow of those log files.

Alternately, you can do this to follow a specific list of log files:

sudo tail -n0 -f /var/log/{messages,secure,cron,cups/error_log}

tar -pczf archive_name.tar.gz /path/to/dir/or/file
2009-07-17 19:53:02
User: ryuslash
Functions: tar
Tags: bash tar gzip

Create a single tar.gz archive

I know it's a very basic one, but it's one I keep forgetting.

sudo rmmod pcspkr
2009-07-17 18:21:19
User: zombiedeity
Functions: rmmod sudo

To ensure that it will never come back, you can edit /etc/modprobe.d/blacklist

Add "blacklist pcspkr" sans quotes

infile=$1 for i in $(cat $infile) do echo $i | tr "," "\n" | sort -n | tr "\n" "," | sed "s/,$//" echo done
2009-07-12 21:23:37
User: iframe
Functions: cat echo sed sort tr
Tags: cat bash sort sed tr

Save the script as: sort_file

Usage: sort_file < sort_me.csv > out_file.csv

This script was originally posted by Admiral Beotch in LinuxQuestions.org on the Linux-Software forum.

I modified this script to make it more portable.

iconv -f437 -tutf8 asciiart.nfo
2009-07-11 23:50:05
User: speaker
Functions: iconv

Files containing ascii art (e.g. with .nfo extension) are typically not correctly reproduced at the command line when using cat. With iconv one can easily write a wrapper to solve this:


if [ -z "$@" ]; then echo "Usage: $(basename $0) file [file] ..."

else iconv -f437 -tutf8 "$@"; fi

exit 0
for y in $(seq 2009 2011); do cal $y; done
2009-07-10 10:07:46
Functions: cal seq
Tags: bash seq cal

print multiple increasing years using cal - calendar -. You can also try

seq Start Increment End
/originalInstall/gem list | tr -d '(),' | xargs -L 1 sudo ./gemInst.sh
2009-07-09 21:46:06
User: snakerdlk
Functions: sudo tr xargs
Tags: bash Linux



for i in $@; do

if [ "$1" != "$i" ]


echo /newInstall/gem install $1 -v=\"$i\"

/newInstall/gem install $1 -v="$i"

if [ "$?" != "0" ]


echo -e "\n\nGEM INSTALL ERROR: $1\n\n"

echo "$1" > gemInst.err




export IFS=$(echo -e "\n")
2009-07-09 15:25:37
User: darkpand
Functions: echo export

When you use a "for" construct, it cycles on every word. If you want to cycle on a line-by-line basis (and, well, you can't use xargs -n1 :D), you can set the IFS variable to .

l=500; x=500; y=200; d=-15;for i in `seq $x $d $y`; do beep -l $l -f $i;done
2009-07-07 22:12:20
Tags: bash beep sound

Generates a frequency sweep from $x to $y, with $d numbers inbetween each step, and with each tone lasting $l milliseconds.

? () { echo "$*" | bc -l; }
2009-06-28 20:15:30
User: fizz
Functions: bc echo

defines a handy function for quick calculations from cli.

once defined:

? 10*2+3
for i in *;do mv "$i" "$(echo $i | sed s/PROBLEM/FIX/g)";done
2009-06-28 01:50:25
User: AlecSchueler
Functions: mv

Useful if non-ascii characters in filenames have been improperly encoded. Replace "PROBLEM" with the incorrect characters (e.g. 'é'), and "FIX" with the correct ones (e.g. '?').

echo {0..1}{0..1}{0..1}{0..1}
2009-06-23 17:30:20
User: dennisw
Functions: echo

If you should happen to find yourself needing some binary numbers, this is a quickie way of doing it. If you need more digits, just add more "{0..1}" sequences for each digit you need. You can assign them to an array, too, and access them by their decimal equivalent for a quickie binary to decimal conversion (for larger values it's probably better to use another method). Note: this works in bash, ksh and zsh. For zsh, though, you'll need to issue a setopt KSH_ARRAYS to make the array zero-based.


echo ${binary[9]}
(Command too long..See sample Output..)
2009-06-14 20:34:37
User: mohan43u
Tags: bash sed echo tr od

curl doesn't provide url-encoding for 'GET' data, it have an option '--data-urlencode', but its only for 'POST' data. Thats why I need to write down this commandline. With 'perl', 'php' and 'python', this is one liner, but just I wrote it for fun. Works in Ubuntu, will work in all linux varients(I hope it will work in unix varients also).

a=`printf "%*s" 16`;b=${a//?/{0..1\}}; echo `eval "echo $b"`
chronic () { t=$1; shift; while true; do $@; sleep $t; done & }
2009-06-13 05:57:54
User: rhythmx
Functions: sleep

Chronic Bash function:

chronic 3600 time # Print the time in your shell every hour chronic 60 updatedb > /dev/null # update slocate every minute

Note: use 'jobs' to list background tasks and fg/bg to take control of them.

URL=http://svn.example.org/project; diff -u <(TZ=UTC svn -q log -r1:HEAD $URL | grep \|) <(TZ=UTC svn log -q $URL | grep \| | sort -k3 -t \|)
2009-06-03 14:26:55
User: sunny256
Functions: diff grep sort
Tags: bash svn

Lists revisions in a Subversion repository with a timestamp that doesn't follow the revision numbering order. If everything is OK, nothing is displayed.

for k in `git branch|perl -pe s/^..//`;do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k|head -n 1`\\t$k;done|sort -r
2009-06-03 08:25:00
User: brunost
Functions: echo head perl sort

Print out list of all branches with last commit date to the branch, including relative time since commit and color coding.

svn log fileName|cut -d" " -f 1|grep -e "^r[0-9]\{1,\}$"|awk {'sub(/^r/,"",$1);print "svn cat fileName@"$1" > /tmp/fileName.r"$1'}|sh
2009-05-27 02:11:58
User: fizz
Functions: awk cut grep
Tags: bash svn awk grep

exported files will get a .r23 extension (where 23 is the revision number)

sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e
2009-05-25 05:37:44
User: mohan43u
Functions: echo sed xargs
echo "http%3A%2F%2Fwww.google.com" | sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e


Works under bash on linux. just alter the '-e' option to its corresponding equivalence in your system to execute escape characters correctly.

diff -uw <(fmt -1 {file1, file2})
2009-05-23 03:11:08
User: sunny256
Functions: diff fmt
Tags: bash diff

It can be hard to spot differences in reformatted files, because of all the diff noise created by word wrapped lines. This command removes all the noise and performs a word-by-word diff. To ignore empty lines, add -B to the diff command. Also, if this is something you do often, you might want to check out the wdiff(1) program.