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,927 results
(echo "" | xsel -o) ; (programa | wgetpaste -s dpaste | awk '{print $7}' | xsel -ai)
2010-03-05 09:31:30
User: dvinchi666
Functions: awk echo
Tags: pipes paste
-4

manda la salida de un comando hacia un servicio de paste y coloca la url de ese paste en el portapapeles

wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
echo -n "Press any key to continue..." && read
2009-11-06 22:49:46
User: matthewbauer
Functions: echo
-4

This works on some other version of read.

tar -xfv archive.zip
2010-10-14 08:19:16
User: vxbinaca
Functions: tar
-4

Simplicity tends to win out on commandlinefu.com Also, why type multiple filenames when range operators work too. Saves finger abuse and time and reduces the chances for mistakes.

sync; echo 3 > /proc/sys/vm/drop_caches
2011-04-26 21:12:06
User: renich
Functions: echo sync
-4

It clears caches from memory. It works fine on CentOS and Fedora. It will show you how much memory you need, for real.

cowsay `fortune` | toilet --gay -f term
curl http://en.m.wikipedia.org/wiki/List_of_Internet_top-level_domains | grep "<tr valign=\"top\">" | awk -F">" '{ print $5 }' | awk -F"<" '{ print $1 }'
2012-12-24 21:00:36
User: sxiii
Functions: awk grep
-4

Oneliner to get domain names list of all existing domain names (from wikipedia)

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.

unzip \*.zip
2009-03-26 02:36:28
User: tiagofischer
Tags: unzip
-4

"unzip *.zip" doesn't work as expected, because unzip handle wildcards in a different way.

You just need to escape the wildcard or do in another way:

for f in *.zip; do unzip "$f"; done
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 '=============================='

alias ltr 'ls -altr'
2011-06-11 03:22:13
User: drb532
Functions: alias
-4

Create an alias to list all contents of the current directory in "reverse" time order. Thus the last modified file will appear just above your next prompt. Useful for remembering where you left off modifying files in a folder or just noting recent changes.

csh format but bash syntax similar

unlink <linkname>
2009-03-12 01:52:24
User: topgun553
Functions: unlink
-4

if you had a symbolic link called "oldLink" in the current folder then you would want to do

unlink oldLink

http://goosh.org
2009-08-29 12:19:34
User: unixbhaskar
Tags: web browser
-4

You can try it . Nice shell interface to search google from the command line.Visit http://goosh.org in your browser.

find . -type f | while read f; do chmod -x "$f"; done
moon-buggy
2009-04-22 05:41:40
User: eastwind
-4

sudo apt-get install moon-buggy

An ascii 2D game where you control a mooncar and try to avoid moonhole by jumping (press space )

VARIABLE="VALUE" COMMAND
2009-03-12 07:04:44
User: magmax
-4

Allows you to change the value of an environment variable only for the execution of the command in the line. (corrected)

sed -i -n '/%/p' *.php
head -$(($RANDOM % $(wc -l < file.txt) +1 )) file.txt | tail -1
export HISTFILE=/dev/null/
2010-06-10 18:48:43
User: thund3rpants
Functions: export
-4

This command is great for dumping your history so that when you're working on a system that is under a shared account, you can keep others from reviewing your history file. I use this when I'm just visiting a system to diagnose a problem, or to make a quick fix.

ps aux | grep process-name | grep -v "grep"
dd if=/dev/sda of=~/backup-disk-YY-MM-DD.img
2010-09-14 11:14:14
Functions: dd
-4

Change /dev/sda with the Disk or partition you want to back-up

To restore use:

dd if=~/backup-disk-YY-MM-DD.img of=/dev/sda

Once again change /dev/sda accordingly

Source: http://www.go2linux.org/linux/2010/09/small-tip-back-disks-clone-hard-disk-773

/bin/ls *.png | xargs -l1 -I {} convert {} -modulate 100,100,70 ../../icons/32x32/{}
mvn -Dmaven.test.skip=true install
2009-05-20 12:55:10
User: sharfah
Tags: maven
-4

the maven.test.skip property can be added to other goals too.

ls | while read -r FILE; do mv -v "$FILE" `echo "prependtext$FILE" `; done
2010-08-14 14:19:18
User: IgnitionWeb
Functions: ls mv read
Tags: echo mv prepen
-4

Prepends all directory items with "prependtext"