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,490 results
shuf file.txt | head -n 1
xterm -e "cd /my/directory; bash"
2009-10-13 12:06:14
User: kekschaot
-4

Usefull e.g. in krusader open terminal function

( cd /my/directory; xterm& )
2009-10-13 13:07:21
User: ashawley
Functions: cd
Tags: subshells
-4

Perfect time for the rarely used sub shell.

aptitude purge linux-image | grep ^i | grep -v $(uname -r)
sleep 4h && halt
uname -m # display machine "hardware name"
2013-01-04 11:46:43
User: mpb
Functions: uname
-4

Display the machine "hardware name" 32 or 64 bit.

"x86_64" is shown on 64 bit machines

"i686" is typically shown on 32 bit machines (although, you might also see "i386" or "i586" on older Linuxen).

On other "unix-like" systems, other hardware names will be displayed.

For example, on AIX, "uname -m" gives the "machine sequence number".

For whatever reason, IBM decided that "uname -M" would give the machine type and model.

(ref: http://www.ibm.com/developerworks/aix/library/au-aix-systemid.html )

On Sun Solaris, "uname -m" can be used to determine the chip type and "isainfo -v" will reveal

if the kernel is 64 or 32 bit.

(ref: http://www.ibiblio.org/pub/packages/solaris/sparc/html/32.and.64.bit.packages.html )

A more reliable way to determine "64-bit ness" across different Unix type systems is to compile the following simple C program:

cat <<eeooff > bits.c

/*

* program bits.c

* purpose Display "32" or "64" according to machine type

* written January 2013

* reference http://www.unix.org/whitepapers/64bit.html

*/

/* hmm, curious that angle-brackets removed by commandlinefu.com data input processing? */

#include "/usr/include/stdio.h"

long lv = 0xFFFFFFFF;

main ( ) {

printf("%2d\n",(lv < 0)?32:64);

}

eeooff

Compile and run thusly: cc -o bits bits.c; ./bits

<command> 2> <file>
ps aux | grep -v `whoami`
echo '#!'$(which bash) > script.sh
2012-02-06 08:25:27
User: sharfah
Functions: echo which
Tags: bash
-4

Writes out the shebang line (#!/bin/bash) to the script.

ls | xargs WHATEVER_COMMAND
2014-03-12 18:00:21
User: pdxdoughnut
Functions: ls xargs
-4

xargs will automatically determine how namy args are too many and only pass a reasonable number of them at a time. In the example, 500,002 file names were split across 26 instantiations of the command "echo".

php -r 'echo md5("password") . "\n";'
ls -l|awk '{print $6,$8}'|sort -d
2009-03-13 19:00:18
User: archlich
Functions: awk ls sort
-4

Can pipe to tail or change the awk for for file size, groups, users, etc.

for file in $(seq -f '%03.f' 1 $TOTAL ); do echo "($file/$TOTAL)"; curl -f -O http://domain.com/Name_$file.ext; done
2010-01-12 15:23:44
User: nordri
Functions: echo file seq
-4

With counter format [001, 002, ..., 999] , nice with pictures or wallpapers collections.

for i in *; do echo '"'$i'"'; done
find /etc -exec grep '[0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*' {} \;
mkdir 0{0..9}{0..9};mv 000 100
2009-08-14 16:33:20
User: sitaram
Functions: mkdir
-4

no external commands, but can only do 0-99, not 1-100, so we adjust it later

ps -xaw -o state,ppid | grep Z | grep -v PID | awk '{ print $2 }' | xargs kill -9
2013-01-09 04:21:54
User: terrywang
Functions: awk grep kill ps xargs
-4

Did some research and found the previous command wrong, we don't kill a zombie but its parent. Just made some modifcation to khashmeshab's command.

ls -F | grep '\''\*'\'' | sed '\''s/\*$//'\
service mysqld restart
2013-12-18 19:13:56
User: denni
-4

This command restarts mysql service.

ls -Sl * | head
2009-03-27 23:20:32
User: colinpj
Functions: ls
-4

head by default displays first ten lines of its output. Use 'head -nXX' to display the XX largest files

nc -w 5 -v -l -p 80 < file.ext
/etc/rc.d/init.d/ntpd start
2013-12-18 20:49:42
User: denni
-4

This command starts up the time synchronization service.

sudo chmod -R g=u-w,g+X *
echo 'example' | sed -e 's/^\(.\)/\U\1/'
less textfile.gz
2009-03-15 23:51:17
User: allbad
Functions: less
-4

There is no need to 'zcat textfile.gz | less' with newer distros. This is useful for reading archived log files without having to extract, read, and zip when done.