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!

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

### Stay in the loop…

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.

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

Hide

Hide

### Credits

Site by David Winterbottom (user root).

All commands from sorted by
Terminal - All commands - 11,604 results
less +F somelogfile
2009-02-19 14:33:46
Functions: less
114

Using +F will put less in follow mode. This works similar to 'tail -f'. To stop scrolling, use the interrupt. Then you'll get the normal benefits of less (scroll, etc.).

Pressing SHIFT-F will resume the 'tailling'.

2009-03-26 22:59:48
Functions: telnet
Tags: telnet
107

Use Ctrl-] to stop it.

2009-05-31 07:18:01
Functions: shutdown
Tags: Linux windows
105

This will issue a shutdown command to the Windows machine. username must be an administrator on the Windows machine. Requires samba-common package installed. Other relevant commands are:

net rpc shutdown -r : reboot the Windows machine

net rpc abortshutdown : abort shutdown of the Windows machine

Type:

net rpc

to show all relevant commands

curl -u username --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if /<name>/; print "$2\n" if /<(title|name)>(.*)<\/\1>/;' 2009-09-08 06:53:39 Functions: perl 100 notice what happens when there is more than one unread message in a thread... also people please dont hardcode the password when you use curl. Leave it out and curl will ask you when it runs. Please...? disown -a && exit 2009-04-10 12:22:34 Tags: bash 99 ping -i 60 -a IP_address 2009-03-04 06:21:22 Functions: ping Tags: Network 99 Waiting for your server to finish rebooting? Issue the command above and you will hear a beep when it comes online. The -i 60 flag tells ping to wait for 60 seconds between ping, putting less strain on your system. Vary it to your need. The -a flag tells ping to include an audible bell in the output when a package is received (that is, when your server comes online). <alt> + <print screen/sys rq> + <R> - <S> - <E> - <I> - <U> - <B> 2009-02-20 07:28:56 99 If the machine is hanging and the only help would be the power button, this key-combination will help to reboot your machine (more or less) gracefully. R - gives back control of the keyboard S - issues a sync E - sends all processes but init the term singal I - sends all processes but init the kill signal U - mounts all filesystem ro to prevent a fsck at reboot B - reboots the system Save your file before trying this out, this will reboot your machine without warning! http://en.wikipedia.org/wiki/Magic_SysRq_key echo "You can simulate on-screen typing just like in the movies" | pv -qL 10 2010-01-14 20:17:44 Functions: echo 96 This will output the characters at 10 per second. getconf LONG_BIT 2009-08-08 21:22:19 Functions: getconf Tags: getconf 32 64 95 Easy and direct way to find this out. history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
2009-02-11 13:12:29
Functions: awk sort
95
ps aux | sort -nk +4 | tail
2009-01-23 17:12:33
Functions: ps sort
93

ps returns all running processes which are then sorted by the 4th field in numerical order and the top 10 are sent to STDOUT.

while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;done &
2011-02-17 11:13:19
Functions: sleep tput
89

A nice way to use the console in full screen without forget the current time.

you can too add other infos like cpu and mem use.

pushd /tmp
2009-02-16 16:52:59
83

If are a Bash user and you are in a directory and need to go else where for a while but don't want to lose where you were, use pushd instead of cd.

cd /home/complicated/path/.I/dont/want/to/forget

pushd /tmp

cd thing/in/tmp

popd (returns you to /home/complicated/path/.I/dont/want/to/forget)

\[command]
2009-02-11 19:34:21
83

e.g. if rm is aliased for 'rm -i', you can escape the alias by prepending a backslash:

rm [file] # WILL prompt for confirmation per the alias

\rm [file] # will NOT prompt for confirmation per the default behavior of the command

lsof -i
2009-04-25 14:24:04
81
CDPATH=:..:~:~/projects
2009-03-20 14:50:25
Tags: bash
81

CDPATH tells the cd command to look in this colon-separated list of directories for your destination. My preferred order are 1) the current directory, specified by the empty string between the = and the first colon, 2) the parent directory (so that I can cd lib instead of cd ../lib), 3) my home directory, and 4) my ~/projects directory.

echo "!!" > foo.sh
2009-02-25 00:37:25
Functions: echo
81

Sometimes commands are long, but useful, so it's helpful to be able to make them permanent without having to retype them. An alternative could use the history command, and a cut/sed line that works on your platform.

history -1 | cut -c 7- > foo.sh
awk '/start_pattern/,/stop_pattern/' file.txt
2009-03-28 14:28:59
Functions: awk
80

I find this terribly useful for grepping through a file, looking for just a block of text. There's "grep -A # pattern file.txt" to see a specific number of lines following your pattern, but what if you want to see the whole block? Say, the output of "dmidecode" (as root):

dmidecode | awk '/Battery/,/^$/' Will show me everything following the battery block up to the next block of text. Again, I find this extremely useful when I want to see whole blocks of text based on a pattern, and I don't care to see the rest of the data in output. This could be used against the '/etc/securetty/user' file on Unix to find the block of a specific user. It could be used against VirtualHosts or Directories on Apache to find specific definitions. The scenarios go on for any text formatted in a block fashion. Very handy. diff <(sort file1) <(sort file2) 2009-02-04 22:20:13 Functions: diff sort 80 bash/ksh subshell redirection (as file descriptors) used as input to diff !* 2009-06-21 17:58:01 78 !* is all of the arguments to the previous command rather than just the last one. This is useful in many situations. Here's a simple example: vi cd /stuff oops! [exit vi, twice] !* expands to: cd /stuff nc -v -l 80 < file.ext 2009-02-17 14:39:52 77 From the other machine open a web navigator and go to ip from the machine who launch netcat, http://ip-address/ If you have some web server listening at 80 port then you would need stop them or select another port before launch net cat ;-) * You need netcat tool installed some_very_long_and_complex_command # label 2009-09-08 05:58:27 76 When using reverse-i-search you have to type some part of the command that you want to retrieve. However, if the command is very complex it might be difficult to recall the parts that will uniquely identify this command. Using the above trick it's possible to label your commands and access them easily by pressing ^R and typing the label (should be short and descriptive). UPDATE: One might suggest using aliases. But in that case it would be difficult to change some parts of the command (such as options, file/directory names, etc). echo "The date is:$(date +%D)"
2009-03-07 15:51:59
Functions: echo
76

This is a simple example of using proper command nesting using $() over . There are a number of advantages of$() over backticks. First, they can be easily nested without escapes:

program1 $(program2$(program3 $(program4))) versus program1 program2 \program3 \program4\\ Second, they're easier to read, then trying to decipher the difference between the backtick and the singlequote: `'. The only drawback$() suffers from is lack of total portability. If your script must be portable to the archaic Bourne shell, or old versions of the C-shell or Korn shell, then backticks are appropriate, otherwise, we should all get into the habit of \$(). Your future script maintainers will thank you for producing cleaner code.

lsof -P -i -n
2009-09-19 18:28:48
75
mv filename.{old,new}
2009-03-02 02:28:55
Functions: mv
74