LINUX
COMMANDS
Contents | Previous | Next
Customising your shell
Three files allow you to customise the shell for each user
account:
| File |
Description |
| ~/.bash_logout |
Commands to be run when you log-out. |
| ~/.bash_profile |
Things to be done when you log-in. Notably, the setting
of environment variables (especially PATH). |
| ~/.bashrc |
Called by ~/.bash_profile to set aliases. |
Customising your prompt
To customise your prompt, you need to change the PS1 (primary
prompt string) environment variable.
- 1 -
Enter:
vi ~/.bash_profile
- 2 -
To the end of this file add something like:
PS1='Enter command: '
- 3 -
Rather than log-out and log-in to activate the change,
just enter:
. .bash_profile
Note:
In a terminal window, the above won't be made permanent
until you logout.
Character sequences
For your shell-prompt to be more informative, include any
of the following character sequences:
| Sequence |
Displays |
Example output |
| \d |
Date. |
"Thu Dec 20" |
| \h |
First part of hostname. |
"localhost" |
| \H |
Hostname. |
"localhost.localdomain" |
| \j |
Number of jobs currently managed by shell. |
"1" |
| \l |
Basename of shell's terminal device name. |
"tty2" (equivalent in X: "2") |
| \n |
Newline character. |
|
| \s |
Name of shell. |
"bash" |
| \v |
Shell version. |
"2.05" |
| \V |
Shell version, plus patchlevel. |
"2.05.8" |
| \t |
Time, in 24-hour HH:MM:SS format. |
"14:39:12" |
| \T |
Time, in 12-hour HH:MM:SS format. |
"02:39:12" |
| \@ |
Time, in 12-hour am/pm format. |
"02:39pm" |
| \u |
Username. |
"john" |
| \w |
Current working directory. |
"~/mywork" |
| \W |
Current working directory, basename only. |
"mywork" |
| \! |
History number of this command. |
"1033" |
| \$ |
"#" if root user, otherwise, "$". |
"$" |
| \\ |
Backslash character. |
"\" |
Creating aliases
An alias is when you enter something and it means something
else. For example:
- 1 -
Enter:
vi ~/.bashrc
- 2 -
Add the following lines to the file:
alias x=startx
alias df='df -h'
alias cls='clear; ls'
Here entering x at the shell prompt will be interpreted
as startx, entering df will be interpreted
as df -h, and entering cls will be interpreted
as clear and then ls.
- 3 -
Rather than log-out and log-in to activate the change,
just enter:
. .bashrc
Note:
In a terminal window, the above won't be made permanent
until you logout.
Contents | Previous
| Next