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
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs