This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

Sometimes bash settings are such that rm is aliased to rm -i and thus requires confirmation for each file being deleted. When I work occasionally on such an account, I use \rm to retrieve the original behaviour of rm without changing user configuration.

Once so often when you've typed a long command and before finishing it you've realized it won't work right away, because you need to run something else before (e.g. entered git commit -m "long commit message here"), you can hit ^A^K to go to the start of the line and kill it (saving into a buffer), next run a command to fix things, and finally ^Y to paste the killed command, and continue. Saves a lot of re-typing. All this, of course is when readline is in Emacs mode.

Another time-saver: mkdir -p some/nested/dirs/to/be/created creates all the dirs in a path if they're missing.

Display a prompt where the hostname is bold. I tried color prompts for a while, but the color would sometimes look bad depending on the background. Bold works for me for light background, dark background, blue backgrounds, etc.

This is for zsh, not bash, fyi (if you haven't used it, you won't regret trying it out). This is really useful for quickly typing out long paths for scp transfers. It works just like using to complete or list available filenames/directories.

I have folders named in my home folder as Document, Downloads, Temp, etc with the first letter in uppercase. When I work on the terminal it's annoying to shift press the first key when you are cd'ing into a directory. Just key in the following in your terminal and bash would auto-correct the case for you.

None of the following 'tricks' is technically challenging or impressive, but they have some impact on the other person. If we can't use our jobs to make our lives happier, then we should think again about some things.

I like alias. My favorite trick is to edit the ~/.bash_aliases on the computer of my gf as she is missing and add a line like:

where 123 is the of the person to whom I would like to wish happy birthday and mails.txt contains the message that I would like to write as the body of the email. Sleep 1; is sometimes necessary as there is a limit on fork(). You could also use command line arguments $1 etc...

Not really a one-liner but I think it's useful. Convert many files to uppercase, for example file_to_upper *php *c. There are many similar cases like converting to lower, renaming all files by suffix/prefix, etc.

ReTTY, which allows you to move a running program from one terminal to another. That way, if you have an ncurses program running outside of screen, tmux, or ssh, you can attach it to an ssh session or a networked screen or tmux session by running ReTTY inside the terminal where you want to use the program in question. In other words, it is similar to screen and tmux but with the exceptions that (a) it can only run one program at a time, and (b) it can be run after you start the child process.

What the above command does is find a file of name x and then searches said file for whatever pattern you are looking for. Incredibly useful if you are looking for a particular bit of code in a file that's somewhere in your subdirectories.

I find understanding bash key strokes leads to more efficient shelling, and that a lot of them are straight from emacs clarifies their usage (i.e. that meta-XXX is the big brother version of ctrl-XXX command usually).

The "meta" key is usually the "alt" key, but can also be "esc" key. e.g. meta-f can be got with either alt-f or esc f.

For the alt- key mappings to work, you may have to unset "menu access keys" or its equivalent in the console options. Basically if you press alt-f and get the file menu prompt, turn off the alt-key access menus.

ctrl-a / ctrl-e : move to start / end of line basics you can't do without

ctrl-f, meta-f : forward char/word pressing alt-f jumps you forward "1 word" which on command line is pretty much a command or argument

ctrl-b, meta-b : backwards char/word same as alt-f, but backwards to jump backwards through the command line

ctrl-d, meta-d : delete char/word pressing alt-d will delete (to end of) current word under cursor. much faster then holding delete down for 30 secs. Useful when you're tab completing in the middle of something and want to forward delete to the end of word.

ctrl-k : kill line deletes to the end of line

ctrl-u : undo
e.g. typing a password, and you know you've got it wrong somewhere, instead of hitting backspace 20 times, just hit ctrl-u. also clears the current command line.

meta-# : insert comment this is great for keeping your command line you're building up as a comment before running it if you need to do something else first. it will go into your command history but not run.

ctrl-g : abort if you're in middle of ctrl-r and want to just get back to where you were typing, just abort your search with ctrl-g

meta-space / ctrl-x ctrl-x : set mark and jump to mark if you need to quickly jump to a position in your command line, first set the mark, then jump back to it with ctrl-x ctrl-x. Note you may have to use esc-space to get the mark set as alt-space is often bound to bringing down the console menu.

ctrl-] <char> : quick jump to <char> jumps forward to the character typed after the ctrl-] on command line. The big brother Meta-ctrl-] <char> jumps backwards.