Tying It All Together: File Management Skills Test


Before we move on, I would like to take a moment to harp on the importance of Unix, the combination of commands to unleash the ultimate in power. This is what it's all about. Knowing commands will do nothing for you if you don't know how to use them from memory. In this section of the lesson, you will see what you remember and what you forgot, and how they (most of the Unix commands we have learned up to now) all work together when applied correctly.

In this example we will move through some of the commands that you have learned in the past nine lessons. This will not only serve as a refresher for you, but will also help you understand how they all can work together.

When working with files and directories, it is key to remember that the way Unix is organized is revolved around the files on your system and the directories in which they are contained. In this example, we will start by moving from your current directory into another one and create a file. Let's begin:

Skills Test

  1. Most times, you will be working within your home directory. What would that look like at the shell prompt?

    Answer: ~

    Is There Another Name? In Unix, a home directory can also be called $HOME.


  2. When you are working within the shell, it keeps track of the directory you are using. This directory is called the current working directory, or the current directory. To find your current directory, what would you type?

    Answer: pwd

  3. To list the files in the current directory, what would you type?

    Answer: ls

    What About Other Listings? In Unix, you can use options with commands. This is especially true of the ls command.

    With the ls command, you can do many switches, but a few options you should really keep in your personal memory banks are the following:

    To list all the files in the current directory, including normally hidden files, type ls a.

    To list the files in the current directory and other additional information, such as the file's owner, its creation date, and its permissions, type ls l.

    To list the files in a directory, type ls <directory name>.


  4. Now that you have listed the files in a directory, you may find that from the pwd and ls commands, you do not see the file you are looking for. You will see a directory within your present working directory that you know you want to work in; it's called storage. You need to change directories to storage where a file should be within it that we want to work on. To change the current directory to the storage directory, what would you type?

    Answer: cd storage

    Do I Always Need to Specify a Directory? No, absolutely not. Specifying something is the easiest way to get right to it. If you do not know the name of the file, there is a handy tip you can learn to move quickly through the Unix file system until you reach the root directory, specified by a /.

    To move up a directory, type cd ...

    This will bring you to the directory just above the one you are currently in now. In other words, if you are in /etc, you will be in / if you issue the cd .. command. You must remember to leave a space, and the two dots.

    You can also specify the direct path when you want to change a directory. You can be in the root directory and specify the path to the file you want by typing the entire path such as, cd /etc/HTMLLAB/. You can now edit a file within this path. In my example, it is indextest.htm.


  5. From accessing the storage directory, we want to create a new directory where we can store only HTML files. You want to call the directory HTML. This being said, we need to create a new directory within the storage directory. To do this, what would you type?

    Answer: mkdir HTML

    Unix Is Sensitive Deep Down Inside Remember, Unix is case sensitive. Although I made a directory in all uppercase letters, do not make the mistake of putting your caps lock key on. This is a big mistake in Unix environments, so break that habit quickly. Be careful when you use uppercase instead of lowercase; you could be specifying the wrong command.


  6. You may have made a mistake and do not need this new directory. The storage directory should have contained a directory called storage. There are many ways for you to change this, but for this example we will look at using a tool to remove the unwanted directory, and create the new one when needed. To do this, what you would type?

    Answer: rmdir HTML

  7. To create a new directory named storage, type mkdir test. When you complete this step, type pwd and ls l to see what is in your current directory. Make sure you have the test directory created inside the directory you are currently located in. Once you ensure that this is good (you can walk back through the steps or the lessons in the book if you are having issues), your next step is to copy a file. You want to find a file in your current directory that you can copy to the test directory. If you are in your home directory, you may have a file in there to copy to another location. If you do not, then move to another directory (using the cd command) and search for a file to copy. You can run a generic search by issuing a wildcard such as find /etc *.htm or find /etc *.conf as examples. You will see Unix perform the search and then list out at the end all the files you requested. Once you find a file you want to copy, what would you type to copy that file to the /etc/storage directory?

    Answer: cp syslog.conf /etc/storage

    If you wanted to verify that this copied over, the follow-up to this command would be

    Answer: ls l /etc/storage

    You should see that the file copied over. If not, check your work and go back through the steps just discussed.

    Unix Gone Wild You can specify more than one file with a path by using wildcards. A wildcard is a character that matches many characters. The * wildcard matches any number of characters.


  8. You have created a directory called storage and it currently has a file copied into it. You could have used the mv command to move it from its source directory to the destination, but that's not what we want. To remove a directory, you must first ensure that the directory does not contain any other files or directories using the rm command. You can then remove the storage directory by typing what?

    Answer: rmdir storage

  9. The last command I will show you is your reward for passing this small test. To prevent the servers from running out of disk space, your accounts are only allowed to store a limited amount of data. To find out how much room you have left, what command would you type at the shell prompt?

    Answer: quota

    This will give you the current disk quota for the current user.

Congratulations, you did a fantastic job in putting this all together. Imagine, you may not have even been working with Unix and now you have already mastered the basics. We haven't even scratched the surface of what Unix can do, and you are already navigating like a pro. Let's continue to the next lesson where we will wrap up file management by explaining to you how to manage your stored data through archiving and compression.

If you honestly had a very hard time working through this example, it is not because you can't do it, it is because you cannot recall the commands quickly. You should at least feel as if you could do it if you had those commands, right? Well, that's the trick to learning Unix; keep practicing, and practice makes perfect.



    SAMS Teach Yourself Unix in 10 Minutes
    Sams Teach Yourself Unix in 10 Minutes (2nd Edition)
    ISBN: 0672327643
    EAN: 2147483647
    Year: 2005
    Pages: 170

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net