Saturday, December 6, 2008

Master the Linux bash command line with these 10 shortcuts

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.

[1] Easily recall previous commands
"speed search" previously-executed commands by typing the first few letters of the command followed by the key combination Ctrl-R.

[2] Use command aliases
You can obtain a list of available aliases by invoking alias without any argument, and you can delete an alias with unalias.

[3] Use filename auto-completion
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.

[4] Use key shortcuts to efficiently edit the command line
Ctrl-A/E: moves the cursor to the beginning/end of the command line.
Ctrl-W/K: deletes the word immediately before/after the cursor.

[5] Get automatic notification of new mail
MAILPATH='/var/spool/mail/USERNAME'
export MAILPATH

[6] Run tasks in the background
To run a task in the background, add an ampersand(&) to the end of its command line.

[7] Quickly jump to frequently-used directories
$PATH variables lists bash's "search path" - the directories it will search when it can't find the requested file in the current directory. However, bash also supports the $CDPATH variable, which lists the directories the cd command will look in when attempting to change directories.

[8] Perform calculations
echo $((16/2))
type in the artithmetic expression you wish to evaluate at the prompt within double parentheses.

[9] Customize the shell prompt
PS1='\u@\h:\w \@> '
export PS1
This will display the name of the current logged-in user, the host name, the current working directory and the current time at the shell prompt.

[10] Get context-specific help
help alias

Reference:
Master the Linux shell command line with these 10 shortcuts

No comments: