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,491 results
ls | xargs du -sh
find . -type d | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\([^ ]\)/|-\1/"
2013-07-16 10:08:34
User: opexxx
Functions: find sed
Tags: sed find
-4

show directory three

help builtin
rm -rf `find -maxdepth 1 -mindepth 1 -mtime +7`
2009-05-22 11:46:57
User: tatwright
Functions: rm
-4

This is useful for command line 'recycle bins' and such like

seq -w 100 | sed 's/^/login/'
2009-10-15 13:56:56
User: lawrence
Functions: sed seq
-4

This command generates a sequential login list. Good to be used as a source of new logins.

dpkg-reconfigure -phigh xserver-xorg
cat .ssh/id_rsa.pub | ssh user@server 'cat >> ~/.ssh/authorized_keys2'
2012-07-12 15:42:10
User: er0k
Functions: cat ssh
-4

for passwordless login

# indicates a comment in shell
2009-03-16 23:15:33
User: mpb
-4
#

Using the "#" in shell is surprisingly useful.

Some of the uses I found:

a) As a visible copy buffer in shell history (caveat: do not use for passwords :-)

b) To build complex commands until ready then hit the HOME, DEL, ENTER keys to run it

c) Placing reference data into shell history (search for tags with CTRL-R TAGNAME)

d) Putting aside a "work in progress" command to focus on another task (HOME # ENTER)

sudo apt-get remove --purge `dpkg -l | awk '{print $2}' | grep gnome` && apt-get autoremove
2009-04-28 10:34:42
User: kelevra
Functions: awk grep sudo
Tags: awk apt-get dpkg
-4

Useful for removes a package and its depends, for example to remove the gnome desktop environment, also configuration files will be removed, you should be carefully and sure that you want to do this.

watch "df | grep /this/folder/"
echo "" > .bash_history
which <command> > /dev/null 2>&1 && echo Success!
2013-03-13 10:04:42
User: skkzsh
Functions: echo which
Tags: which
-4

or

which <command> > /dev/null 2>&1 || echo Error!

For example, I write

which colordiff > /dev/null 2>&1 && alias diff=colordiff

in my `~/.bashrc`.

perl -p -i -e ?s/New/Old/g? *.html
2009-11-16 13:40:13
User: chappado
Functions: perl
-4

-p -> loop (same as -n in sed)

-i -> edit files

-e -> execute command

replace Old with New in all *.html files

dd if=/dev/zero of=/tmp/bigfile bs=1024k count=100
curl -s http://www.google.com/ig/api?weather=$(curl -s "http://api.hostip.info/get_html.php?ip=$(curl -s icanhazip.com)" | grep City | sed 's/City: \(.*\)/\1/' | sed 's/ /%20/g' | sed "s/'/%27/g") | sed 's|.*<temp_f data="\([^"]*\)"/>.*|\1\n|'
ping -qc 10 server.tld | awk -F/ '/^rtt/ {print $5}'
2011-10-12 21:07:06
User: atoponce
Functions: awk ping
Tags: awk ping
-4

Quick and dirty one-liner to get the average ping(1) time from a server.

man !!
2010-09-24 13:38:17
User: pahnin
Functions: man
-4

when we work with terminal often we open man pages for help if we did some mistakes

and when we want to open the man page for command we are working with this one helps

as many people may be knowing that '!!' performs the last command action

we use it in sudo !! to perform the last action with root previleages

man !! will also be helpful and handy

thanx

ip a s eth0 | grep "inet " | head -n 1 | awk '{print $2}' | cut -f1 -d'/'
2012-07-16 07:54:43
User: thelan
Functions: awk cut grep head
Tags: IP
-4

Get the first IPv4 address of an interface

(while read fn; do; cp "$fn" $DESTINATION\.; done<filename.txt)
2013-05-05 16:29:51
User: jameskirk
Functions: cp read
Tags: shell
-4

If you want to copy all files listed (with full path) in a text-file (i.e. cmus playlist.pl) to a certain directory use this nice oneliner...

Credits goes to RiffRaff: http://www.programmingforums.org/post242527-2.html

function duf { du -sk "$@" | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done; }
case $# in 0) echo usage: $0 pattern ;; *)case $1 in */*)sed ' s,'"$1"',\ ,g';; *) sed ' s/'"$1"'/\ /g' ;;esac;esac;
2011-12-30 23:54:12
User: argv
Functions: echo sed
-4

alternative to tr char '\012'

works with sed's that don't accept "\n"

allows for multi-char sentinals, while tr(1) only operates on single chars

wc -l *c
uname -m
2011-01-15 21:07:13
User: retrodanny
Functions: uname
Tags: 32 processor
-4

i686 = 32 bits

x86_64 = 64 bits

the command "getconf LONG_BIT" will work just as well.

lsusb
# cat file1.mp3 file2.mp3 > file3.mp3
2010-01-17 13:18:34
User: svnlabs
Functions: cat
-4

cat - concatenate MP3 files and save it...