UNIX For Dummies [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

UNIX For Dummies [Electronic resources] - نسخه متنی

John Levine, Margaret Levine Young

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید






Putting Your Ducks in a Row

As with everything else in life (if we may be so bold as to suggest it), it pays to be organized when you’re naming files and putting them in directories. If you don’t have at least a little organization, you will never find anything. Think about which types of files you will make and use. (Word-processing files? Spreadsheet files?) Then make a directory for every type of file or for every project you’re working on. This section shows you how.


Making directories


Before you create a directory, be sure that you put it in the right place. Remember that you type the following line to display your working directory (the current directory):


pwd

The most likely place to create a subdirectory is in your home directory. If you’re not there already, type this line to go back home:


cd

When you create a directory, you give it a name. To create a directory called Temp to hold temporary files, type this line:


mkdir Temp

Many people have a directory called Temp to hold files temporarily. These files can be the ones you need to keep just long enough to print, to copy to a floppy disk or tape, or whatever. Anyway, you have one now, too. To confirm that the Temp directory is there, type this line:


ls

You can even go in there and look around by typing the following (and pressing Enter after typing the first line):


cd Temp
ls

When you create a directory, it starts out empty (it contains no files).

Most people have directories with names something like these examples:



Mail or Maildir : For electronic mail (see Chapter 17).



Docs : For miscellaneous documents, memos, and letters.



Temp : For files you don’t plan to keep. Use Temp to store files you plan to throw away soon. If you put them in some other directory and don’t erase them when you finish with them, you may forget what they are and be reluctant to delete them later. Directories commonly fill up with junk in this way. Make a rule that any files left in the Temp directory are considered deletable. Most UNIX systems also have a directory called /tmp where anyone can stash temporary files for a while, which is emptied every time the system is restarted.



bin : For programs that you use but that aren’t stored in a central place. Your system administrator may have already made you your own bin directory. (See Chapter 12 for information about the bin directory and making your own programs.)

You can also make one or more directories to contain actual work.


Dot and dot dot


Tip UNIX has two funny directory names you can use — especially with the cd and ls commands. One is . (a single dot), which stands for the current directory. You type the following line, for example, to tell UNIX to list the files in the current directory:


ls .

This command is pointless, of course, because typing the following line does exactly the same thing:


ls

Okay, forget about . (the single dot). But .. (the double dot, or dot dot) is useful. It stands for the parent directory of the working directory. The parent directory is the one of which the working directory is a subdirectory. The parent is one level up the tree from where you are now. If you’re in the directory /usr/home/zacyoung/Budget , for example, the .. (dot dot, or parent) directory is /usr/home/zacyoung .
Suppose that you type this line:


ls ..

You see a list of the files in the parent directory of where you are now. This command can save you from some serious typing (and the associated errors).


Neat operations you can perform on directories


After you have some directories, you may want to change their names or get rid of them. You also may want to move a file from one directory to another. This section shows you how to try that first.

Transplanting files


Chapter 5 describes the use of the mv command to rename a file. You can use the same command to move files from one directory to another. To get the mv command to move files rather than just rename them, you tell it two things:



The name of the file you want to move

The name of the path where you want to put the file

If you want, you can rename the file at the same time you move it, but we like to keep things (comparatively) simple. Suppose that you put the file sues.04.budget into the /Budget/Year2003 directory rather than in /Budget/Year2004 . The easiest way to move it is to go first to the directory in which it is located. In this example, you type this line:


cd /Budget/Year2003

Use ls to make sure that the file is in the current directory. After you are sure that the file is there, you can move it to the directory you want by typing this line:


mv sues-04-budget /Budget/Year2004

Be sure to type one space after mv and one space between the name of the file and the place you want to move it to. If you use ls again, you discover that the file is no longer in the working directory (Year2003 ). You should change to the directory to which you moved the file and use ls to make sure that the file is there. Make one typing mistake in a mv command, and you can move a valuable file to some unexpected place.

Amputating unnecessary directories


You can use the rmdir command to remove a directory, but what about the files in the directory? Are they left hanging in the air with the ground blown out from under them? Nope; you must either get rid of the files in the directory (delete them) or move them elsewhere before you can hack away at the directory.

To erase a directory, follow these steps:



Use the rm command to delete any files you don’t want to keep.
(See Chapter 5 for the gory details of using this command.)

If you want to keep any of the files, move them to somewhere else by using the mv command (as explained in the preceding section).


Move to some other directory when the directory you want to delete is empty.
Deleting your working directory is usually a poor idea. The easiest thing to do is to move to the working directory’s parent directory:


cd ..



Remove the directory by typing this line:

rmdir OldStuff

Replace OldStuff with the name of the directory you want to ax.



Use ls to confirm that the directory is gone.


Warning You can delete a directory and all the files in it or even a directory and all the subdirectories and files in them, but this process is dangerous stuff. You usually are better off sifting through the files and deleting or moving them in smaller groups. If you’re interested in a really dangerous command, which we shouldn’t even be telling you about, you can type rm –r to remove a directory and all its files and subdirectories in one fell swoop.

Renaming a directory


If you have used DOS, you will be thrilled to learn that in UNIX you can rename a directory after you create it. (DOS didn’t let you do that, at least not in early versions.) Again, the mv command comes to the rescue.
To rename a directory, you tell mv the current directory name and the new directory name. Go to the parent directory of the directory you want to rename, and then use the mv command. To rename the /Budget directory to the /Finance directory, for example, go to the / directory (type cd /) and then type this line:


mv Budget Finance

Remember Make sure first that a directory with that name isn’t already there. If it is, UNIX moves the first-named directory to become a subdirectory of the existing directory. In other words, if a /Finance directory is already there, /Budget moves to become /Finance/Budget . That could be handy, if that’s what you have in mind. Then again, it could drive you out of your mind if that’s not what you expect.

/ 213