If you’ve ever typed a command at the Linux shell prompt, you’ve probably already used bash — after all, it’s the default command shell on most modern GNU/Linux distributions.
The bash shell is the primary interface to the Linux operating system — it accepts, interprets and executes your commands, and provides you with the building blocks for shell scripting and automated task execution.
Bash’s unassuming exterior hides some very powerful tools and shortcuts. If you’re a heavy user of the command line, these can save you a fair bit of typing. This document outlines 10 of the most useful tools:
1. Easily recall previous commands
Bash keeps track of the commands you execute in a history buffer, and allows you to recall previous commands by cycling through them with the Up and Down cursor keys. For even faster recall, “speed search” previously-executed commands by typing the first few letters of the command followed by the key combination Ctrl-R; bash will then scan the command history for matching commands and display them on the console. Type Ctrl-R repeatedly to cycle through the entire list of matching commands.
2. Use command aliases
If you always run a command with the same set of options, you can have bash create an alias for it. This alias will incorporate the required options, so that you don’t need to remember them or manually type them every time. For example, if you always run ls with the -l option to obtain a detailed directory listing, you can use this command:
bash> alias ls='ls -l'
To create an alias that automatically includes the -l option. Once this alias has been created, typing ls at the bash prompt will invoke the alias and produce the ls -l output.
You can obtain a list of available aliases by invoking alias without any arguments, and you can delete an alias with unalias.
3. Use filename auto-completion
Bash supports filename auto-completion at the command prompt. To use this feature, type the first few letters of the file name, followed by Tab. bash will scan the current directory, as well as all other directories in the search path, for matches to that name. If a single match is found, bash will automatically complete the filename for you. If multiple matches are found, you will be prompted to choose one.
Read the rest of this entry »
Recent Comments