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

less +F somelogfile

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

12) Set audible alarm when an IP address comes online

ping -i 60 -a IP_address

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

13) Backticks are evil

echo “The date is: $(date +%D)”

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.

14) Simulate typing

echo “You can simulate on-screen typing just like in the movies” | pv -qL 10

This will output the characters at 10 per second.

15) python smtp server

python -m smtpd -n -c DebuggingServer localhost:1025

This command will start a simple SMTP server listening on port 1025 of localhost. This server simply prints to standard output all email headers and the email body.

16) Watch Network Service Activity in Real-time

lsof -i

17) diff two unsorted files without creating temporary files

diff <(sort file1) <(sort file2)

bash/ksh subshell redirection (as file descriptors) used as input to diff

18) Rip audio from a video file.

mplayer -ao pcm -vo null -vc dummy -dumpaudio -dumpfile <output-file> <input-file>

replace accordingly

19) Matrix Style

tr -c “[:digit:]” ” ” < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR=”1;32″ grep –color “[^ ]”

20) This command will show you all the string (plain text) values in ram

sudo dd if=/dev/mem | cat | strings

A fun thing to do with ram is actually open it up and take a peek.

21) Display which distro is installed

cat /etc/issue

22) Easily search running processes (alias).

alias ‘ps?’=’ps ax | grep ‘

23) Create a script of the last executed command

echo “!!” > foo.sh

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

24) Extract tarball from internet without local saving

wget -qO – “http://www.tarball.com/tarball.gz” | tar zxvf –

25) Create a backdoor on a machine to allow remote connection to bash