UNIX / Linux Tutorial

Chapter 1

1.1 Introduction   | 1.2 Basic Concepts  |  1.2.1 Creating An Account    |   1.2.2 Logging In

1.2.3 Virtual Consoles   |   1.2.4 Shells And Commands   |    1.2.5 Logging Out

1.2.6 Changing Your Password   |   1.2.7 Files And Directories   |   1.2.8 The Directory Tree

1.2.9 The Current Working Directory

 

1.1 Introduction

If you’re new to Unix or Linux, you may be a bit intimidated by the size and apparent complexity of the system before you. This chapter does not go into great detail or cover advanced topics. Instead, I want you to hit the ground running.

I assume very little here about your background, except perhaps that you have some familiarity with personal computer systems and MS-DOS. However, even if you’re not an MS-DOS user, you should be able to understand everything here. At first glance, both Operating Systems (O/S) look a lot like MS-DOS--after all, parts of MS-DOS were modeled on the CP/M Operating System (O/S), which in turn was modeled from Unix. However, only the most superficial features of Unix and Linux resemble MS-DOS. Even if you’re completely new to the PC world, this tutorial should help.

Before we begin: Don’t be afraid to experiment. The system won’t bite you! You can’t destroy anything by working on the system. Both Networking Operating Systems (NOS) have built-in security features to prevent "normal" users from damaging files that are essential to the system. Even so, the worst thing that can happen is that you may delete some or all of your files and you’ll have to re-install the system. So, at this point, you have nothing to lose.

e.g. From now on, I will refer to both Networking Operating Systems (NOS)as "Linux" unless referred to otherwise. The majority of commands listed or referred to, in this tutorial reference, are interchangeable with either systems.

1.2 Basic  Concepts

Linux is a multitasking, multi-user Operating System, which means that many people can run many different applications on one computer at the same time. This differs from MS-DOS, where only one person can use the system at any one time. Under Linux, to identify yourself to the system, you must log in, which entails entails entering you login name (the name the system uses to identify you), and entering your password, which is your personal key for logging in to your account. Because only you know your password, no one else can log into the system under your user name.

On traditional Unix Systems, the System Administrator assigns you a user name and an initial password when you are given an account on the system. However, with Linux, if you’re the system administrator, you must set up your own account before you can log in. For the following discussions, we’ll use the imaginary user name, "patrick".

In addition, each system has a host name assigned to it. It is this host name that gives your machine a name. The host name is used to identify individual machines on a network, but even if your machine isn’t networked, it should have a host name. For our examples below, the system’s host name is "house".

1.2.1 Creating An Account

Before you can use a newly installed Linux system, you must set a user account for yourself. It’s usually not a good idea to use the root account for normal use; you should reserve the root account for running privileged commands and for maintaining the system as discussed below.

In order to create an account for yourself, log in as root and use the useradd or adduser command. 

1.2.2 Logging In

At login time, you’ll see a prompt resembling the following:

house login:

Enter your user name and press the Enter key. Our hero, patrick ,would type:

house login: patrick

password:

Next, enter your password. The characters you enter won’t be echoed to the screen, so type carefully. If you mistype your password, you’ll see the message:

login incorrect.

and you’ll have to try again.

Once you have correctly entered the user name and password, you are officially logged into the system and are free to roam.

1.2.3 Virtual Consoles

The System’s console is the monitor and keyboard connected directly to the system. (Because Linux is a multi-user Operating System, you may have other terminals connected to serial ports on your system, but these would not be the console.)

Linux, like some other version of Unix, provides access to virtual consoles or (VC’s), that let you have more than one login session on the console at one time.

To demonstrate this, login to your system. Next, press Alt-F2. You should see the login: prompt again. You’re looking at the second virtual console. To switch back to the first VC, press Alt-F1. Voila!!! You’re back to your first login session.

A newly-installed Linux System probably lets you access only the first half-dozen or so VC’s, by pressing Alt-F1 through Alt-F4, or however many VC’s are configured on your System. It is possible to enable up to 12 VCs--one for each function key on your keyboard. As you can see, use of VCs can come in handy, because you can work in several different sessions at the same time.

While the use of VCs is somewhat limiting (after all, you can look at only one VC at a time), it should give you a feel for the multi-user capabilities of Linux. While you’re working on the first VC, you can switch over to the second VC and work on something else.

1.2.4 Shells And Commands

For most of your exploration in the world of Linux, you will talk to the System through a shell, a program that takes the commands you type and translates them into instructions to the Operating System. This can be compared to the COMMAND.COM program under MS-DOS, which does essentially the same thing. A Shell is just one interface to Linux. There are many possible interfaces--like the X Window System, which lets you run commands by sing the mouse and keyboard.

As soon as you login, the System starts the shell and you can begin entering commands. Here’s a quick example. Patrick logs in and is waiting at the shell prompt:

house login: patrick

password: patrick’s password

Welcome to the House!

/home/patrick#

The last line of this text is the shell’s prompt, indicating that it’s ready to take commands. (More on what the prompt itself means later). Let’s try telling the system to do something interesting:

/home/patrick# make love

make: ***No way to make target ‘love’.Stop.

/home/patrick#

Well, as it turns out, make is the name of an actual program on the System and the shell executed this program when given the command. (Unfortunately, the System was being unfriendly).

This brings us to the burning question: What is a command? What happens when you type "make love"? The first word on the command line, "make", is the name of the command to be executed. Everything else on the command line is taken as arguments to this command. Example:

/home/patrick# cp foo bar

The name of this command is "cp" and the arguments are "foo" and "bar".

