Technology Tips

Dan Comden

The past two "Tech Tips" columns have mentioned how to find help for UNIX commands (the man command) and how to list files in a directory using ls. The next step is to understand how to create new directories to better organize your file area. For example, you might want to keep information about gopher and ftp sites in a directory called "Internet" while other files such as downloaded pictures might go in a directory called "Images." With a well-organized directory structure, you can easily retrieve information you've saved, with little searching.

As you know by now, you have a directory where you begin when you first login to your UNIX account. This is called your home directory. If you think of the computer as a building, and directories as individual offices, you can consider your home directory to be your very own office. Since this is your office, you can organize it however you like! You can put all your magazines in one drawer of your desk, hang pictures on the wall, or even stack all your stuff right in the middle of the floor. Whatever you do in your office or home directory doesn't impact anyone else.

But as you might imagine, it's easier to have a well-organized directory structure just like it's better to keep your office as efficiently laid out as possible.

So how do you expand and explore your directory area? Use the cd, mkdir, and rmdir, commands to move between, create, remove directories. The pwd command is useful to check your current location.

What directory am I in?
 
The pwd command is quite useful to determine your present working directory. Just type pwd at any time and the operating system will respond with your current location (e.g., /w0/danc/Images).
 
Changing directories
 
The cd (for change directory) command is used to move from one directory to another. For example, if you have a directory called "Images" that is one level down from your current directory, you would type cd Images.

Remember that UNIX is case sensitive. In other words, if a file or directory name has capitalized letters, you must type the name exactly as it's shown in order for the command to be successful.

A nice feature of the cd command is that if you type it without specifying a directory, you will return to your home directory. This is useful if you are many subdirectories away from your home directory and wish to quickly return "home."

Creating and removing a directory
 
Use the mkdir (short for "make directory") command to create a new subdirectory. For example, if you wanted to create a directory called "Gopher" type mkdir Gopher. You may have noticed by now that I capitalize the first letter of directory names. This is a method I've used to help me quickly recognize the difference between file names and directory names when I use the ls command to list the contents of a directory.

If you create a directory that you no longer want, use the rmdir command to remove a directory. The format is similar to the mkdir command, as you must specify the name of the directory you wish to delete. This command removes the directory called "Books": rmdir Books

Note that a directory must not have any files in it in order for it to be removed. This is to help keep you from inadvertently losing files that you may want to save.

Removing a file
 
Use the rm command with caution. Once a file is deleted, there's a good chance that it's lost forever! The structure of the command is simple. For example, if you have a file called "tribbles" in the current directory that you wish to remove, you enter rm tribbles.

For additional information on any of these commands, remember that you can use the man command along with the command in question to get more details and options.