Tuesday, June 13, 2006

Getting into the shell

One of the components of Linux that many Windows users might not be ready for is the shell. The shell, as you might recall from an earlier column, is the layer of the operating system that fits between the desktop and the kernel. It allows you to directly interact with the various components of your computer without going through the graphical interface.

Of course, there are several graphical interfaces, or desktops, available for Linux -- KDE and Gnome are chief among them. These desktops allow you to accomplish even very complex tasks pretty easily. However, there is no easier way to get a lot accomplished quickly than by using the shell -- once you get used to it.

Windows, of course, used to have a real shell -- the DOS window. In the DOS window, you could easily view, load, copy, and erase files, format hard drives, and even reconfigure parts of the computer. As Windows progressed through 98 to XP, DOS became less and less powerful. Now, you have to jump through hoops to get to a real DOS window from Windows.

With Linux, however, the "DOS" window reappears, in the form of a "console", or shell window. From the shell, you can do all of the tasks you once c0uld perform from the DOS window. Of course, you can still use the graphical interface to do many of these tasks, but the console window can let you do it faster. You can generally find an icon to open up a console window on one of the menus within your desktop environment.

Users accustomed to DOS have some adjustments to make, though. Many of the commands ("dir", "copy", etc.) have new equivalents in Linux ("ls", "cp", etc.). Rather than catalog all of the shell commands here, I'll run through some of the most helpful:

ls -- list files
cp -- copy file(s)
mv -- move file(s); use this instead of "rename"
rm -- remove file(s)
tar -- compress or decompress files
man [command] -- display help file associated with [command]
more -- display contents of a file one screen at a time

One of the handiest features of the shell is the wildcard. If you want to list all the files in a directory that start with "amy", for example, you can type "ls amy*". Try that with your desktop. There are plenty of resources available to help you learn to use wildcards to your advantage. They are one of the best reasons to jump into a console from time to time.

You can also run most software from the shell, by typing the name of the program. For example, to run the Email program "Evolution", you can type

evolution

from the console prompt. When you do this, though, your console will be completely occupied with running the software until you exit it. You may want to run it as a background task -- allowing the console to do other things (including taking other commands from you) while it runs it. Add an ampersand (&) to the end of the command.

evolution &

The "Superuser"
From Windows, you'll recall the concept of having different users logging into the same computer, each having access to private (user-only) and shared files. Linux continues this concept -- you can add users ad infinitum. One user always remains the same -- the root user. This "user" has access to every file on the machine.

As a regular user, when you log into the desktop or use the shell, you'll only have access to your own files and any files that other users are sharing. Even if you're the only user on your computer, the operating system will automatically limit your ability to get to system and protected files. This is for your own protection, so you don't accidentally disrupt things that will make your operating system not work anymore. In order to access, change, or delete system files, you will have to log in as the root.

This is not as much of an issue with the graphical interface, because you should never log into the desktop as the root user. Really. We mean it. The root restrictions are the most powerful protection your computer has against viruses and against your own bad behavior. If you log into the desktop as root, both of these protections are gone. When you're logged into the desktop as a regular user, you (and any virus you may contract) can only destroy your personal files, but the system will live on no matter what.

There are reasons to log into the shell as the root user, though. If you need to look at or copy files in the protected area of the system, which you might from time to time, you'll need to log in as root to do so. You'll also need to log in as root to install software or reconfigure your system.

Be very careful, though. You can make your system completely unusable by deleting even one critical file. Don't even think about using wildcards to delete multiple protected files unless you really know what you're doing -- this is a recipe for disaster. In general, until you know what's what, you should not log in as root unless people who know what they're doing tell you to.

To log in as the root user from the shell, type

su

from the command prompt. You will then be asked for the "root password" you created when you installed the system. When the prompt reappears, you will have access to every file on your system. Only this window, however, and any program you run from this window, will have root access. On your desktop, you'll still be logged in as yourself, a regular user. You can then go about your business. When you're done, you can close this window, and the root access will disappear. You can also type

su [username]

to log back in as yourself. It's probably safer, though, to simply close out the window.

Once you get comfortable with the shell, you'll probably find yourself popping in and out of it to perform certain tasks, rather than spending lots of time working within it. But it's handy when you need it.

Regards.


0 Comments:

Post a Comment

<< Home