42
◾
Linux with Operating System Concepts
• The user owner and group owner of the object
• The size of the object
• The last modification (or creation) date and time of the object
• The name of the object (and if a symbolic link, the item it is linked to)
Figure 2.2
shows an example of an
ls –l
operation applied to a portion of a user’s
home space.
An instruction can receive any combination of options. If you wish to provide a long
listing of all files, you would use
ls –al
(or
ls –la
). You could separate these to be
ls
–a –l
or
ls –l –a
but it is more common to combine all options as desired to save
typing.
You might notice the period that appears after the first series of characters (the hyphens,
r and w entries). The period indicates that the given item (file, directory) has an SELinux
context. SELinux is security-enhanced Linux and provides a greater degree of protection
over those available through ordinary Linux permissions. We cover Linux permissions in
Chapter 3 and briefly overview SELinux in Chapter 8.
While
ls has a number of options, there are only a few options that you would typically
use. Table 2.1 describes these (omitting
–a
and
–l
from earlier).
As mentioned at the beginning of this section, commands receive options and param-
eters. For ls, the parameters are a listing of files and directories. These names are the enti-
ties that are listed. If no such argument(s) is provided, the ls command lists all entries in
the current directory. If parameters are provided, they can consist
of one or several files
and/or directories.
Consider the following instruction:
ls file.txt
FIGURE 2.2
A long listing.
The Bash Shell
◾
43
If this file exists, the ls command responds by listing it. Otherwise, ls returns the response
ls: file.txt: No such file or directory
This instruction is not a very informative instruction as it only tells you if the file exists
or not.
A user more commonly will want to see what is in the directory. Therefore, there seems
little value to supply such an argument. However, when
used with options such as
–l
, it
becomes far more meaningful. For instance, when issuing
ls –l file.txt
, we might see
-rwxr--r--. 1
foxr foxr 183
Jul 23 2011 file.txt
If we use ls in conjunction with a directory name, then the command displays all of the
contents of the given directory (rather than the current working directory). We can use
wildcards to indicate possible variations in name. The * wildcard is used to match any-
thing. Thus,
ls *.txt
will list all files in the current working directory whose names end
with .txt no matter what appears on the left-hand side of the period.
We explore wildcards
in Chapter 3.
2.3 MAN PAGES
How do you learn about the options available for a command? Another command avail-
able in Linux is called
man
, which is short for manual page. This command displays the
manual contents for a given Linux command. These contents explain the intention of the
TABLE 2.1
Common ls Options
Do'stlaringiz bilan baham: