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

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Hide

Hide

### Credits

All commands from sorted by
Terminal - All commands - 12,330 results
2009-05-31 07:18:01
Functions: shutdown
Tags: Linux windows
111

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

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
108

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.

2009-03-04 06:21:22
Functions: ping
Tags: Network
108

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).

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 108 echo "You can simulate on-screen typing just like in the movies" | pv -qL 10 2010-01-14 20:17:44 Functions: echo 104 This will output the characters at 10 per second. getconf LONG_BIT 2009-08-08 21:22:19 Functions: getconf Tags: getconf 32 64 104 Easy and direct way to find this out. <alt> + <print screen/sys rq> + <R> - <S> - <E> - <I> - <U> - <B> 2009-02-20 07:28:56 104 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 ps aux | sort -nk +4 | tail 2009-01-23 17:12:33 Functions: ps sort 98 ps returns all running processes which are then sorted by the 4th field in numerical order and the top 10 are sent to STDOUT. mv filename.{old,new} 2009-03-02 02:28:55 Functions: mv 95 pushd /tmp 2009-02-16 16:52:59 93 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 91 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 90 echo "!!" > foo.sh 2009-02-25 00:37:25 Functions: echo 88 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 nc -v -l 80 < file.ext 2009-02-17 14:39:52 87 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 diff <(sort file1) <(sort file2) 2009-02-04 22:20:13 Functions: diff sort 87 bash/ksh subshell redirection (as file descriptors) used as input to diff rm !(*.foo|*.bar|*.baz) 2010-04-13 15:13:54 Functions: rm 86 Deletes all files in a folder that are NOT *.foo, *.bar or *.baz files. Edit the pattern inside the brackets as you like. !* 2009-06-21 17:58:01 86 !* 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 some_very_long_and_complex_command # label 2009-09-08 05:58:27 85 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). lsof -P -i -n 2009-09-19 18:28:48 84 awk '/start_pattern/,/stop_pattern/' file.txt 2009-03-28 14:28:59 Functions: awk 83 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.

CDPATH=:..:~:~/projects
2009-03-20 14:50:25
Tags: bash
83

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 "The date is: $(date +%D)" 2009-03-07 15:51:59 Functions: echo 82 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.

ifconfig | convert label:@- ip.png
2011-08-24 05:58:29
Functions: ifconfig
Tags: ImageMagick
79
man hier
2010-01-26 16:31:05
Functions: man
76

Curious about differences between /bin, /usr/bin, and /usr/local/bin? What should be in the /sbin dir? Try this command to find out.

Tested against Red Hat & OS X

vim -x <FILENAME>
2009-05-05 23:24:17
Functions: vim
76

While I love gpg and truecrypt there's some times when you just want to edit a file and not worry about keys or having to deal needing extra software on hand. Thus, you can use vim's encrypted file format.