When you enter a command, the shell does several things. First, it checks the command to see if it is internal to the shell. (That is a command which the shell knows how to execute itself. There are a number of these commands and we will go into them later). The shell also checks to see if the command is an alias, or substitute name, for another command. If neither of these conditions apply, the shell looks for a program, on disk, having the specified name. If successful, the shell runs the program, sending the arguments specified on the command line.

In our example, the shell looks for a program called make and runs it with the argument love. Make is a program often used to compile large programs and takes as arguments the name of a "target" to compile. In the case of "make love", we instructed make to compile the target love. Because make can’t find a target by this name, it fails with a humorous error message and returns us to the shell prompt.

What happens if we type a command to a shell and the shell can’t find a program having the specified name? Well, we can try the following:

/home/patrick# eat dirt

eat: command not found

/home/patrick#

Quite simply, if the shell can’t find a program having the name given on the command line (here,"eat"), it prints an error message. You’ll often see this error message if you mistype a command (for example, if you had typed "mkae love"instead of "make love")..

1.2.5 Logging Out

Before we delve much further, we should tell you how to log out of the System. At the shell prompt, use the command:

/home/patrick# exit

to log out. There are other ways of logging out, but this is the most foolproof one for now.

1.2.6 changing Your Password

You should also know how to change your password. The command passwd prompts you for your old password and a new password. It also asks you to re-enter the new password for validation. Be careful not to forget your password--if you do, you will have to ask the System Administrator to reset it for you. (If you are the System Administrator, read on.)

1.2.7 Files And Directories

Under most Operating Systems (including Linux), there is the concept of a file, which is just a bundle of information given a name (called a filename). Examples of files might be your history term paper, an e-mail message, or an actual program that can be executed. Essentially, anything saved on disk is saved in an individual file.

Files are identified by their file names. For example, you could name your history paper with the file name history-paper. These names usually identify the file and its contents in some form that is meaningful to you. There is no standard format for file names as there is under MS-DOS and some other Operating Systems; in general a file name can contain any character (except the / character -- see the discussion of pat names, below) and is limited to 256 characters in length.

With the concept of files comes the concept of directories. A directory is a collection of files. You can think of it as a folder that contains many different files. Directories are given names, with which you can identify them. Furthermore, directories are maintained in a tree-like structure; that is, directories may contain other directories.

Consequently, you can refer to a file by its path name, which is made up of the filename, preceded by the name of the directory containing the file. For example, let’s say that Patrick has a directory called papers, which contains three files: history-final, english-lit and masters-thesis. Each of these three files contains information for three of Patrick's ongoing projects. To refer to the english-lit file, Patrick can specify the file’s pathname, as in:

papers/english-lit

As you can see, the directory and filename are separated by a single slash(/). For this reason, filenames themselves cannot contain the / character. MS-DOS users will find this convention familiar, although in the MS-DOS world the (\)backslash is used instead.

As mentioned, directories can be nested within each other as well. For example, let’s say that there is another directory within papers, called notes. The notes directory cheat-sheet is:

papers/notes/cheat-sheet

Therefore, a path name is really like a path to the file. The directory that contains a given subdirectory is known as the parent directory. Here, the directory papers is the parent of the notes directory.

1.2.8 The Directory Tree

Most Linux Systems use a standard layout for files so that system resources and programs can be easily located. This layout forms a directory tree, which starts at the "/" directory, also known as the "root directory". Directly underneath / are important subdirectories:

/bin,/etc,/dev and /usr, among others. These directories in turn contain other directories which contain System configuration files, programs and so on.

In particular, each user has a home directory, which is the directory set aside for that user to store their files. In the examples above, all of Patrick’s files (like cheat-sheet and history-final) are contained in Patrick’s home directory. Usually, user home directories are contained under /home and are named for the user owning that directory.

Patrick’s home directory is: /home/patrick

1.2.9 The Current Working Directory

At any moment, commands that you enter are assumed to be relative to your current working directory. You can think of your working directory as the directory in which you are currently "located". When you first login, your working directory is set to your home directory--/home/patrick, in our case. Whenever you refer to a file, you may refer to it in relationship to your current working directory, rather than specifying the full pathname of the file.

Here’s an example. Patrick has the directory papers and papers contains the file history-final. If Patrick wants to look at this file, he can use the command:

/home/patrick# more/home/patrick/papers/history-final

The more command simply displays a file, one screen at a time. However, because Patrick’s current working directory is/home/patrick, he can instead refer to the file relative to his current location by using the command:

/home/patrick# more papers/history-final

If you begin a filename (like papers/final) with a character other than /, you’re referring to the file in terms relative to your current working directory. This is known as a relative path name.

On the other hand, if you begin a file name with a /, the system interprets this as a full path name--that is, a path name that includes the entire path to the file, starting from the root directory, /. this is known as an absolute path name.

HOME

1.1 Introduction   1.2.10 Referring To Home Directories   1.3.4  Copying Files

1.6 Exploring The File System   1.8   Wildcards   1.9.3 Pipes   1.10.3 Permissions Dependencies

1.12.4  Stopping And Restarting Jobs   1.13.3 Inserting Text   1.13.9 Including Other Files

1.14.3 Shell Initialization Scripts   System Administration   2.3.1 The /etc/imitate file

2.4 Managing File Systems   2.6 Managing Users  2.6.5 Groups   2.7.2 gzip and compress

2.8.3 Making Backups To Tape Devices   2.9.1 Upgrading The Kernel   

2.9.3 Installing A Device Driver Module

BOOK: LINUX QUICK COMMAND REFERENCE

http://personal.atl.bellsouth.net/~psadler

© copyright KnowledgeWorks, Inc. (2001)