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,581 results
cat > /dev/null
2010-10-08 14:35:25
User: GouNiNi
Functions: cat
-5

In exemple, screen can bind keys to switch between windows. I like to use Ctrl + Arrow to move left or right window. So I bind like this in .screenrc :

bindkey ^[OD prev # Ctl-left, prev window

bindkey ^[OC next # Ctl-right, next window

rpm -qf /lib/modules/*
2010-03-01 05:00:56
User: megacoder
Functions: rpm
-5

Exploit that RPM database just sitting there, taking up space.

while read line; do echo $line; done <<< "$var"
2011-09-22 16:53:32
User: totti
Functions: echo read
-5

Consider the following simple situation [ reading something using while and read ]

[See script 1 in sample output]

---------------------------------------------------

The variable var is assigned with "nullll" at first. Inside the while loop [piped while] it is assigned with "whillleeee". [Onlly 2 assignments stmts]. Outside the loop the last assigned value for "var" [and no variable] inside the while can't be accessed [Due to pipe, var is executed in a sub shell].

In these type of situation variables can be accessed by modifying as follows.

[See script 2 in sample output]

___________________________

Vary helpful when reading a set of items, say file names, stored on a file [or variable] to an array an use it later.

Is there any other way 2 access variables inside and outside the loop ??

while true; do sleep 4 ; xdotool click 1 ; done
2011-09-23 09:23:02
User: rusino
Functions: sleep
-5

Automation click every 4 second on a macro slot bar to world of warcraft for prospecting item

enable auto loot and create macro, put mouse over slot on the bar

/cast Prospecting

/use Elementium Ore

history -r
poweriso convert image.daa -o image.iso -ot iso
for person in Alex Bruce Fred Kathy Vicki Victoria ; do say -v $person "Hello, my name is $person"; sleep 1; done
2009-03-09 15:42:13
User: haivu
Functions: sleep
Tags: Os X
-5

Listen to different voices in the system--useful for picking the voice you like

find /dir/ -name *name*
2009-02-09 20:24:10
User: cinan
Functions: find
-5

"*" is important if you don't know exact name of file. Check it out and you'll see

find . -exec chmod 777 {} \;
pkill $1
2009-07-20 12:47:41
User: svg
-5

There's already a proper command for what the former alternative tried to script

echo alias xkcd="gwenview `w3m -dump http://xkcd.com/|grep png | awk '{print $5}'` 2> /dev/null" >> .bashrc
2010-01-30 20:38:16
User: GinoMan2440
Functions: alias echo
-5

Add an alias to your .bashrc that allows you to issue the command xkcd to view (with gwenview) the newest xkcd comic... I know there are thousands of them out there but this one is at least replete with installer and also uses a more concise syntax... plus, gwenview shows you the downloading progress as it downloads the comic and gives you a more full featured viewing experience.

can(){ shift 2; sudo "$@"; }
lynx --dump http://ip.boa.nu|sed -e 's/^[[:space:]]*//' -e 's/*[[:space:]]$//'|grep -v ^$
2009-11-04 22:23:45
User: xeor
Functions: grep sed
-5

For those of us that still uses lynx :)

print -l $path
2009-08-27 16:33:04
User: Mikachu
Tags: zsh PATH
-5

This doesn't work in bash, but in zsh you can typeset -T to bind a scalar variable to an array. $PATH and $path behave this way by default.

echo *
2009-04-17 21:40:58
User: kFiddle
Functions: echo
Tags: echo ls
-5

Sometimes "ls" is just too slow, especially if you're having problems with terminal scroll speed, or if you're a speed freak. In these situations, do an echo * in the current directory to immediately see the directory listing. Do an echo * | tr ' ' '\n' if you want a column. Do an alias ls='echo *' if you want to achieve higher echelons of speed and wonder. Note that echo * is also useful on systems that are so low in memory that "ls" itself is failing - perhaps due to a memory leak that you're trying to debug.

rm ~/.bash_history && kill -9 $$
2009-10-08 12:25:47
User: Velenux
Functions: kill rm
-5

Best way I know to get rid of .bash_history and don't allow bash to save the current one on exit

Edit: added ~/ before .bash_history, just in case... ;)

while read col1 col23; do echo $col1; done < three-column.txt > first-column.txt
jot -b '' 100
ls -1 | sort -R | sed -n 's/^/Selected /;1p'
tail -n +4 | head -n 1
grep '^[^#]' squid.conf
2013-02-21 18:51:06
User: Flow
Functions: grep
Tags: regex grep,
-5

grep '^[^#]' sample.conf

\__/ |||| \_________/

| |||| |

| |||| \- Filename

| ||||

| |||\- Only character in group is '#'

| |||

| ||\- Negate character group (will match any cahracter *not* in the

| || group)

| ||

| |\- Start new character group (will match any character in the

| | group)

| |

| \- Match beginning of line

|

\- Run grep

Empty lines will also be not matched, because there has to be at least one non-hash-sign character in the line.

ls -R .
rm ~/.bash_history; ln -s /dev/null ~/.bash_history
2009-10-08 17:40:48
Functions: ln rm
-5

Remove your BASH history and then link it to /dev/null

getenforce
2009-10-08 23:06:00
User: felix001
-5

Shows the status of SElinux.

-- fir3net.com --

sudo update-grub
2014-02-27 19:50:25
User: Anshik
Functions: sudo
-5

sudo gedit /etc/default/grub

This would open the Grub configuration file. In this file we have to edit the line

GRUB_CMDLINE_LINUX=""

to

GRUB_CMDLINE_LINUX="acpi_backlight=vendor"