### All commands (14,043) the last day the last week the last month all time sorted by date votes

• Easy and direct way to find this out. Show Sample Output

121
getconf LONG_BIT
· 2009-08-08 21:22:19
• 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).

117
· 2009-03-04 06:21:22
• This will output the characters at 10 per second.

116
echo "You can simulate on-screen typing just like in the movies" | pv -qL 10
· 2010-01-14 20:17:44

• 115
history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head · 2009-02-11 13:12:29 • 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 110 <alt> + <print screen/sys rq> + <R> - <S> - <E> - <I> - <U> - <B> · 2009-02-20 07:28:56 • 105 mv filename.{old,new} · 2009-03-02 02:28:55 • ps returns all running processes which are then sorted by the 4th field in numerical order and the top 10 are sent to STDOUT. Show Sample Output 102 ps aux | sort -nk +4 | tail · 2009-01-23 17:12:33 • Deletes all files in a folder that are NOT *.foo, *.bar or *.baz files. Edit the pattern inside the brackets as you like. Show Sample Output 101 rm !(*.foo|*.bar|*.baz) · 2010-04-13 15:13:54 • 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) 101 pushd /tmp · 2009-02-16 16:52:59 • 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 100 echo "!!" > foo.sh · 2009-02-25 00:37:25 • 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). 98 some_very_long_and_complex_command # label · 2009-09-08 05:58:27 • 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 98 \[command] · 2009-02-11 19:34:21 • 96 lsof -i · 2009-04-25 14:24:04 • bash/ksh subshell redirection (as file descriptors) used as input to diff 96 diff <(sort file1) <(sort file2) · 2009-02-04 22:20:13 • 94 lsof -P -i -n · 2009-09-19 18:28:48 • !* 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 94 !* · 2009-06-21 17:58:01 • 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.

93
echo "The date is: $(date +%D)" · 2009-03-07 15:51:59 • 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 91 nc -v -l 80 < file.ext · 2009-02-17 14:39:52 • 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 89 man hier · 2010-01-26 16:31:05 • 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.

88
awk '/start_pattern/,/stop_pattern/' file.txt
· 2009-03-28 14:28:59
• 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.

87
CDPATH=:..:~:~/projects
· 2009-03-20 14:50:25
• 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. For more info on vim's encrypted files visit: http://www.vim.org/htmldoc/editing.html#encryption Show Sample Output

86
vim -x <FILENAME>
· 2009-05-05 23:24:17

• 85
ifconfig | convert label:@- ip.png
· 2011-08-24 05:58:29
• Using awk, find duplicates in a file without sorting, which reorders the contents. awk will not reorder them, and still find and remove duplicates which you can then redirect into another file.

82
awk '!x[$0]++' <file> · 2009-12-20 02:33:21 • 80 ssh-copy-id [email protected] · 2009-02-16 12:11:26 • < 1 2 3 4 > Last › ### What's this? commandlinefu.com is the place to record those command-line gems that you return to again and again. 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. ### Check These Out diff files while disregarding indentation and trailing white space Convert seconds to [DD:][HH:]MM:SS Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

find files in a date range
Example above will recursively find files in current directory created/modified in 2010.

Calculate 1**2 + 2**2 + 3**2 + ...

tcpdump top 10 talkers
capture 2000 packets and print the top 10 talkers

extract email adresses from some file (or any other pattern)
This will catch most separators in the section of the email: dot . dash - underscore _ plus + (added for gmail) ... and the basic dash '-' of host names.

Get creation date of a file on ext2-3-4 fs
Return the creation date of a file on ext2, 3, 4 filesystems, because stat command won't show it. Useful on ubuntu, debian, and else

escape any command aliases
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

easily trace all Nginx processes
Nginx (and other webservers like Apache) can be awkward to trace. They run as root, then switch to another user once they're ready to serve web pages. They also have a "master" process and multiple worker processes. The given command finds the process IDs of all Nginx processes, joins them together with a comma, then traces all of them at once with "sudo strace." System trace output can be overwhelming, so we only capture "networking" output. TIP: to kill this complex strace, do "sudo killall strace". Compare with a similar command: http://www.commandlinefu.com/commands/view/11918/easily-strace-all-your-apache-processes

Calculates the size on disk for each package installed on the filesystem (or removed but not purged). This is missing the \$ | sort -rn which would put the biggest packges on top. That was purposely left out as the command is slightly on the slow side Also you may need to run this as root as some files can only be checked by du if you can read them ;)