Take control of the command line
Setting Default Permissions
As you probably know, permissions define how a file or directory can be used. When you create a new file, it is automatically given a default set of permissions called the umask.
One way to summarize permissions is with three digits. From left to right, they are the permissions for the user account from which the file was created, for those in the same group as the creator, and for all others logged in. Apparently for no other reason than that the idea seemed good at the time, each digit is a sum of numbers in base 8 defining a permission. Read permission is 4, write permission 2, execute permission 1, and no permissions 0. This shorthand is called absolute mode, symbolic permissions, or octal permissions, depending on your preference.
Under this system, a file that everyone could read, write, and execute would have a permission of 777. By contrast, a file that the owner could read, write, and execute, and that nobody else could use at all, would have a permission of 700.
When you create a file and the system assigns the default set of permissions, the umask is defined in /etc/login.defs. However, you can set the umask for each account by adding the umask command followed by the permissions (e.g., umask 700) to .bashrc.
Customizing the Prompt
The command prompt is the recurring text that appears to the left of where you start typing in a command. If you're a new user, you might not have paid much attention to the prompt.
Nor do you absolutely need to these days. In the days before desktops became the norm, the prompt once held useful information that you might want at a glance, such as the current directory, date, and time. Nowadays, when you can get much of this information from the desktop, you might not care so much about the prompt.
Still, even today, you might find it handy to have basic information always visible, such as the current account and directory, even if you are almost always using a virtual terminal. For one thing, you never know when you will need to repair your system when you have no desktop available. Moreover, if you look at many distributions, you often find that the final character in the prompt tells you whether you are using a user or root account; user account prompts end in a dollar sign, whereas root account prompts end in a hash sign (#).
In fact, once you look, you might notice that different distributions have different prompts on the basis of what information they think users might want. For example, if I were working in the /usr/share directory on a computer called nanday, in Fedora, my default prompt would be [bruce@conure share] $, whereas in Debian, it would be bruce@nanday:/usr/share$. From this difference, you might correctly infer that Fedora's defaults assume that users stay largely in their home directories because the full path is not given, whereas Debian's defaults assume that their more advanced users might be anywhere in the system and prefer not to stop to use the pwd command to find out where they are.
In addition, you might want to shorten the prompt, especially if you are listing current paths but tend to have directories nested five or six deep. Alternatively, you might simply want to change the color of the prompt to make it more visible, to please your sense of aesthetics, or to provide a more striking distinction between the root and everyday accounts.
Whatever your reason, the best place to start if you want to change your prompt is by temporarily changing the PS1 prompt parameter. These changes will remain in effect until you either change them yet again or close your current virtual terminal. The next terminal you open will revert to the default prompt.
To begin, you want to view the current settings for PS1, the variable for the prompt, by entering the command echo $PS1. Likely, you will get a response that reads something like: [\u@\h \W]$, which is the reading I get for a machine with Fedora 10 installed. By comparing it with the Fedora prompt mentioned above, you can figure out what each entry in it means. Notice, though, the extra elements, such as the @ between the username (\u) and hostname (\h) and the space between the hostname and the current directory (\W).
You can change this prompt temporarily by referring to Table 1. I have not bothered with some options that are unlikely to be of interest to modern non-developers. If you are curious, you can easily find a complete list online with a quick search.
For instance, if I wanted just to display the current user account, I could make a temporary change by running PS1="\u $ " to produce the prompt bruce $ . Notice that the space after the dollar sign is not an error but was added deliberately so that my typing is separate from the prompt.
If I want to add color, I can change the color of the characters according to the formula:
"\e[x;ym\e[m "
In this formula, \e[ marks the start of the characters that the color applies to, \e[m marks the end, and x;ym is the color code (Table 2). The command to change the prompt to dark red would be:
PS1="\e[0;31m[\u@\h \W]\$ \e[m "
If you substitute a 1 for the 0, you get a lighter version of the same color.
Experiment with these temporary changes until you have the prompt you want. If you make a mistake, you can either use the arrow keys to find an entry in the command history from which you can reverse the mistake or simply close the window if you are working in a virtual terminal.
When you figure out the prompt formula that you want, open the .bashrc file for your account in a text editor and replace the existing formula with the one that you have devised. If you prefer, you can also use the export command: for example, export PS1="\e[0;31m[\u@\h \W]\$ \e[m ".


History Options
The Bash history is a list of previously used commands stored in .bash_history. If you continually type the same or similar commands, you can use the Up and Down arrow keys to scroll to the command you want to use.
The export command sets shell variables and is one way to customize the Bash history. Or, edit .bashrc directly. To set the number of commands stored in the history to 1,200, either enter on the command line or add to .bashrc:
export HISTFILESIZE=1200
Because .bash_history is a text file, it does not require much memory, so you have no reason not to use this setting to increase the default size of 500 entries. Of course, the larger the file, the more scrolling you have to do to find an older command, but you can always open .bash_history in a text editor and use its search function.
Another customization is to keep duplicate commands from being added to .bash_history. For this option, enter:
export HISTCONTROL=erasedups
This customization ensures that .bash_history contains only unique commands, but it might mean that the command you want requires extra scrolling, especially if you have just used a command that already appears well down the list.
« Previous 1 2 3 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

News
-
First Release Candidate for Linux Kernel 6.14 Now Available
Linus Torvalds has officially released the first release candidate for kernel 6.14 and it includes over 500,000 lines of modified code, making for a small release.
-
System76 Refreshes Meerkat Mini PC
If you're looking for a small form factor PC powered by Linux, System76 has exactly what you need in the Meerkat mini PC.
-
Gnome 48 Alpha Ready for Testing
The latest Gnome desktop alpha is now available with plenty of new features and improvements.
-
Wine 10 Includes Plenty to Excite Users
With its latest release, Wine has the usual crop of bug fixes and improvements, along with some exciting new features.
-
Linux Kernel 6.13 Offers Improvements for AMD/Apple Users
The latest Linux kernel is now available, and it includes plenty of improvements, especially for those who use AMD or Apple-based systems.
-
Gnome 48 Debuts New Audio Player
To date, the audio player found within the Gnome desktop has been meh at best, but with the upcoming release that all changes.
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.