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

All commands from sorted by
Terminal - All commands - 12,403 results
find /path/ -type f -exec grep -l '<string of text>' {} \; | xargs sed -i -e 's%<string of text>%<new text string>%g'
gominify() { if [ $# -ne 2 ]; then echo 'gominify < src > < dst >'; return; fi; s="$1"; d="$2"; java -jar yui.jar $s >$d; if [ $? == 0 ]; then a=$( ls -sh $s | awk '{print $1}' ); b=$( ls -sh $d | awk '{print $1}' ); echo "Saved $s ($a) to $d ($b)"; fi;}
2010-08-03 10:19:24
User: meathive
Functions: awk echo ls

This command, or a derivative like it, is a must-have if you're a server administrator interested in website optimization: https://kinqpinz.info/?%C2%B6=287a7ba6

Command requires Yahoo's YUI, find it here: http://developer.yahoo.com/yui/

find . -mtime +30 -exec mv {} old/ \;
2014-02-09 23:05:41
User: minnmass
Functions: find mv
Tags: bash file

Use find's built-in "exec" option to avoid having to do any weirdness with quoting.

find -name pom.xml | while read f; do cd $(dirname "$f"); mvn clean; cd -; done;
2015-04-15 21:24:49
User: glaudiston
Functions: cd dirname find read

this command is used to locate all pom.xml files, access the dir and do a mvn clean, but I do recommend you to disable network interfaces to not download dependencies packages to be faster.

while [ 1 ]; do date; ls -l /path/to/dir; sleep 1; done
tar -tf <file.tar.gz> | parallel rm
2010-01-28 08:28:16
Functions: tar

xargs deals badly with special characters (such as space, ' and "). To see the problem try this:

touch important_file

touch 'not important_file'

ls not* | xargs rm

Parallel https://savannah.nongnu.org/projects/parallel/ does not have this problem.

rename -n "s/-.*//" *
2011-03-06 12:08:39
User: pepin
Functions: rename

of course, replace the "-" after / by the character you wish. a dot must by protected by a backslash, as it is a regexp. it's the same result as the command proposed. but if there is more than a dash in the name, only the part before the first dash is kept... so that's not an "extension renaming" command.

echo 1 2 3 > FILE; while read -a line; do echo ${line[2]}; done < FILE
2009-03-06 15:32:40
User: occam
Functions: echo read
Tags: bash

This will print out the third column of every line in FILE. Useful for many files in /proc or *csv data.

ip link
tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 10 | sed 1q
kill `ps aux | grep xmms | grep -v grep | awk '{ print $2 }'`
2010-11-11 17:26:26
User: corp769
Functions: awk grep kill

I use this command, within a cron job, to kill XMMS after a certain amount of time. This command returns the PID used by XMMS, and gets passed to the kill command. Another alternative would be ps aux | grep xmms | grep -v grep | awk '{ print $2 }' | xargs kill

2009-03-24 16:19:12
User: haivu
Functions: bc

bc is a wonderful calculator. Just type bc at the command line and have at it. Ctrl+D (or type quit) will get you out. This usage is just scratching the surface: bc can handle a mini scripting language, complete with variable, statements, loop, conditional statements and more. Do a man page on it to find out.

svn status |grep '\?' |awk '{print $2}'| parallel -Xj1 svn add
2010-01-28 08:47:54
Functions: awk grep
Tags: xargs parallel

xargs deals badly with special characters (such as space, ' and "). To see the problem try this:

touch important_file

touch 'not important_file'

ls not* | xargs rm

Parallel https://savannah.nongnu.org/projects/parallel/ does not have this problem.

leapyear() { if [ $[$1 % 4] -eq 0 ] && [ $[$1 % 100] -ne 0 ] || [ $[$1 % 400] -eq 0 ]; then echo $1' is a leap year!'; else echo $1' is not a leap year.'; fi; }
2010-03-30 17:19:20
User: kaedenn
Functions: echo
Tags: echo test

Tested on bash, and follows all the rules about leap years.

ls -t1 | head -n1
head -1000 < lines.txt | tail -1
killall xmms
/opt/psa/bin/pleskbackup server -v --output-file=plesk_server.bak
wget -O - -q http://checkip.dyndns.org/ | cut -d':' -f2 | cut -d'<' -f1| cut -c2-
2011-09-17 13:42:01
User: ztank1013
Functions: cut wget

This is just a "cut" addicted variant of the previous unixmonkey24730 command...

svn st | grep /main/java | awk '{print $2}' | xargs echo | xargs svn ci -m "my comment here"
BACKUP_FILE_SIZE=`eval ls -l ${BACKUP_FILE} | awk {'print $5'}`; if [ $BACKUP_FILE_SIZE -le 20 ]; then echo "its empty"; else echo "its not empty"; fi
2009-12-29 08:34:37
User: Redrocket
Functions: awk echo ls

If you gzip an empty file it becomes 20 bytes. Some backup checks i do check to see if the file is greater than zero size (-s flag) but this is no good here. Im sure someone has a better check than me for this? No check to see if file exists before checking it's size.

java -jar compiler.jar --js file.js
svn st | cut -c 9- | parallel -X tar -czvf ../backup.tgz
2010-01-28 11:43:16
Functions: cut tar

xargs deals badly with special characters (such as space, ' and "). In this case if you have a file called '12" record'.

Parallel https://savannah.nongnu.org/projects/parallel/ does not have this problem.

Both solutions work bad if the number of files is more than the allowed line length of the shell.

2011-04-14 06:59:06
User: atgf0127
Functions: top

usage: top -hv | -bcisSHM -d delay -n iterations [-u user | -U user] -p pid [,pid ...]

ldapsearch -H ldap://localhost:389 -D cn=username,ou=users,dc=domain -x -W -b ou=groups,dc=domain '(member=cn=username,ou=users,dc=domain)' | grep ^dn | sed "s/dn\: cn=\([^,]*\),ou=\([^,]*\),.*/\2 \1/"
2009-06-11 14:50:11
User: nitehawk
Functions: grep sed

This expression looks for groups inside of a GroupOfNames class element, that is itself inside one (or many) Organizational Unit (ou) nodes in the ldap tree. Give you a quick dump of all the groups the user belongs to. Handy for displaying on a webpage.