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,604 results
umount -t smbfs
2012-02-23 10:46:44
User: Velenux
Functions: umount
Tags: samba
-2

smbfs or cifs, depends on which you are using

< /dev/urandom tr -dc A-Za-z0-9_ | head -c $((1024 * 1024)) | tee >(gzip -c > out.gz) >(bzip2 -c > out.bz) > /dev/null
cat /sys/devices/virtual/dmi/id/board_name
2010-04-22 03:21:40
User: matthewbauer
Functions: cat
-2

Prints the type of computer you have.

I think this should be used more in distros and other applications because it is so easy to get. This can also be asked by tutorials as an easy way to get your base hardware.

Some alternatives:

sudo dmidecode -s system-product-name

and

sudo smbios-sys-info-lite | sed -n 's/^Product Name: *\(.*\)/\1/p'
/sbin/ifconfig|grep -B 1 inet |head -1 | awk '{print $5}'
tar -C <source> -cf - . | tar -C <destination> -xf -
find . -name "*.gz" | xargs -n 1 -I {} bash -c "gunzip -c {} | sort | gzip -c --best > {}.new ; rm {} ; mv {}.new {}"
2009-08-05 14:16:15
User: kennethjor
Functions: bash find xargs
-2

I used this because I needed to sort the content of a bunch of gzipped log files. Replace sort with something else, or simply remove sort to just rezip everything

while read ; do python <script> ; done
2012-02-23 22:29:09
User: Zulu
Functions: python read
-2

Very useful for test a script. After launch this command, you only have to press ENTER for launch your script again. I work with screen and tape ENTER instead of '!!'+ENTER

If you break your script with CTRL-C, it will wait for press ENTER and will re-launch

You can write like it : while read -p "Press ENTER" ; do python ; done

cat /etc/shadow
ifconfig | grep -o "inet [^ ]*" | cut -d: -f2
2010-12-06 10:36:52
User: dooblem
Functions: cut grep ifconfig
Tags: ifconfig grep cut
-2

This is what we use.

You can grep -v 127.0.0.1 if you wish.

brew update && brew upgrade
find . -type f -exec ls -tr {} +
2010-05-27 14:52:28
Functions: find ls
-2

List all files from the current directory and subdirectories, sorted by modification time, oldest first.

command > tmp && cat logfile.txt >> tmp && tmp > logfile.txt && rm tmp
2009-04-05 22:00:32
User: akoumjian
Functions: cat command rm
-2

Adds the stdout (standard output) to the beginning of logfile.txt. Change "command" to whatever command you like, such as 'ls' or 'date', etc. It does this by adding the output to a temporary file, then adding the previous contents of logfile.txt to the temp file, then copying the new contents back to the logfile.txt and removing the temp file.

CTRL + e
ps auxwww | grep outofcontrolprocess | awk '{print $2}' | xargs kill -9
kill -9 $(pidof process)
ls -rl --time-style=+%s * | sed '/^$/,/^total [0-9]*$/d' | sort -nk6
echo src::${PATH} | awk 'BEGIN{pwd=ENVIRON["PWD"];RS=":";FS="\n"}!$1{$1=pwd}$1!~/^\//{$1=pwd"/"$1}{print $1}'
2009-09-09 04:03:46
User: arcege
Functions: awk echo
Tags: awk echo PATH
-2

Removes trailing newline; colon becomes record separator and newline becomes field separator, only the first field is ever printed. Replaces empty entries with $PWD. Also prepend relative directories (like ".") with the current directory ($PWD). Can change PWD with env(1) to get tricky in (non-Bourne) scripts.

for FILE in `ls -1`; do if [ -L "$FILE" ]; then cp $(readlink "$FILE") ${FILE}_rf; rm -f $FILE; mv ${FILE}_rf "$FILE"; fi; done
echo "Xc" | tr "Xo" "\033\017
kquitapp plasma
2009-02-16 21:27:16
User: raphink
Tags: KDE
-2

KDE4 is great, but still a bit buggy, and sometimes plasma requires to be restarted. Instead of quitting it with "killall plasma", which might loose your preferences (widgets, etc.), kquitapp will cleanly quit it. Tip: you can type this in the "Alt+F2" window, and then type "plasma" in Alt+F2 again to restart plasma (be patient though...).

find $DIR -name *.php -exec vim -u NONE -c 'set ft=php' -c 'set shiftwidth=4' -c 'set tabstop=4' -c 'set noexpandtab!' -c 'set noet' -c 'retab!' -c 'bufdo! "execute normal gg=G"' -c wq {} \;
2011-04-08 11:42:45
User: ruslan
Functions: find vim
-2

The sample command searches for PHP files replacing tabs with spaces.

-u NONE # don't use vimrc

Instead of

retab!

one may pass

retab! 4

for instance.

Look at this http://susepaste.org/69028693 also

ggqqqqq/^$dd@qq@q
2013-08-16 20:37:44
User: evilsoup
Tags: vim
-2

Here's the other way of doing it in vim: setting a recursive macro. 'gg' brings you to the top of the buffer, 'qqq' clears the 'q' macro, 'qq' starts recording a macro called 'q', '/^$' moves the cursor to the next empty line, 'dd' deletes the line that the cursor is on, '@q' calls the 'q' macro (currently empty because of 'qqq'), and 'q' stops recording the macro. '@q' calls the macro.

It will run until it cannot find another blank line, at which point it will throw up an error and cease.

While this is longer than the regex, you can use it without having to move your thoughts from 'vim-mode' to 'regex-mode'.

setenv GREP_COLOR '1;37;41'
find . -type d -name DIR -print0 | xargs -r0 rm -r
2009-03-04 14:49:21
User: miguelbaldi
Functions: find rm xargs
Tags: svn cvs
-2

You can use this command to delete CVS/svn folders on given project.

$class=ExampleClass; $path=src; for constant in `grep ' const ' $class.php | awk '{print $2;}'`; do grep -r "$class::$constant" $path; done