Directory listings
Notes:
The ls command - examples of common options:
The ls command is used to show the contents of a directory.
Some of the options of the ls command are:
-
ls
List the contents of the current directory
-
ls /etc
List the contents of the /etc directory
-
ls -a
Display all entries in the current directory including those beginning with
a period. File and directory names that start with a period are "hidden"
files in unix; they do not appear in ordinary directory listings.
-
ls -l
Display a long or detailed listing of the current directory, one line of
data for each entry.
-
ls -al /etc
Display a long listing of the /etc directory including "hidden" files or
subdirectories.
-
ls -h
The -h option is the "help" option, this gives a list of all of the options
for the ls command and brief explanations.
-
To get a list of all of the other options of ls, use the man command. [ man
ls ]
Some of the fields in a directory listing entry:
There are a number of things that appear in a unix directory listing:
-
Permissions:
Users and the system administrator need a way to control the way other users
can access files and directories. The standard unix filesystem does this
with permissions. Each file has read, write and execute permisssions set
for the owner, the group and then all other users.
-
Links:
Users can create links to existing files. The filesystem keeps track of the
number of links.
-
Owner and group:
Unix is a multi-user operating system. For each file and directory, the
filesystem keeps track of the file owner and group.
-
Size in bytes:
-
Date:
The unix filesystem actually maintains 3 dates for each file: the last access
date, the last modification date (the last date that the file contents were
modified) and the last change date (the last date that the file "inode" or
directory entry was modified). The date that appears in a standard directory
entry is the last modification date.
-
Filename:
A sample directory entry:
-rwxrw-r-- 1 xyz staff 12 Mar 7 12:35
runme
-
- This is an ordinary file
-
rwx The permissions for the owner (xyz): read, write, execute
-
rw- The permissions for the group (staff): read, write,
not execute
-
r-- The permissions for others: read, not write, not execute
-
1 The number of links to the file
-
xyz The owner
-
staff The group
-
12 The size (in bytes)
-
Mar 7 12:35 The last time that the file was modified
-
runme The name of the file
Exercises:
-
Load floppix and login using your own initials.
-
In a previous lab, the directory map showed the following directories under
/.
bin, boot, dev, etc, home, lib, mnt, proc, sbin, tmp, usr, var
Look at the directory listing for the root directory on floppix.
Are there any directories in the above list that are not present in
floppix?
_________________________
Are there any top-level directories that are present in floppix and not listed
above?
_________________________
-
Change to the root directory and try to list the contents of each of the
top-level directories.
Which of these directories are empty? _________________________
Ordinary users cannot view the contents of some of these directories.
Which ones? _________________________
What are the permissions for those directories? _________________________
-
What is the purpose of the -F option of the ls command. Look this up using
the man pages. _________________________
-
Try running the commands:
ls -F /home
ls -F /bin
What symbol does the -F option use to identify directories? __________
What symbol does the -F option use to idenfify executable files? __________
Questions & Answers:
-
Interpret this directory entry:
drwxr-xr-- 2 abc users 1024 Mar 7 12:35 ddd
Answer: The directory entry specifies:
-
d This is a directory
-
rwx The permissions for the owner (abc): read, write, execute
-
r-x The permissions for the group (users): read, not write,
execute
-
r-- The permissions for others: read, not write, not execute
-
2 The number of links to the directory
-
abc The owner
-
users The group
-
1024 The size (in bytes)
-
Mar 7 12:35 The last time that the file was modified
-
ddd The directory name
Copyright © L.
M. MacEwan