Ch5.FileSystemFileHierarchy_35
Ch5.FileSystemFileHierarchy_35
Example:
$ ls
_____________________ output _______________________
21x LINES.dat LINES.idx PAGES.dat PAGES.idx
Notice that the files are listed in order. Files beginning with
numbers come first; files beginning with uppercase characters
come next; and files beginning with lowercase characters come
last. Also notice that although this format displays your
filenames in a compact fashion, it doesn't give information
about the file’s attributes.
Long Listing
Get more detail about files by a long listing (-l option).
It is know as Long –Listing.
Displays seven columns of information about each file.
Example,
$ ls –l
_______________________Output________________________________
-rwxr-xr— 1 asm adept 512 Dec 14 16:16 21x
-rw-rw-r— 1 marsha adept 1024 Jan 20 14:14 LINES.dat
-rw-rw-r— 1 marsha adept 256 Jan 20 14:14 PAGES.dat
-rw-rw-r— 1 marsha acct 240 May 5 1992 acct.pds
-rw-rw-r— 1 marsha adept 1024 Nov 22 15:42 marsha.pds
-rwxrwxr— 4 root sys 43072 Aug 22 1991 p11
-rwxrwxr— 4 root sys 256041 Aug 22 1991 t11
drw-rw-r— 1 marsha adept 3072 Oct 12 11:42 users
___________________________________________________________
The First Column of in the Listing
- indicates the file's type (See Table on next slide).
-rwxr-xr— indicates the file's permissions.
1 indicates the number of links to the file.
asm is the user ID of the file's owner.
adept is the group ID of the group that the
owner belongs to.
512 is the size of the file in bytes.
Dec 14 16 :16 is the time stamp—the last
modified date & time.
21x is the name of the file.
Type of File Indicator Table
- Ordinary file
d Directory file
l Link file
c Special /character file
p Named pipe special file
b Special block file
Showing Hidden Files with -a
The ls option doesn't normally list files that begin with a period.
Suppose that the directory displayed in the previous section also
contained a file named .profile. In that case, you would see:
$ ls -a
_______________________Output____________________________
. .. .profile 21x LINES.datLINES.idx PAGES.dat
Note that the files . and .. represent the current and parent
directories, respectively.
You can combine Options
Example (Long listing and Hidden Files):
$ ls –al <RT>
_______________________Output_______________________
• Even if you don't know what the mystery character is, you can still
work with the file by using filename substitution (discussed in the
next section). If you need to know the exact nature of the mystery
character, you can use the -b option, which causes the nonprintable
character to print in octal mode. With the -b option, the filename
would display as abcd\010efg, in which \010 is the octal
representation of a backspace.
Additional ls options include:
-u Used with -l, causes the last access time stamp to
be displayed; instead of the last modification time.
-s Used with -l, gives the file size in blocks instead of
bytes.
-t Sorts the output by time stamp instead of name,
also used with -u sorts the output by access time.
-r Reverses the order of the output. By itself,
displays the output in reverse alphabetic order.
-x Forces the output into multicolumn.
Pattern Matching on a Single Character
In a filename substitution, the question mark ? stands for any
single character.
You can use the question mark ? in any position. For example:
$ ls ?11 _______Output___________________
p11 t11 z11
_________________________________________________
Multiple Question Marks ??
Using multiple question marks in a single substitution.
Examples:
$ ls p??
______________________Output_______________________
p10 p11
___________________________________________________
Finding files that end in .pds -Below two commands illustrate how to do this:
$ ls ????.pds
_________________Output______________
acct.pds
_____________________________________
$ ls ?????.pds
____________________Output__________________
marsha.pds
____________________________________________
Pattern Matching on a Group of Characters
In the previous example ($ ls ????.pds), to list all files ending in .pds
using single character substitution, you would have to know exactly how
many characters precede the period. To overcome this problem, you use
the asterisk *, which matches a character string of any length, including
a length of zero.
Examples:
$ ls *.pds
______________________Output________________
acct.pds marsha.pds
____________________________________________
$ ls p10*
______________________Output________________
p10 p101
____________________________________________
Multiple Asterisk **
Multiple asterisk * can be used in a single substitution.
Example:
$ ls *.*
__________________Output______________________
LINES.dat LINES.idx PAGES.dat PAGES.idx acct.pds
marsha.pds
______________________________________________
Meta-Characters
• Combining character sets with meta-characters. To list
the names of all files that begin with p or t:
• $ ls [pt]*
____________Output_____________________
p10 p101 p11 t11
_______________________________________
More About Character Set
Now suppose that you wanted a list of all filenames that begin with
an UPPERCASE alphabetic character. You could use
$ ls [ABCDEFGHIJKLMNOPQRSTUVWXYZ]*
______________________Output________________________
LINES.dat LINES.idx PAGES.dat PAGES.idx
___________________________________________________
If you're guessing that there might be a better way to do this, you're
right. When the characters in a character set substitution are in
sequence, you can use a - (hyphen) to denote all of the characters in
the sequence. Therefore, you can abbreviate the previous command
in this way:
$ ls [A-Z]*
__________________The Same Output Above____________
Broken Sequence of Character Set
If a character sequence is broken, you can still use the
hyphen for the portion of the character set that is in
sequence. For example, the following command lists
all the three-character filenames that begin with p, q,
r, s, t, and z:
$ ls [p-tz]??
______________________Output__________________
p10 p11 t11 z11
_____________________________________________
_
Listing a Full Tree
Listing The FULL Sub-Tree From the Current Directory
$ ls *
______________________Output_________________