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
-
New Slimbook EVO with Raw AMD Ryzen Power
If you're looking for serious power in a 14" ultrabook that is powered by Linux, Slimbook has just the thing for you.
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.