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
hostinfo.sh
2009-02-11 01:15:14
User: kongxx
-4

#!/bin/sh

_HOSTNAME=`hostname`

_HOSTTYPE=`echo $HOSTTYPE`

_MACHINETYPE=`echo $MACHTYPE`

_OSTYPE=`echo $OSTYPE`

_VENDOR=`echo $VENDOR`

_KERNEL=`uname -r | awk -F- '{print $1}'`

_GLIBC=`ls /lib/libc-*.so | awk -F- '/lib/ {print $2}' | awk -F. '{print $1"."$2}'`

_MEM=`cat /proc/meminfo | awk '/MemTotal/ {print $2 $3}'`

_CPU=`cat /proc/cpuinfo | grep 'cpu MHz' | awk '{print $4}'`

echo '=============================='

echo 'HOSTNAME ' $_HOSTNAME

echo 'HOSTTYPE ' $_HOSTTYPE

echo 'MACHINETYPE ' $_MACHINETYPE

echo 'OSTYPE ' $_OSTYPE

echo 'VENDOR ' $_VENDOR

echo 'KERNEL ' $_KERNEL

echo 'GLIBC ' $_GLIBC

echo 'MEM INFO ' $_MEM

echo 'CPU INFO ' $_CPU

echo '=============================='

find ./* -name 'CVS' | awk '{print "dos2unix " $1 "/*"}' | awk '{system($0)}'
mogrify -resize 1024 *.jpg
2009-02-11 00:01:29
User: mitzip
1

This command requires the imagemagick libraries and will resize all files with the .jpg extension to a width of 1024 pixels and will keep the same proportions as the original image.

alias apt-get='sudo apt-get'
2009-02-10 22:45:49
User: mogsie
Functions: alias
-4

apt-get must be run as root, and it is useless to run it as your own user. So just run it as root. Saves you the "sudo !!" every time you're adding a package.

watch -n 15 curl -s --connect-timeout 10 http://www.google.com/
2009-02-10 21:48:45
User: dltj
Functions: watch
6

If your web server is down, this command will periodically attempt to connect to it. If the output is blank, your server is not yet up. If you see HTML, your server is up. Obviously, you need to replace the Google URL with your web server URL...

* 'watch' -- a command for re-executing a command and displaying

the output

* '-n 15' -- tells watch to redo the command every 15 seconds

* 'curl' -- a handy utility for getting the source of a web page

* '-s' -- tells curl to be silent about failing

* '--connect-timeout 10' -- Try to connect for 10 seconds

svn st | grep "^\?" | awk "{print \$2}" | xargs rm -rf
svn diff --diff-cmd diff -x -uw /path/to/file
2009-02-10 20:39:54
User: katylava
Functions: diff
0

get subversion diff output without distracting whitespace changes. good for when you are cleaning up code to make sure you didn't change anything important. also useful when working with old code, or someone else's code.

rsync -zav --progress original_files_directory/ root@host(IP):/path/to/destination/
2009-02-10 17:01:04
User: haithamg
Functions: rsync
1

copying files from one server to another using rysnc. Root access need to be allowed on the destination.

rename .oldextension .newextension *.oldextension
2009-02-10 16:58:05
User: haithamg
Functions: rename
11

Changing a file extension to a new one for all files in a directory.

chown -cR --from=olduser:oldgroup newuser:newgroup *
2009-02-10 16:55:09
User: haithamg
Functions: chown
1

Changing files ownership in a directory recursivley from a user to another

find . -name Root -print | xargs rm -f
tar zcvf somedir-$(date +%Y%m%d-%H%M).tar.gz somedir/
2009-02-10 15:25:40
User: kmac
Functions: date tar
3

A useful bash function:

gztardir()

{

if [ $# -ne 1 ] ; then

echo "incorrect arguments: should be gztardir "

else

tar zcvf "${1%/}-$(date +%Y%m%d-%H%M).tar.gz" "$1"

fi

}

archivefile=filename-$(date +%Y%m%d-%H%M).tar.gz
cat file.php | perl -p -e 's/(\$|->)(str|arr|obj|int|flt|boo|bool|mix|res)([A-Z])/$1\L$3/g'
2009-02-10 14:37:12
User: root
Functions: cat perl
0

This removes the type prefix used in Hungarian notation (v. bad) for PHP variables. Eg. variables of the form $intDays, $fltPrice, $arrItems, $objLogger convert to $days, $price, $Items, $logger.

alias ll="ls -lh --color=auto"
cd XX YY
2009-02-10 13:20:11
User: yogsototh
Functions: cd
3

If you are in /begin/path/with/XX/pattern

cd XX YY

will change your current directory to

/begin/path/with/YY/pattern

in ZSH

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.

find . -name "*.php" -exec php -l {} \; | sed -e "/^No syntax/d"
2009-02-10 09:14:25
User: TomNomNom
Functions: find sed
1

Uses the PHP binary to check the syntax of all .php files in or below the current working directory. Really handy for doing that last minute check before you commit code to the repository.

sudo date mmddhhxxyyyy
git add -u
ps aux | grep [h]ttpd
2009-02-10 02:59:20
User: abcde
Functions: grep ps
10

Surround the first letter of what you are grepping with square brackets and you won't have to spawn a second instance of grep -v. You could also use an alias like this (albeit with sed):

alias psgrep='ps aux | grep $(echo $1 | sed "s/^\(.\)/[\1]/g")'

xxdiff -r --exclude=.svn
2009-02-09 23:07:07
User: andrewf
-1

Needs xxdiff installed, which looks a bit clunky but is an extremely powerful graphical diff.

script
2009-02-09 22:38:56
User: chrisdrew
Functions: script
9

Creates a log of a session in a file called typescript. Or specify the file with:

script filename

Exit the session with control-d.

ls -R | grep : | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\''
2009-02-09 22:32:01
User: scw
Functions: grep ls sed
-3

Shows the current directory and those below it in a simple tree structure. Recommended use:

alias lt='$command_above'

aticonfig --pplib-cmd "set fanspeed 0 <number>"