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



All commands from sorted by
Terminal - All commands - 12,419 results
alias dush="du -xsm * | sort -n | awk '{ printf(\"%4s MB ./\",\$1) ; for (i=1;i<=NF;i++) { if (i>1) printf(\"%s \",\$i) } ; printf(\"\n\") }' | tail"
2010-07-15 10:38:27
User: dopeman
Functions: alias

Essentially the same as funky's alias, but will not traverse filesystems and has nicer formatting.

sed -e "s,/\+$,," -e "s,^/\+,," file.txt
2012-11-02 21:08:30
User: bugmenot
Functions: sed

There can be more than one trailing slash, all of them will be removed.

@echo off && sc create CmdAsSystem type= own type= interact binPath= "cmd /c start cmd /k (cd c:\ ^& color ec ^& title ***** SYSTEM *****)" && net start CmdAsSystem && sc delete CmdAsSystem
2010-02-07 15:28:28
User: willemijns

In 2014, ask a kind of specific UAC authorization to run due to his dangerousity.

ifconfig eth0|awk '/HWaddr/{gsub(/:/,"",$5);print $5}'
DD=`cat /etc/my.cnf | sed "s/#.*//g;" | grep datadir | tr '=' ' ' | gawk '{print $2;}'` && ( cd $DD ; find . -mindepth 2 | grep -v db\.opt | sed 's/\.\///g; s/\....$//g; s/\//./;' | sort | uniq | tr '/' '.' | gawk '{print "CHECK TABLE","`"$1"`",";";}' )
2009-07-25 03:42:31
User: atcroft
Functions: cd find gawk grep sed sort tr uniq

This command will generate "CHECK TABLE `db_name.table_name` ;" statements for all tables present in databases on a MySQL server, which can be piped into the mysql command. (Can also be altered to perform OPTIMIZE and REPAIR functions.)

Tested on MySQL 4.x and 5.x systems in a Linux environment under bash.

/usr/bin/Xephyr :5 -query localhost -once -fullscreen -ac -keybd "ephyr,,,xkbmodel=pc105,xkblayout=it,xkbrules=evdev,xkboption="
2012-11-03 01:21:36
User: hute37
Tags: Xephyr xdmcp

XDMCP ust be enabled (gdm,lightdm,xdm etc )

sudo aptitude -y install iasl && sudo cat /sys/firmware/acpi/tables/DSDT > dsdt.dat && iasl -d dsdt.dat
2009-02-15 23:13:50
User: brettalton
Functions: cat install sudo

In July 2008, there was an uproar over Foxconn motherboards feeding Linux installs incorrect ACPI information (http://ubuntu-virginia.ubuntuforums.org/showthread.php?t=869249).

Foxconn has gladly corrected their mistake, but make sure it's not happening on your motherboard!

After running the command, just view the 'dsdt.dsl' in any editor you like.

for dnsREC in $(curl -s http://www.iana.org/assignments/dns-parameters |grep -Eo ^[A-Z\.]+\ |sed 's/TYPE//'); do echo -n "$dnsREC " && dig +short $dnsREC IANA.ORG; done
for i in `cat /etc/passwd | awk -F : '{ print $1 }';`; do passwd -e $i; done
sed -e 's/{"url":/\n&/g' ~/.mozilla/firefox/*/sessionstore.js | cut -d\" -f4
change-homepage(){ sed -ri 's|( "homepage": ").*(",)|\1'"$@"'\2|' .config/chromium/Default/Preferences; }
ssh-add ~/.ssh/KEY_PAIR_NAME.pem
2012-11-03 02:59:52
User: brockangelo
Functions: ssh ssh-add
Tags: ssh EC2

This command adds your pem key to SSH so that you no longer have to manually specify it when connecting to EC2 instances.

# you can do this:

ssh ec2-instance.amazonaws.com

# instead of this:

ssh -i ~/.ssh/KEY_PAIR_NAME.pem ec2-instance.amazonaws.com

for menu in {1..4}; do echo -e "<ul>\n <li>menu $menu</li>\n <ul>"; for items in {1..5}; do echo " <li>item $items</li>"; if [ $items -eq 5 ];then echo -e " </ul>";fi;done; echo "</ul>";done | xclip
2013-09-22 06:34:32
User: qcjn
Functions: echo

This will create rapidly an html menu. You can paste it in you're html page with the middle button(the wheel). I didn't test it in an html with css, but it seems alright.

du --max-depth=1 | grep -v '\.\/\.'
grep -l bar *.log | xargs grep -l foo
2011-01-10 19:54:46
User: dlebauer
Functions: grep xargs
Tags: bash xargs grep

Uses xargs to call the second grep with the first grep's results as arguments

fromdos <file>
2011-02-14 17:28:53
User: jbuitt

requires the package tofrodos on Debian/Ubuntu:

sudo apt-get install tofrodos

for i in {1..40};do echo -n $i. $(date +%H:%M:%S):\ ; (time curl 'http://ya.ru/' &> /dev/null) 2>&1|grep real;sleep 1;done
2011-11-11 10:40:38
User: AntonyC
Functions: date echo grep sleep time
Tags: curl

This uses curl to find out the access times of a web service

perl -pi -e 's/foo/bar/g' $(grep -l foo ./*)
2009-03-27 17:18:08
User: dopeman
Functions: grep perl

This command will replace all instances of 'foo' with 'bar' in all files in the current working directory.

2009-08-14 14:02:37



You'll first need to install the uuid package. Available immediately from apt in Ubuntu, Debian, or other myriad Debian variants. You could always compile it from source as well.

du -sh * | grep -v '\.\/\.'
while $i;do `notify-send -t 200 "You are awesome :)"`;sleep 60; done;
2011-02-14 18:49:38
User: pahnin
Functions: sleep

sends notification msg within repeated intervals of time to notify-send ;)

Just for fun.

sudo sync && sudo echo 3 | sudo tee /proc/sys/vm/drop_caches
2012-03-17 08:27:58
User: StephenJudge
Functions: echo sudo sync tee
Tags: memory cache

"That's it. Not much to see here. The first command writes any cache data that hasn't been written to the disk out to the disk. The second command tells the kernel to drop what's cached. Not much to it. This invalidates the write cache as well as the read cache, which is why we have the sync command first. Supposedly, it is possible to have some cached write data never make it to disk, so use it with caution, and NEVER do it on a production server. You could ... but why take the risk?

As long as you are running a post 2.6.16 kernel,..."

Source: http://ubuntuforums.org/showpost.php?p=3621283&postcount=1

df | awk '{if ($2!=dspace) print "different"; dspace=$2;}'
find . | sort | awk 'NR%2==0' | xargs rm $1
2013-07-11 07:36:18
User: sucotronic
Functions: awk find rm sort xargs

If you have a directory with lot of backups (full backups I mean), when it gets to some size, you could want to empty some space. With this command you'll remove half of the files. The command assumes that your backup files starts with YYYYMMDD or that they go some alphabetical order.

find . -iname "*.mp3" | mpg123 -Z --list -