Lab5 4 6
Lab5 4 6
Objectives:
• Learn to display directory and file information
• Use the ls (list files) command with various options
• Display hidden files
• Display files and file types
• Examine and interpret the results of a long file listing
• List individual directories
• List directories recursively
Background:
In this lab, the student will use the ls command, which is used to display the contents of a directory. This
command will display a listing of all files and directories within the current directory or specified directory
or directories. If no pathname is given as an argument, ls will display the contents of the current
directory. The ls command will list any subdirectories and files that are in the current working directory if
a pathname is specified. The ls command will also default to a wide listing and display only file and
directory names. There are many options that can be used with the ls command, which makes this
command one of the more flexible and useful UNIX commands.
Tools / Preparation:
a) Before starting this lab, the student should review Chapter 5, Section 4 – Listing Directory
Contents
b) The student will need the following:
1. A login user ID, for example user2, and a password assigned by their instructor.
2. A computer running the UNIX operating system with CDE.
3. Networked computers in classroom.
Notes:
1-5 Fundamentals UNIX 2.0—-Lab 5.4.6 Copyright 2002, Cisco Systems, Inc.
Use the diagram of the sample Class File system directory tree to assist with this lab.
a. Enter the command to change to the home directory. What command was used?
b. Enter the command to verify the directory the student is currently in. What command was used?
a. Enter the command to display the contents of the dir2 directory using a relative pathname from
the student’s home directory. What command was used?
2-5 Fundamentals UNIX 2.0—-Lab 5.4.6 Copyright 2002, Cisco Systems, Inc.
c. Enter the command to list the files in the /etc directory, which is a standard UNIX directory under
the root, using an absolute pathname. What command was used?
d. Enter the command to list the files in the planets directory using an absolute pathname? What
command was used?
e. Enter the command to list only the dante file in the student’s home directory, to see if it exists and
not see all other files and directories. What command was seen?
b. Enter the command that will allow all files in the student’s home directory to be seen?
d. Enter the following to create a new empty file called .hiddenfile using the touch command (be
sure to make the first character a dot). $ touch .hiddenfile
• Directory: A forward slash (/) after the name indicates this is a directory or subdirectory. A
directory is considered a type of file with UNIX.
• ASCII Text File: If there is no symbol after the name this indicates a plain ASCII text file with no
formatting characters in it. ASCII is the American Standard Code for Information Interchange. An
ASCII text file is similar to a DOS text file.
• Executable: An asterisk (*) after the name indicates that this is a command, an application, or a
script file, which can be run or executed.
• Symbolic Link: An at sign (@) after the name indicates a symbolic link which is a way of giving a
file an alternate name. Symbolic links are covered later in this course.
a. From the student’s home directory, enter the basic ls command without any options. Could a
user tell whether they are looking at files or directories if it were not for the fact that most of the
directories have “dir” in their name?
3-5 Fundamentals UNIX 2.0—-Lab 5.4.6 Copyright 2002, Cisco Systems, Inc.
b. Enter the command that will allow the student to see the file names in the home directory and
their type. List the names of the directories:
d. The /usr/bin directory contains many UNIX executable commands, some of which the student has
already used. Enter the command to see the files and types in the /usr/bin directory. What
command was used?
f. The /etc directory contains many different type of UNIX system files. Enter the command to see
the files and types in the /etc directory. What command was used?
Shown below is an example of a long listing for a file (dante) and a directory (dir1). The listing is
interpreted as follows:
• The first position of the display indicates whether this is a file or a directory.
• The lower case letter d indicates a directory.
• The dash (-) indicates a file.
• The group of characters shown as r, w, x and dashes are the permissions for the file or directory.
• The numbers shown as 1 and 5 are the number of links.
• User2 is the file owner.
• Staff is the file or directory access group.
• The 320 and 512 indicate the file size.
• The date and times shown indicate the date and time the file was created or modified.
• Finally the name of the file or directory is shown.
Links, owner, and group are covered later in the course.
a. From the student’s home directory, enter the basic ls command without any options. What
information was displayed on each file or directory listed?
b. Enter the command that will allow a user to see a long listing for the file names in their home
directory. What command was entered?
e. Using -t (time) option will list files with the most recently modified at the top of the list. To get a
detailed or long listing of files sorted by time use the ls –lt version of the command. This will
show the most recent at the top. Enter the ls –lt command. What is the most recently created
or modified file?
4-5 Fundamentals UNIX 2.0—-Lab 5.4.6 Copyright 2002, Cisco Systems, Inc.
Step 8. Use the ls Command to List Individual Directories
Use ls -ld to display detailed information about a directory, but not its contents. This is useful when a
user wants to see the properties of a directory and not the information about its contents.
a. From the student’s home directory, enter the command that will provide a long listing of just the
information for the dir2 directory.
b. From the student’s home directory, enter the command that will provide a long listing for just the
information on the fruit directory using a relative pathname.
a. From the student’s home directory, enter the command that will provide a recursive listing for the
dir2 directory.
5-5 Fundamentals UNIX 2.0—-Lab 5.4.6 Copyright 2002, Cisco Systems, Inc.