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,621 results
find . -type d -name '*[A-Z]*' -execdir bash -c '! test -f "$(echo "$0" | tr "[:upper:]" "[:lower:]")"' {} \; -execdir bash -c 'mv "$0" "$(echo "$0" | tr "[:upper:]" "[:lower:]")"' {} \;
alias install='sudo apt-get install'
2011-10-27 19:53:01
User: haivu
Functions: alias
Tags: Ubuntu alias
-6

I put this line in my ~/.bashrc file (which I source via ~/.bash_profile). Now, when I need to install a package, I typed *install* instead of the longer version.

lwp-dump http://www.boredomsoft.org/ip.php|grep Client
cowsay `fortune` | toilet --metal -f term
2010-06-03 21:48:54
-6

Get colorful fortunes dictated by an ASCII cow. For full enjoyment you'll need to have color setup enabled for your terminal.

du -h <Directory>
2010-06-04 03:14:37
User: Vasudev
Functions: du
-6

Prints the size of Directory in human readable format like KB MB or GB. If you want to see size each files and directories inside the directory use -a option as shown in second output and if you want a total sum then add -c option :)

head -n 20 <filename> | tail
while read f;do echo "$f";done < <(find .)
2010-03-02 14:22:22
Functions: echo find read
-6

Read all contents from current directory and display to stdout.

wget -O - -q ip.boa.nu
!tail
for i in `seq 1 100`;do echo;done
2010-09-07 09:55:35
User: javisol
-6

Sometimes I need to move several blank lines my terminal, I usually use this command, does anybody know a better one?

Thanks

cat /etc/debian_version
2011-12-11 11:13:16
User: eastwind
Functions: cat
-6

work on any debian based GNU/Linux distro

gcc -Wall -Werror -o prog prog.c || rm -f prog.c
find . -name "*.java" -exec gnome-terminal \-x vim {} \;
2009-02-10 09:38:04
User: root
Functions: find vim
-6

Not that useful really, more novel. Can open up an awful lot of terminal windows.

The command is too big to fit here. :( Look at the description for the command, in readable form! :)
2011-01-05 02:45:28
User: hunterm
Functions: at command
-6

Yep, now you can finally google from the command line!

Here's a readable version "for your pleasure"(c):

google() { # search the web using google from the commandline # syntax: google google query=$(echo "$*" | sed "s:%:%25:g;s:&:%26:g;s:+:%2b:g;s:;:%3b:g;s: :+:g") data=$(wget -qO - "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=$query") title=$(echo "$data" | tr '}' '\n' | sed "s/.*,\"titleNoFormatting//;s/\":\"//;s/\",.*//;s/\\u0026/'/g;s/\\\//g;s/#39\;//g;s/'amp;/\&/g" | head -1) url="$(echo "$data" | tr '}' '\n' | sed 's/.*"url":"//;s/".*//' | head -1)" echo "${title}: ${url} | http://www.google.com/search?q=${query}" }

Enjoy :)

byobu
find . -maxdepth 1 -type f -name '*.sh' -o -name '*.txt'
scp -l username -pw pa33w0rd file.txt 192.168.1.2:/path/to/dir
find / -name *.conf | tee salida
for file in *; do echo $PWD/$file; done
awk '{if (NR % 2 == 1) print $0}' file.txt
sed '/foo/ s/foo/foobar/g' <filename>
2013-01-02 08:52:44
User: totti
Functions: sed
Tags: sed file optimize
-6

Use optimized sed to big file/stream to reduce execution time

Use

sed '/foo/ s/foo/foobar/g' <filename>

insted of sed

's/foo/foobar/g' <filename>
kill -9 `ps aux | grep "search_criteria" | awk '{if ($2 != pid) print $2}'`
2010-09-16 08:52:59
User: ozgurkuru
Functions: awk grep kill
-6

search_criteria = what do you want to kill

pid = pid of you dont kill

for i in `ls *xml`; do sed -e 's,oldpassword,newpassword,g' $i > $i.2 && mv -f $i.2 $i ; done
netstat -an | grep -i listen