I miss or forget these commands very often. So I decided to write a post. If you know some other helpful commands or key combinations please let me know about them.

At the beginning I want to write some bash navigation commands. First one should be well known by you. It’s a quick search of previously-executed commands. You just press the key combination ctrl+r and type the first few letters of the command. It’s very helpful command excepts when you miss some details of the command. For example, you’re looking for “mysql -u root -p mydatabase” command and run “mysql -u root -p mydatabase < two-week-ago-backup.sql” command by accident. Yep… There is no fun anymore. So you should use it carefully.

Next two commands are safe. Their key combinations are crtl+a and crtl+e which bring your cursor to the begin or the end of your command. It may be helpful when you want to run a command in sudo mode.

The following three commands are similar to cut/paste key combinations. crtl+w allows you cut one word before a current position of the cursor. ctrl+u has the same behavior but cuts all words from the begin of the command to a current position of the cursor. And using ctrl+y you can put back previous cut words into your command.

Now I want to talk about commands which require superuser privileges. You’ve run the command

lighttpd.wrapper start

and have got the result:

lighttpd.wrapper: line 25: kill: (488) - Operation not permitted

Of course you can use “Up” key on your keyboard, then ctrl+a key combination and input sudo but there is an easy way. Just input

sudo !!

to run last executed command under superuser.

The last command is a tip for vim editor. If you need save the document with superuser privileges use the following command:

:w !sudo tee

This command shows you the files which contain “your search string” words.

grep -lir "your search string" *

To enable/disable startup sound in mac os x

sudo nvram -d SystemAudioVolume //enable
sudo nvram SystemAudioVolume="%00"  //disable