|
Before we begin, it is important to know that all file and command names on a Linux system are case-sensitive (unlike operating systems such as MS-DOS). For example, the command make is very different from Make or MAKE . The same is true for file and directory names.
3.1 Moving around.
Now that you can log in, and you know how to refer to files using pathnames, how can you change your current working directory, to make life easier?
The command for moving around in the directory structure is cd , which is short for ``change directory''. Many often-used Linux commands are two or three letters. The usage of the cd command is

where directory is the name of the directory which you wish to become the current working directory.
As mentioned earlier, when you log in, you begin in your home directory. If Larry wanted to switch to the papers subdirectory, he'd use the command

As you can see, Larry's prompt changes to reflect his current working directory (so he knows where he is). Now that he's in the papers directory, he can look at his history final with the command
Now, Larry is stuck in the papers subdirectory. To move back up to the next higher (or parent) directory, use the command

(Note the space between the `` cd '' and the `` .. ''.) Every directory has an entry named `` .. '' which refers to the parent directory. Similarly, every directory has an entry named `` . '' which refers to itself. Therefore, the command

gets us nowhere.
You can also use absolute pathnames with the cd command. To cd into Karl's home directory, we can use the command

Also, using cd with no argument will return you to your own home directory.

3.2 Looking at the contents of directories
Now that you know how to move around directories, you might think, ``So what?'' Moving around directories is fairly useless by itself, so let's introduce a new command, ls . The ls command displays a listing of files and directories, by default from your current directory. For example:

Here we can see that Larry has three entries in his current directory: Mail , letters , and papers . This doesn't tell us much--are these directories or files? We can use the -F option of the ls command to get more detailed information.

From the / appended to each filename, we know that these three entries are in fact subdirectories.
Using ls -F may also append `` * '' to the end of a filename in the resulting list which would indicate that the file is an executable , or a program which can be run. If nothing is appended to the filename using ls -F , the file is a ``plain old file'', that is, it's neither a directory nor an executable.
In general, each UNIX command may take a number of options in addition to other arguments. These options usually begin with a `` - '', as demonstrated above with the -F option. The -F option tells ls to give more information about the type of the files involved--in this case, printing a / after each directory name.
If you give ls a directory name, the system will print the contents of that directory.

If you're a MS-DOS user, you may notice that the filenames can be longer than 8 characters, and can contain periods in any position. You can even use more than one period in a filename.
Let's move to the top of the directory tree, and then down to another directory with the commands

You can also move into directories in one step, as in cd /usr/bin .
Try moving around various directories, using ls and cd . In some cases, you may run into the foreboding `` Permission denied '' error message. This is simply UNIX security kicking in: in order to use the ls or cd commands, you must have permission to do so.
3.3 Creating new directories.
It's time to learn how to create directories. This involves the use of the mkdir command. Try the following:

Congratulations! You made a new directory and moved into it. Since there aren't any files in this new directory, let's learn how to copy files from one place to another.
3.4 Copying files
To copy files, use the command cp , as shown here:

The cp command copies the files listed on the command line to the file or directory given as the last argument. Notice that we use `` . '' to refer to the current directory
3.5 Moving files
The mv command moves files, rather than copying them. The syntax is very straightforward:

Notice that the termcap file has been renamed sells . You can also use the mv command to move a file to a completely new directory.
Note: mv and cp will overwrite a destination file having the same name without asking you. Be careful when you move a file into another directory. There may already be a file having the same name in that directory, which you'll overwrite
3.6 Deleting files and directories
You now have an ugly rhyme developing with the use of the ls command. To delete a file, use the rm command, which stands for ``remove'', as shown here:

We're left with nothing but shells, but we won't complain. Note that rm by default won't prompt you before deleting a file--so be careful.
A related command to rm is rmdir . This command deletes a directory, but only if the directory is empty. If the directory contains any files or subdirectories, rmdir will complain.
3.7 Looking at files
The commands more and cat are used for viewing the contents of files. more displays a file, one screenful at a time, while cat displays the whole file at once.
To look at the file shells , use the command

In case you're interested what shells contains, it's a list of valid shell programs on your system. On most systems, this includes /bin/sh , /bin/bash , and /bin/csh . We'll talk about these different types of shells later.
While using more , press Space to display the next page of text, and b to display the previous page. There are other commands available in more as well, these are just the basics. Pressing q will quit more .
Quit more and try cat /etc/termcap . The text will probably fly by too quickly for you to read it all. The name `` cat '' actually stands for ``concatenate'', which is the real use of the program. The cat command can be used to concatenate the contents of several files and save the result to another file.
3.8 Getting online help
Almost every UNIX system, including Linux, provides a facility known as manual pages . These manual pages contain online documentation for system commands, resources, configuration files and so on.
The command used to access manual pages is man . If you're interested in learning about other options of the ls command, you can type

and the manual page for ls will be displayed.
Unfortunately, most manual pages are written for those who already have some idea of what the command or resource does. For this reason, manual pages usually contain only the technical details of the command, without much explanation. However, manual pages can be an invaluable resource for jogging your memory if you forget the syntax of a command. Manual pages will also tell you about commands that we don't cover in this book. I suggest that you try man for the commands that we've already gone over and whenever I introduce a new command. Some of these commands won't have manual pages, for several reasons. First, the manual pages may not have been written yet. (The Linux Documentation Project is responsible for manual pages under Linux as well. We are gradually accumulating most of the manual pages available for the system.) Second, the the command might be an internal shell command, or an alias which would not have a manual page of its own. One example is cd , which is an internal shell command. The shell itself actually processes the cd --there is no separate program that implements this command |