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.

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

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 11,860 results
function fur () { curl -sL 'http://www.commandlinefu.com/commands/random/plaintext' | grep -v "^# commandlinefu" }
IFS=?" ; for i in * ; do mv -v $i `echo $i|tr ???????????????????\ aaaeeiooAAAEEIOOOcC_` ; done
ls -lFart |tail -n1
2011-10-17 19:49:14
User: jambino
Functions: ls tail
Tags: tail pipe ls
-2

List all files in a directory in reverse order by modified timestamp. When piped through tail the user will see the most recent file name.

cat /dev/zero > /dev/null &
2009-03-02 18:18:52
User: gustavold
Functions: cat
-2

Just waste some resources in a philosophical way

history | sed -e 's/^sudo //' | awk '{print $2}' | sort | uniq -c | sort -rn | head
2012-01-07 22:29:54
User: bibe
Functions: awk sed sort uniq
-2

I make an extensive use of sudo, so I had to exclude the sudo part of the command history

lynx -source http://www.commandlinefu.com/commands/random | sed 's/<[^>]*>//g' | head -1037 | tail -10 | sed -e 's/^[ \t]*//' | sed '/^$/d' | head -2
watch -tn1 'date -u +%T -d @$(expr $(date -d HH:MM +%s) - $(date +%s)) | toilet -f bigmono12'
2010-06-26 11:56:11
User: prayer
Functions: date expr watch
Tags: date time
-2

Change HH:MM with your target time.

This is for a Debian/Ubuntu GNU system. You need bash (package bash), date (package coreutils) and toilet (package toilet). Install with:

# apt-get install bash coreutils toilet toilet-fonts

find . -depth \( -path '*/*.java.orig' -o -path '*/*.java.orig/*' \) -delete
find . -name "*.pyc" -exec rm {} \;
2009-02-16 17:15:58
User: nsmgr8
Functions: find rm
-2

For a python project, sometimes I need to clean all the compiled python files. I have an alias 'rmpyc' to this command. This really saves me a lot of typing and hunting throughout the folders to delete those files.

grep -r 'keyword keyword2' your/path/ | grep -v svn
2009-07-08 20:48:11
User: anis
Functions: grep
-2

this command searches for a keyword or an expression in a path and avoids versionned files

mount | grep : | tr -s ' ' -d 3 | xargs umount -v
ls -F | sed -n 's/@$//p'
echo sleep() begins: %TIME% && FOR /l %a IN (10,-1,1) do (ECHO 1 >NUL %as&ping -n 2 -w 1 127.0.0.1>NUL) && echo sleep() end: %TIME%
2009-08-19 13:43:09
User: pfredrik
Functions: echo
-2

Enable 'sleep' function in Windows environment where this does not exist, although not exact in time. (there is a delay for each ping) This is a simple way to separate commands with a time-period.

find . -type d -name "*TestDir*" | wc -l
2011-01-24 22:38:27
User: linuxgeek
Functions: find wc
-2

A simple command to find the total number of subdirectories in current directory starting with specific name.

echo "1 2 3+p" | dc
find . -type f|perl -lne '@x=sort {$b->[0]<=>$a->[0]}[(stat($_))[7],$_],@x;splice(@x,11);print "@{$x[0]}";END{for(@x){print "@$_"}'
2012-01-08 14:43:43
User: bazzargh
Functions: find perl
Tags: sort perl find
-2

A different approach to the problem - maintain a small sorted list, print the largest as we go, then the top 10 at the end. I often find that the find and sort take a long time, and the large file might appear near the start of the find. By printing as we go, I get better feedback. The sort used in this will be much slower on perls older than 5.8.

nl filename | more
2009-05-04 07:35:16
User: haivu
Functions: nl
-2

The nl command lists the contents of a file where is each line is prefixed by a line number. For more information about this command, check out its man page. I tested under Mac OS X and Xubuntu 9.04

setxkbmap us
2010-01-23 04:08:46
User: keturn
-2

Restores the keyboard so your partner who expects the keys to correspond to what they're labelled can type (in qwerty).

printf "%.50d" 0 | tr 0 -
ls -l | sed -e 's/--x/1/g' -e 's/-w-/2/g' -e 's/-wx/3/g' -e 's/r--/4/g' -e 's/r-x/5/g' -e 's/rw-/6/g' -e 's/rwx/7/g' -e 's/---/0/g'
kill -HUP ` ps -aef | grep -i firefox | sort -k 2 -r | sed 1d | awk ' { print $2 } ' `
sudo iptables-restore < /etc/iptables.test.rules
2009-08-19 14:38:08
User: kamiller
Functions: iptables-restore sudo
Tags: iptables
-2

If you don't save the rule set it won't be applied during a reboot

echo "test" | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'
2011-04-05 09:52:37
User: lightuono
Functions: echo sed
-2

Convert text from lowercase to uppercase

for f in *; do clear; cat $f; sleep .3; done
2011-11-25 17:10:47
User: toddkaufmann
Functions: cat sleep
-2

The better alternative to #9756.

I don't think I'd ever use the original command, but this one was so bad I had to post this. Sorry.

1. $(ls) is dumb, and will give errors if you have an alias like "ls -Fs"

2. clear is better and more portable than reset state.

3. if you're interested in differences, then use diff, not cat.

sudo mount -t cifs -o credentials=/path/to/credenials //hostname/sharename /mount/point
2009-11-23 23:55:20
User: magma_camel
Functions: mount sudo
-2

mounts a samba share on a remote machine using a credentials file that can be in a file tht is not accessable by other users the file will look like:

username="username"

password="password"

best option i belive