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
-
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
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.
-
DebConf24 to be Held in South Korea
Busan will be the location of the latest DebConf running July 28 through August 4