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,857 results
FAIL2BAN=`ps ax | grep fail2ban | grep -v grep | awk {'print $1'}` && if [ -n "$FAIL2BAN" ]; then printf "\n[INFO] Fail2Ban is running and the PID is %s\n\n" $FAIL2BAN; else printf "\n [INFO] Fail2Ban is not running\n\n"; fi
2009-02-11 04:36:49
User: fmdlc
Functions: awk grep printf
-6

Check if Fail2Ban is running on the system and alert it with a message in the terminal

pv file1 > file2
2010-02-25 19:18:32
User: ppaschka
-6

Only works on single files, doesn't preserve permissions/timestamps/ownership.

(crontab -e) 00 12 * * * apt-get update (/etc/init.d/cron restart)
alias lh='ls -a | egrep "^\."'
rd /S /Q directory
setenforce 0
2013-04-05 15:38:05
User: techie
Tags: selinux
-6

This will turn off SE Linux

ifconfig |grep broadcast | awk '{print $2}'
ls -saltS [dirname]
2011-09-18 22:03:11
User: ztank1013
Functions: ls
-6

It lists files and folder under dirname adding at the beginning of each line the file allocated size in blocks (-s). It also sorts output by file size (-S) from bigger to smaller. Actually the -t option in that precise position does not give any effect... (challenge: can you tell me why?) but of course gives to the ls command some salty taste! :)

nice -n0 ls | mpg321 -@- &
vim txt.gz
2010-09-03 01:54:05
User: Aparicio
Functions: vim
-6

Works at lest with .gz .bz2 .tar.gz .tar.bz2

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 :)