Experiment No. - 6 - Managing Directories 1. Objective(s) : The Activity Aims
Experiment No. - 6 - Managing Directories 1. Objective(s) : The Activity Aims
___6__
MANAGING DIRECTORIES
1. Objective(s):
The activity aims
1.1 To discriminate different UNIX commands used to manage directories and the files they
contain
1.2 To analyze the UNIX commands used to create and delete directories 1.3
To test different UNIX commands used to manage files within directories 2.
Intended Learning Outcomes (ILOs):
The students shall be able to:
2.1. To choose the commands used to manage files and directories as needed.
In the previous activity, you are presented with commands to display the contents of your
directory as well as the contents of a file.
While working in a computing environment, you will create various files and retrieve them at a
later time. How do you organize them? It is therefore necessary for you to learn how to
organize your files. In the real world, files are organized in a filing cabinet. Each file is labeled
intuitively and inserted in correct folders or drawers. Similarly, in a computing environment,
you must name your files appropriately and store them in proper directories and
subdirectories for easy retrieval.
UNIX provides tools to create directories and subdirectories, as well as copy and move files.
It also provides tools to delete unneeded files and directories. Since you may be working with
hundreds, even thousands of files, UNIX provides a tool to find your files
4. Resources:
Personal computer with Unix or unix-based operating system
5. Procedure:
5.1. Start a terminal session with your unix or unix-based operating system.
5.2. Run and tests the commands that falls in the categories of directory management.
Recall the UNIX directory structure given as part of an exercise. You will also create
structure as extension of your home directory, similar to the structure that UNIX system
itself uses.
Remember that UNIX uses a base directory called the root directory. And all other
directories are subdirectories of the root directory. The root directory is signified by the
slash (/) symbol
The directory that you login to during the login process is your home directory, e.g.
/home/<loginname>. This is your designated working directory; all other subdirectories and
files should be stored in this directory.
When working with files and directories, oftentimes you want to know which directory you
are currently using. After issuing many directory-level commands and moving your working
directory positions several times, you may loose track of which directory you are currently
using. UNIX provides the pwd command to do this, pwd means print your working
directory. It displays the full path of the working directory.
Try typing pwd <return>; which directory are you currently in?
The directory you login to during the login process is called you home directory. This
directory has the format /home/<loginname>. In the figure shown above, the home
directory is /home/ariel.
If you want to move to a different directory, use the cd command plus the directory name
that you want to use as in the exercise below:
You create files when you use applications, when you copy other files, when you redirect
output to files. You can choose to collect all these files in your home directory, or you can
create additional directories with descriptive names to hold together files with the same
categories and simplify management of these files.
You are not, however, locked in the original organization that you created. You can still
copy or move these files to different directories. You can even empty the directories that
you have created or delete them completely.
The following sections help you gain understanding of how to create directories and
manipulate them and their contents.
To create new directories, issue the command mkdir, make directory. The command takes
the name of the directory that you want to create as argument. The name of the directories
follows the UNIX naming convention for files.
In the exercise below, two files prog1 and prog2 were created then moved to the shell
directory. Please note that the wildcard character (?) was also used in place of the
numbers 1 and 2.
mv filename-to-be-renamed new-filename
where filename-to-be-renamed is the name of the file in the directory before the mv
command is issued. The second argument new-filename is the name of the file after the
command is executed.
To understand the concept of links, note that UNIX tracks a file’s identity by using the file’s
i-number in the i-node table. The file’s name and i-number are both sotred in a directory
entry. The directory’s i-number entry, in effect, points UNIX to the i-node that holds a file’s
storage information. When you give a file-name argument, UNIX looks at the names in the
directory and finds the named entry. UNIX then uses the associated i-number to access
the contents of the file. It is therefore possible for two or more directory entries to “point” to
the same i-number (same file) even when the names used for the file are different.
The figure below shows the files prog2 and progln has the same inode number. Use the
command ls –il to display the inode number or the stat prog2 progln command to give the
statistics of the files.
Note that once a file is removed from the directory, it cannot be recovered. Thus it is
recommended to take precautionary measures when erasing files, oftentimes it is a good
practice to issue an ls command on the files that you want to delete before actually
deleting them.
At times, you may want to save some files and make copies of them so that you can
modify the copies or the original. Use the cp with the –r option to copy entire contents of a
directory to a specified directory.
The exercise below shows how to copy the entire contents of the shell directory to shellbak
directory.
Two files, file1 & file2 were created inside the shell directory. Then, the cp -r shell
shell_bak command, copied the entire contents of the shell directory to the shellbak
directory. Note that UNIX created the shellbak directory since it does not exist prior to the
execution of the command.
Course: Experiment No.: Group No.: Section: Group Members:
Date Performed: Date Submitted: Instructor:
6. Data and Results:
7. Conclusion: