I was doing some more poking around in the .bashrc file in my home folder, and I spotted these three lines.
if [ -f ~/.bash_aliases ]; then
What these lines do is look in my home folder for a file called .bash_aliases. If it is found, the file is opened and the contents are read in. Effectively it makes the contents of the .bash_aliases file appear to be part of the .bashrc file.
Because the .bashrc file is executed each time you open a terminal window, anything you put in the .bash_aliases file is executed as well. And as the name implies, the idea is that you put your personal alias definitions in the .bash_aliases file.
By default there is no .bash_aliases file, but you can create one and add some entries to it by typing:
The first line makes sure you are in your home folder, the second opens the gedit editor and tells it to open a file called .bash_aliases. If no such file exists, it is created. These are some lines from my .bash_aliases file.
alias hf=’history | grep $1′
alias pf=’ps -e | grep $1′
The first alias sets cls to clear the screen. It’s just faster to type cls than it is to type clear. Likewise the second line. It’s fewer keystrokes to hit h. instead of history.
The hf alias is a bit more interesting. I use the history option a lot. hf makes it a bit easier to locate the command you want. For instance, to see the files you have recently opened in gedit, you could type:
The result on my test machine is shown here. The commands that have gedit in them are listed with the gedit highlighted in red.
The pf alias does the same sort of thing, but with process names instead of command names. You can use it to list all of the processes that have a certain word in their name. In the example below I have used the pf alias twice, once to list all the processes that have gnome in their name and once to list all processes that have unity in their name.
Note that when you have typed your aliases into the bash_aliases file, you must save the file, and exit the terminal session, and open a new terminal window before the aliases become available for use.
Remember, because the .bash_aliases file is a dotfile (its name starts with a full stop), the .bash_aliases file will not be listed when you use the ls command.
To see dotfiles you have to use the the -a or -A parameters, or use the la system-provided alias.
If you go poking around in the .bashrc file, located in your home folder, you’ll see the following lines:
alias ll=’ls -alF’
alias la=’ls -A’
alias l=’ls -CF’
These provide some ready made aliases for you. Alisases take commonly used commands and provide abbreviations for you so that you don’t have to type the original command in again and again.
For example, if you type:
in a terminal window Ubuntu will treat it as though you had typed:
is the equivalent of having typed:
is the equivalent of having typed:
To see a description of what the various options for ls do, type:
You will see a display like this:
Use q to quit from the man session when you wish to return to the command prompt.
Whenever you open a terminal window a script file called .bashrc is run. This establishes certain settings within your terminal environment.
In your home folder, if you type:
You will see the contents of this file listed to the screen.
To stop the output whizzing past in a flash type the following:
cat .bashrc | less
This will allow the less program to handle the output. You can then scroll backwards and forwards through the contents of the file using the Home, End and Up Arrow and Down Arrow keys. Q will exit back to the prompt. This is a convenient way to examine text files safely – there is no danger of you accidently making changes to them.
Within the .bashrc file are some lines that look like this:
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
if you want to have a colour prompt in your terminal windows, in your home folder type:
This causes the gedit editor top open the file so you can make changes to it. Be Careful! Change the line that said:
to now say:
Save the file, and close gedit. Close the terminal window and open a new terminal window. I use keyboard shortcuts a lot, so I do this through:
You should now see a colour prompt.
It’s not life-changing perhaps, but it helps to visually distinguish the output from the shell prompt.