What are some of your favorite shell tips? Stuff that makes your every day command line use that much easier?
Mine, for bash:
Add this to the .inputrc file in your home dir:
"\e[A": history-search-backward
"\e[B": history-search-forward
Now, when you start typing at the prompt, the arrow keys will search through your history for any other commands that start with what you've already typed.
If you are a vi user, try vi mode for bash:
Press ESC to enter command mode. From there, you can navigate the command line using familiar vi commands (hjkl, w, ^, $, i, A, c, d, etc). You can search your command history using /. You can even press v to fire up vi and edit your current command.
See this cheat sheet for a list of supported vi commands.
Not a tip, instead more of a meta-tip. There are lots of cool cli reciipies at http://www.commandlinefu.com/
Here's the ones I use the most in day to day stuff in bash
Keyword shortcuts I use the most - tab of course for tab completion (setup bash completion to make this even better) - up and down for navigating the history - ctrl-a and ctrl-e for start and end of the line - ctrl-r for searching through your history (just start typing the start of the command) - ctrl-g to cancel the search - alt-f move cursor forward a word - alt-b move the cursor back a word - esc then . to add the last argument of the last command to the current command (doing it again goes to the last arg of the command before that) - alt-d delete the word in front of the current position of the cursor - ctrl-w delete the word behind the current position of the cursor - ctrl-u to delete everything from the current position of the cursor to the start of the line - ctrl-k to delete everything from the current position to the end of the line
On top of this, make sure you have a colour ls setup, I add the git branch to my prompt
I also always have the reload function in my .bash_aliases file (which is obviously sourced from my .bashrc or .bash_profile file)
I deal with a lot of different machines so one of my favorites is aliases for each machine that I need to frequently SSH to:
It is also useful to setup a good
.ssh/config
and ssh keys to make hopping amongst machines even easier.Another one of my favorite aliases is for moving up directories:
And some for commonly used variations of
ls
(and typos):History can be very useful, but by default on most distributions your history is blown away by each shell exiting, and it doesn't hold much to begin with. I like to have 10,000 lines of history:
That way, if I know that I've done something before but can't remember the specifics, a quick
history | grep foo
will help jog my memory.I often found myself piping output through
awk
in order to get a certain column of the output, as indf -h | awk '{print $2}'
to find the size of each of my disks. To make this easier, I created a functionfawk
in my .bashrc:I can now run
df -h|fawk 2
which saves a good bit of typing.Probably one of the simplest, and most useful things is just learning the readlin shorcuts. So ^h for backspace, ^u to delete a line up to the cursor, ^k to delete the line after the cursor. There's a complete list of the shortcuts here [here][1]http://www.bigsmoke.us/readline/shortcuts.
As well as that, on debian/ubuntu (at least, don't have any other linuxes to test it on, adding this to your .bashrc will enable smart completion in bash, like in zsh, so that arguments to common commands (like find, etc) will be tab completable