Setting Up the Environment
Unix and Linux are very customizable systems. You can set the environment (settings and variables that define how the shell behaves) to your liking in a number of ways. If there is something that you find yourself repeatedly setting or changing, it is usually possible to have that automatically done for you by the system. Here some of the most useful are explored.
The Shell Profile
One of the main places for putting your personalized tweaks is the ~/.profile ($HOME/.profile) file. When a new interactive shell is started, /etc/profile, followed by /etc/bash.bashrc (if a bash shell), ~/.profile, and finally ~/.bashrc are executed in that order. ~/.profile is read by all shells so it is best to put generic settings in there, and then bash-specific settings in ~/.bashrc. You can set variables and aliases here, and even run commands if you want to. Because the local (user-specific) versions of these files all reside in the home directory and begin with a period (.) so that a regular ls does not list them, they are often referred to as “dotfiles.” There are many examples of dotfiles around the net; http://dotfiles.org/ is one useful repository.
Environment Variables
There are many environment variables that change the way the system works. You can set these interactively, or more usefully in your ~/.bashrc file.
PS1 Prompt
PS1 is the basic shell prompt; you can customize this. The default for bash is \s-\v\$, or “shell-version-dollar” — for example, bash-4.1$ ...
Get Shell Scripting: Expert Recipes for Linux, Bash, and More now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.