http://www.extremetech.com/article2/0,1558,10398,00.asp

Tips for New Linux Users, Part II

Text Editors File Managers Revisited / Editing Package Management Files More Configuration File Editing with Text Editors Shall We See Some Shell Sessions? Notes on Documentation Access Notes on Documentation Access (cont'd) Accounts & Passwd File Editing The adduser Command

In Part I, we covered KDE's Konqueror, Gnome's Nautilus, Linux directory structure, tarballs, and mime types, among other things, and we'll now look at Linux Text Editors

Text Editors Every now and then, you will find it necessary to change a script, configuration, or text file. To do this, you will need a text editor. There are many text editors available in every Linux system. Each Linux distribution has its preferred or default text editor. Some are graphical or semi-graphical, and some are accessed through a terminal and depend totally on key commands and command lines to function. The advantage of non-graphical editors is that they can work easily through a remote connection. Telnet connections are text-only and work in concert with such editors.

File Managers Revisited / Editing Package Management Files

In Part I, we mentioned file managers such as Nautilus, KDE's Konqueror (in super-user mode), GMC (Gnome Midnight Commander), Xftree, and others. These file managers are designed to present the user with a visual overview of the directory structure of the system, presenting all files, folders, applications, and graphics in a hierarchical "tree" to facilitate the user's access. They work pretty much like the file manager in Microsoft Windows. They all have the same drag and drop and/or the right-click menu to select options for the handling of files and folders. Debian includes an "APT sources file" (see Debian's Advanced Packaging Tool documentation) which lists the sources or mirror locations where packages can be downloaded. The maneuver I am about to show you may also be accomplished by issuing commands from a terminal. I have a tendency to forget exact file locations, and specific command line syntaxes, so I prefer to do this visually. Files are easier to find this way and I do not need a reference book at my side for commands I seldom use. What I will do is add a mirror location to the list so that when I ask my system to seek an update or a new application, it will have one more place to search for it. In Debian the "list" or file in question is located in /etc/apt/sources.list.

In KDE, using the File Manager (located under System) in super-user mode, a simple click will open a text file with the embedded text viewer, but you will need to open it with a true text editor to actually perform edits. Simply find the file, right click on it, click on "open with" (similar to the process you might under Windows), and choose between the text editors with which you are presented, or simply scroll until you find one to your liking. Kedit will suffice, because we won't be editing and managing source code here. We only want to add a mirror to a list. The same principle applies to modifying configuration files. So, for this simple task, you only need to pick an editor sufficient for the job at hand unless you have time and want to learn the ins and outs of other editors such as Emacs, Xemacs, Vi, and Vim, to name only a few. All those editors include very extensive help files.

In the Nautilus and the GMC file managers, the process is much the same, but remember that the editing of certain files requires root privileges, so you will either have to log into a root session, or work from a terminal after logging in as root. Once again, I cannot stress enough the importance of taking your time so as not to delete or change something by accident when accessing configuration files as a root user.

Adding a Security Mirror click on image for full view javascript:OpenImageWindow('http://www.extremetech.com/image_popup/0,1694,iid=12646,00.asp', '640', '600')

As you can see, I added a security mirror to the list. Now when I update my system, that site will be automatically scanned for updates related to my system.

More Configuration File Editing with Text Editors

Of course the APT sources file isn't the only type of configuration file that may be modified with a text editor. Just to give you an idea of the power of editing configuration files, let's choose a Gnome file first -one that won't ruin your system if you or I make a mistake. There is a file in /usr/share/gnome/apps called ".order" that determines the order of items as they appear in the Gnome menu system. To modify anything concerning the menu system in Gnome, you must be either logged in as root in a terminal, or logged into a root session.

Look at the screenshot below and see the list as compared to the Main Menu. I moved Mail from the bottom to the top of the menu list. After saving my modifications, it appears in the place I have chosen in the order of presentation. You may also use this method to arrange submenus, change wordings, and add your own comments. Such modifications apply globally to all users, because that's the way Gnome handles menus. In KDE, each user is responsible for menu changes, usually through the GUI provided in the KDE Control Center. Much of this work may be done through the Menu Editor GUI provided with Gnome and via the Gnome Control Center, but not all of it.

Editing Configuration Files click on image for full view javascript:OpenImageWindow('http://www.extremetech.com/image_popup/0,1694,iid=12647,00.asp', '640', '600')

For more information on the Gnome and the KDE menu systems and how to modify them, I highly recommend this article by David D. Scribner, "Get Your KDE and GNOME Menus in Line" and for information concerning both the Gnome and KDE Desktops, including the location of all the configuration files, "Get your Default KDE and GNOME Desktops in Line" by the same author is the best document I have seen on the subject.

You will have many occasions to use a simple or advanced text editor. You will often receive suggestions and recommendations concerning the modification of configurations, the addition of font lists, the removal of unwanted functions, and many other tweaks. All you need to know is the location of the file in question and the text to add to or erase from the content.

If you plan to build a large business network and plan much remote interaction to other local or distant stations, or if you plan to do much coding, and kernel tweaking, you would likely opt for the non-graphical editors and follow the necessary period of apprenticeship. If you just want to be able to tweak and improve your system bit-by-bit, and fine tune your distribution to your needs, graphical editors usually suffice, but the other editors mentioned should also be considered to increase your ability to control all eventualities.

A Wee Note-- The prior information is by no means intended to provide a complete tutorial on the subject of text editors in Linux. It is only meant to give the new user a taste of the possibilities and the power of their use. Most graphical, and especially non-graphical editors, have an included help file, easily accessed through the interface of each.

Shall We See Some Shell Sessions?

To perform tasks not provided by the GUI, or that a GUI simply cannot handle because of its design, the shell provides a powerful task-oriented tool. The Bourne Again Shell, or Bash, is the command interpreter used by GNU (the Free Software's freely distributable answer to Unix). Fully compatible with the Bourne shell, the command interpreter for Unix also known as sh. (/bin.sh is linked to /bin/bash), and if that's Greek to you, don't worry about it. It isn't clear to anyone! This is the most commonly used shell among Linux users. It incorporates features from both the Korn and the C shells, which we won't get into here.

Another shell called ash (named as such because it is very lightweight), is often used as the default shell on installation root floppy disks, but it lacks too many features to be effective in a full blown distribution and is not as useful and ubiquitous as bash.

A shell reads, interprets, and carries out commands issued in a terminal session. Users of Red Hat who open a terminal to type "up2date" after the root prompt to update their system or register with the Red Hat Network for the first time, are using a shell command to do so. When you type apropos, info, or man followed by a command initial or program name for which you sought information or access to a manual, you were using the shell. (More on documentation access below).

The uses and number of commands handled by the shell is a vast subject, but I will give a few rather common examples: When you open a terminal, or more exactly a shell session, you will be presented with one of three signs, called prompts: a $ sign, a % sign, or a # sign (called a pound or hash sign, and signifies the root prompt). When you type "su" then hit , followed by your password, you are issuing a command to be interpreted by the shell. Commands have two syntax forms for indicating options on the command line. The most common form is a single dash "-", followed by a single letter or a number for each one of the options. Whole word options are usually preceded by a double dash "—". For example: in Debian, typing dselect –expert after the root prompt "#" will place you in the dselect program in expert mode.

Running dselect click on image for full view javascript:OpenImageWindow('http://www.extremetech.com/image_popup/0,1694,iid=12648,00.asp', '640', '600') Output from dselect click on image for full view javascript:OpenImageWindow('http://www.extremetech.com/image_popup/0,1694,iid=12649,00.asp', '640', '600')

When you log in to a Linux session at startup, you are using the shell. The shell searches for certain files in the home directory that contain prewritten commands that define environmental variables or aliases. These collections of commands are called scripts, which are executed in a batch, rather than entered in the command line terminal one by one. Bash has two files that it reads at startup: .bash_profile and .bashrc. Below is my .bashrc file, a line or two of which I wrote myself using a text editor (remember?). I wouldn't try that at home if I were you just yet unless you are following specific and detailed instructions related to your distribution of Linux.

Editing .bashrc click on image for full view javascript:OpenImageWindow('http://www.extremetech.com/image_popup/0,1694,iid=12650,00.asp', '640', '600')

Other shells The C shell, called csh, was developed by Bill Joy as part of Berkeley UNIX. Created to overcome the limitations of the older Bourne shell, not to be confused with the Bourne Again Shell, it uses a syntax that resembles the C programming language. Many distros include csh as well as tcsh, an enhanced version of the same. In csh, a "set" or "unset" command defines variables and the word set or unset must be typed: % set workdir /home/kaos/work and % unset workdir. The startup scripts in the C shell are a lot like those of bash. A script called .login is executed at the time of login, and a script called cshrc is executed whenever a csh session is started.

Other shells include the korn shell, or ksh, and zsh, a shell with numerous features not found in others and quite handy for certain scripting, psh, a perl shell, and ash, which uses a language common to both interactive and non-interactive use. To find out if you have any of these shells installed in your distro, simply type info ksh, zsh, psh, or ash in a terminal and see if some info comes up. If it does, you may follow up with man 'shellname' and apropos 'shellname' to find out more.

Notes on Documentation Access

There is much documentation already installed in most Linux distributions. For example, you may open a terminal and type "man bash" for a manual on the Bourne Again Shell.

Manpage for Bash from Terminal click on image for full view javascript:OpenImageWindow('http://www.extremetech.com/image_popup/0,1694,iid=12651,00.asp', '640', '600')

Some distros provide easier to read interfaces for the internal manpages provided by most distros such as TkMan and CoolMan. Here lies the problem. How is the relatively new user to know just what to type in a terminal to have access to manual pages? Surprisingly, this information is often omitted from the little printed user manuals provided with boxed sets of Linux distributions. Many distros direct the user only to their distribution-specific help system. The fact is, that there is a wealth if documentation for each application provided with each distro.

Manpage for Bash on TkMan click on image for full view javascript:OpenImageWindow('http://www.extremetech.com/image_popup/0,1694,iid=12652,00.asp', '640', '600') Manpage for Bash on Coolman click on image for full view javascript:OpenImageWindow('http://www.extremetech.com/image_popup/0,1694,iid=12653,00.asp', '640', '600')

The user often needs quick access to a bit of information concerning a process or an application. It is nice to be able to do this "on the fly" and with a minimum of system resources--very handy when you already have one too many applications running. This is where manual and info pages come in the picture. Like Unix, Linux is a self-documenting system. Manuals pages for X Window and for Linux commands are found in the /usr/share/man, the /usr/local/man, and the /usr/X11R6/man directories. These are not usually accessed by direct contact from within each directory. For example, to read the remove directory or "rm" command's manual page, open a terminal and type "man rm" after the prompt symbolized by $. The following should appear in your terminal window...

Manpage for RM click on image for full view javascript:OpenImageWindow('http://www.extremetech.com/image_popup/0,1694,iid=12654,00.asp', '640', '600')

Notes on Documentation Access (cont'd)

apropos... When you do not know what manuals to consult, you can use the apropos command to find a list of commands related to the subject of your query. The apropos command initiates a search then displays installed commands names based on keywords associated with the commands. This is useful when you are searching for a command when you are not quite sure which one to use or the syntax involved. Let's say that you would like to take a look at all the commands concerning directories, their movement, their deletion, their creation, etc. Open a terminal and type "apropos directories" after the $ prompt:

$ apropos directories

Output from 'apropos directories' click on image for full view javascript:OpenImageWindow('http://www.extremetech.com/image_popup/0,1694,iid=12655,00.asp', '640', '600')

info The info program provides information about specific commands. It is a hypertext tool for reading documentation, which is controlled by the keyboard. For a list of commands related to info, simply type "info info" in a terminal.

Info Introduction click on image for full view javascript:OpenImageWindow('http://www.extremetech.com/image_popup/0,1694,iid=12656,00.asp', '640', '600')

Other Internal Documentation Sources Documents are also stored in /usr/share/doc. Most of them are zipped, or in txt or html format. There are two documents here of particular interest to new users and old veterans alike. They are in HTML format and are in /usr/share/doc/HOWTO/en-html and /usr/share/doc/FAQ/Linux-FAQ. To access the index in each, find the "index.html" file and open it. The index within consists of hyperlinks to the subject matter. While you are in this directory, you may want to create a desktop shortcut for the index, after which you will have access to the entire manual.

Internal Documentation click on image for full view javascript:OpenImageWindow('http://www.extremetech.com/image_popup/0,1694,iid=12657,00.asp', '640', '600')

Accounts & Passwd File Editing

If you plan to let several users use your workstation and you wish each to have a separate account that does not include administrative privileges, you will need to set up individual user accounts. The passwd file in /etc/passwd will contain most of the account information for each user. When a user logs in, this file will be referenced to check the password, the default shell, and the home directory path for the particular account. Other information may also be contained in the passwd file, such as the user's full name and address, and other information that may be required by the administrator.

This file may be modified with your favorite text editor. All such editing must, of course, be done by the administrator or root. All you potential crackers out there pay attention. Passwords are "shadowed" or encrypted. The following format is used to interpret each line in the file:

user name : encrypted password : user ID number : group ID number : personal data, comments

and/or

descriptions : default account path : default shell

When you edit this file, leave the password area blank and assign a password to the account after you have completed the editing of the file. The command to set the password is passwd, followed by the name of the new account. Later, when you become more familiar with processes and accounts, you may wish to create an account for a process as opposed to an actual user. No one will ever log into such an account, because it will belong to a process and not a person. To prevent user access to the system, type /bin/false for the shell instead of /bin/sh or /bin/bash. This will prevent a shell from activating at log in and the user will have no access or control over the process.

The adduser Command

Now that you know how to use a terminal and a bit about shells, you will be able to add a user account from the command line. The syntax is as follows:

adduser [options] user [group]. You may use this tool with only a user name. You mad add options to modify default information. The location of the adduser file is: /etc/adduser.conf. If you plan to host many users, this is handy to know.

Here is how the adduser process looks when executing:

$ adduser nerdbird Adding user nerdbird.. Adding new group nerdbird (1004). Adding new user nerdbird (1004) with group nerdbird. Creating home directory /home/nerdbird. Copying files from /etc/skel Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for nerdbird Enter the new value, or press return for the default Full Name [ ] : linuxophilius nerdbird Room Number [ ] : 123456789 Work Phone [ ] : 000-0000 Home Phone [ ] : 000-0000 Other [ ] : 000-0000 Is this information correct? [y/n] y

The reference information is optional. To skip it, simply type <enter>. During this process, you will be asked for a password for the account. Then you must confirm the password by retyping it. If the passwords do not match, all the files and the directories that were created in the process up to that moment are removed. This may explain some Linux installation difficulties concerning accounts and passwords.

The /etc/group file contains group information that may apply to an individual user or many users. Each account belongs to a minimum of one group. The same name is often used in both the passwd and the group files. Colons are used to separate values in the same way as in the passwd file. Here's the syntax: groupname:password:group ID number:user1:,user2, (etc...).

Groups also have passwords. The -g (for group) option with the passwd command is used to set group passwords. Each member of a group has access to the group's common files. You can add a member to a group simply by adding the person's name to the end of the group name line. Remember that each name must be separated by a comma. Once again, this is a perfect reason to use your favorite text editor. I hope this little intro to shells wasn't too light or too heavy. It certainly wasn't as thorough as a manual on the general subject, but I will be examining the use of Shell Scripts as we need them as related to other subjects in my following articles. And that ends Part II of our Tips for New Linux Users series.

Back to Sitemap Index