ls - list contents of directory
/usr/bin/ls [-aAbcCdeEfFghHilLmnopqrRsStuvVx1@] [-/ c | v] [-% atime | crtime | ctime | mtime | all] [file]...
/usr/xpg4/bin/ls [-aAbcCdeEfFghHilLmnopqrRsStuvVx1@] [-/ c | v] [-% atime | crtime | ctime | mtime | all] [file]...
/usr/xpg6/bin/ls [-aAbcCdeEfFghHilLmnopqrRsStuvVx1@] [-/ c | v] [-% atime | crtime | ctime | mtime | all] [file]...
For each file that is a directory, ls lists the contents of the directory. For each file that is an ordinary file, ls repeats its name and any other information requested. The output is sorted alphabetically by default. When no argument is given, the current directory (.) is listed. When several arguments are given, the arguments are first sorted appropriately, but file arguments appear before directories and their contents.
There are three major listing formats. The default format for output directed to a terminal is multi-column with entries sorted down the columns. The -1 option allows single column output and -m enables stream output format. In order to determine output formats for the -C, -x, and -m options, ls uses an environment variable, COLUMNS, to determine the number of character positions available on one output line. If this variable is not set, the terminfo(4) database is used to determine the number of columns, based on the environment variable, TERM. If this information cannot be obtained, 80 columns are assumed.
The mode printed when the -e, -E, -g, -l, -n, -o, -v, -V, or -@ option is in effect consists of eleven characters. The first character can be one of the following:
d
D
l
b
c
p
P
s
-
The next 9 characters are interpreted as three sets of three bits each. The first set refers to the owner's permissions; the next to permissions of others in the user-group of the file; and the last to all others. Within each set, the three characters indicate permission to read, to write, and to execute the file as a program, respectively. For a directory, execute permission is interpreted to mean permission to search the directory for a specified file. The character after permissions is an ACL or extended attributes indicator. This character is an @ if extended attributes are associated with the file and the -@ option is in effect. Otherwise, this character is a plus sign (+) character if a non-trivial ACL is associated with the file or a space character if not.
If -/ and/or -% are in effect, then the extended system attributes are printed when filesystem supports extended system attributes. The display looks as follows:
$ls -/ c file -rw-r--r-- 1 root root 0 May 10 14:17 file {AHRSadim-u} $ls -/ v file -rw-r--r-- 1 root root 0 May 10 14:17 file {archive,hidden,readonly,system,appendonly\ nodump,immutable, av_modified,\ noav_quarantined,nounlink} $ls -l -% all file -rw-r--r-- 1 root root 0 May 10 14:17 file timestamp: atime Jun 25 12:56:44 2007 timestamp: ctime May 10 14:20:23 2007 timestamp: mtime May 10 14:17:56 2007 timestamp: crtime May 10 14:17:56 2007
See the option descriptions of the -/ and -% option for details.
ls -l (the long list) prints its output as follows for the POSIX locale:
-rwxrwxrwx+ 1 smith dev 10876 May 16 9:42 part2
Reading from right to left, you see that the current directory holds one file, named part2. Next, the last time that file's contents were modified was 9:42 A.M. on May 16. The file contains 10,876 characters, or bytes. The owner of the file, or the user, belongs to the group dev (perhaps indicating ``development''), and his or her login name is smith. The number, in this case 1, indicates the number of links to file part2 (see cp(1)). The plus sign indicates that there is an ACL associated with the file. If the -@ option has been specified, the presence of extended attributes supersede the presence of an ACL and the plus sign is replaced with an 'at' sign (@). Finally, the dash and letters tell you that user, group, and others have permissions to read, write, and execute part2.
The execute (x) symbol occupies the third position of the three-character sequence. A - in the third position would have indicated a denial of execution permissions.
The permissions are indicated as follows:
r
w
x
-
s
S
t
T
l
L
For user and group permissions, the third position is sometimes occupied by a character other than x or -. s or S also can occupy this position, referring to the state of the set-ID bit, whether it be the user's or the group's. The ability to assume the same ID as the user during execution is, for example, used during login when you begin as root but need to assume the identity of the user you login as.
In the case of the sequence of group permissions, l can occupy the third position. l refers to mandatory file and record locking. This permission describes a file's ability to allow other files to lock its reading or writing permissions during access.
For others permissions, the third position can be occupied by t or T. These refer to the state of the sticky bit and execution permissions.
The following options are supported:
The following options are supported for all three versions:
-a
-A
-b
-c
-C
-d
-e
-E
In addition, this option displays the offset from UTC in ISO 8601:2000 standard format (+hhmm or -hhmm) or no characters if the offset is indeterminable. The offset reflects the appropriate standard or alternate offset in force at the file's displayed date and time, under the current timezone.
-f
-g
-h
-H
-i
-l
-L
-m
-n
-o
-p
-q
-r
-R
-s
-S
-t
-u
-v
-V
The -V option is only applicable to file systems that support NFSv4 ACLs, such as the Solaris ZFS file system.
The format of the displayed ACL is as follows:
entry_type : permissions : inheritance_flags : access_type
entry_type is displayed as one of the following:
user:username
group:groupname
owner@
group@
everyone@
The following permissions, supported by the NFSv4 ACL model, are displayed by using the -v or -V options:
read_data (r)
list_directory (r)
write_data (w)
add_file (w)
append_data (p)
add_subdirectory (p)
read_xattr (R)
write_xattr (W)
execute (x)
read_attributes (a)
write_attributes (A)
delete (d)
delete_child (D)
read_acl (r)
write_acl (C)
write_owner (o)
synchronize (s)
-
The following inheritance flags, supported by the NFSv4 ACL model, are displayed by using the -v or -V options:
file_inherit (f)
dir_inherit (d)
inherit_only (i)
no_propagate (n)
successful_access (S)
failed_access (F)
inherited (I)
-
access_type is displayed as one of the following types:
alarm
allow
audit
deny
For example:
$ ls -dV /sandbox/dir.1 drwxr-xr-x+ 2 root root 2 Jan 17 15:09 dir.1 user:marks:r-------------:fd-----:allow owner@:--------------:-------:deny owner@:rwxp---A-W-Co-:-------:allow group@:-w-p----------:-------:deny group@:r-x-----------:-------:allow everyone@:-w-p---A-W-Co-:-------:deny everyone@:r-x---a-R-c--s:-------:allow $ ||||||||||||||||:||||||+ inherited access ||||||||||||||:||||||+ failed access ||||||||||||||:|||||+--success access ||||||||||||||:||||+-- no propagate ||||||||||||||:|||+--- inherit only ||||||||||||||:||+---- directory inherit ||||||||||||||:|+----- file inherit |||||||||||||| ||||||||||||||+ sync |||||||||||||+- change owner ||||||||||||+-- write ACL |||||||||||+--- read ACL ||||||||||+---- write extended attributes |||||||||+----- read extended attributes ||||||||+------ write attributes |||||||+------- read attributes ||||||+-------- delete child |||||+--------- delete ||||+---------- append |||+----------- execute ||+------------ write data |+------------- read data
-x
-1
-@
-c | -v
appendonly
archive
av_modified
av_quarantined
crtime
hidden
immutable
nodump
nounlink
readonly
system
The display characters used in compact mode (-/ c) are as follows:
Attribute Name Display archive A hidden H readonly R system S appendonly a nodump d immutable i av_modified m av_quarantined q nounlink u
The display in verbose mode (/ v) uses full attribute names when it is set and the name prefixed by 'no' when it is not set.
The attribute name crtime and all other timestamps are handled by the option -% with the respective timestamp option arguments and also with all option argument. The display positions are as follows: The display in verbose mode (-/ v) uses full attribute names when it is set and the name prefixed by no when it is not set. The attribute name crtime and all other timestamps are handled by the option -% with the respective timestamp option arguments and also with all option argument.
The display positions are as follows:
{||||||||||} |||||||||+- u (nounlink) ||||||||+-- q (av_quarantined) |||||||+--- m (av_modified) ||||||+---- i (immutable) |||||+----- d (nodump) ||||+------ a (appendonly) |||+------- S (system) ||+-------- R (readonly) |+--------- H (hidden) +---------- A (archive)
-% atime | crtime | ctime | mtime | all
atime
crtime
ctime
mtime
If extended system attributes are not supported or if the user does not have read permission on the file or if the crtime extended attribute is not set, crtime is treated as a synonym for mtime.
When option argument -all is specified, all available timestamps are printed which includes -atime, -ctime, -mtime and on the extended system attribute supporting file systems, -crtime (create time). The option -% all does not effect which timestamp is displayed in long format and does not affect sorting.
-F
Specifying more than one of the options in the following mutually exclusive pairs is not considered an error: -C and -l (ell), -m and -l (ell), -x and -l (ell), -@ and -l (ell). The -l option overrides the other option specified in each pair.
Specifying more than one of the options in the following mutually exclusive pairs is not considered an error: -C and -1 (one), -H and -L, -c and -u, and -e and -E, and -t and -S. The last option specifying a specific timestamp (-c, -u, -% atime , -% crtime, -% ctime, and -% mtime) determines the timestamps used for sorting or in long format listings.
-F
Specifying more than one of the options in the following mutually exclusive pairs is not considered an error: -C and -l (ell), -m and -l (ell), -x and -l (ell), -@ and -l (ell), -C and -1 (one), -H and -L, -c and -u, and -e and -E, and -t and -S. The last option specifying a specific timestamp (-c, -u, -% atime , -% crtime, -% ctime, and -% mtime) determines the timestamps used for sorting or in long format listings.
-F
Specifying more than one of the options in the following mutually exclusive pairs is not considered an error: -C and -l (ell), -m and -l (ell), -x and -l (ell), -@ and -l (ell), -C and -1 (one), -H and -L, -c and -u, and -e and -E, -t and -S. The last option specifying a specific timestamp (-c, -u, -% atime , -% crtime, -% ctime, and -% mtime) determines the timestamps used for sorting or in long format listings.
The following operand is supported:
file
See largefile(5) for the description of the behavior of ls when encountering files greater than or equal to 2 Gbyte ( 2^31 bytes).
Example 1 Viewing File Permissions
The following example shows how to display detailed information about a file.
% ls -l file.1 -rw-r--r-- 1 gozer staff 206663 Mar 14 10:15 file.1
The permissions string above (-rw-r--r--) describes that the file owner has read and write permissions, the owning group has read permissions, and others have read permissions.
The following example shows how to display detailed information about a directory.
% ls -ld test.dir drwxr-xr-x 2 gozer staff 2 Mar 14 10:17 test.dir
The permissions string above (drwxr-xr-x) describes that the directory owner has read, write, and search permissions, the owning group has read and search permissions, and others have read and search permissions.
Another example of listing file permissions is as follows:
% ls -l file.2 -rw-rwl--- 1 gozer staff 206663 Mar 14 10:47 file.2
The permissions string above (-rw-rwl---) describes that the file owner has read and write permissions, the owning group has read and write permissions, and the file can be locked during access.
Example 2 Displaying ACL Information on Files and Directories
The following example shows how to display verbose ACL information on a ZFS file.
% ls -v file.1 -rw-r--r-- 1 marks staff 206663 Mar 14 10:15 file.1 0:owner@:execute:deny 1:owner@:read_data/write_data/append_data/write_xattr/write_attributes /write_acl/write_owner:allow 2:group@:write_data/append_data/execute:deny 3:group@:read_data:allow 4:everyone@:write_data/append_data/write_xattr/execute/write_attributes /write_acl/write_owner:deny 5:everyone@:read_data/read_xattr/read_attributes/read_acl/synchronize :allow
The following example shows how to display compact ACL information on a ZFS directory.
% ls -dV test.dir drwxr-xr-x 2 marks staff 2 Mar 14 10:17 test.dir owner@:--------------:------:deny owner@:rwxp---A-W-Co-:------:allow group@:-w-p----------:------:deny group@:r-x-----------:------:allow everyone@:-w-p---A-W-Co-:------:deny everyone@:r-x---a-R-c--s:------:allow
The following example illustrates the ls -v behavior when listing ACL information on a UFS file.
$ ls -v file.3 -rw-r--r-- 1 root root 2703 Mar 14 10:59 file.3 0:user::rw- 1:group::r-- #effective:r-- 2:mask:r-- 3:other:r--
Example 3 Printing the Names of All Files
The following example prints the names of all files in the current directory, including those that begin with a dot (.), which normally do not print:
example% ls -a
Example 4 Providing File Information
The following example provides file information:
example% ls -aisn
This command provides information on all files, including those that begin with a dot (a), the i-number, the memory address of the i-node associated with the file---printed in the left-hand column (i); the size (in blocks) of the files, printed in the column to the right of the i-numbers (s); finally, the report is displayed in the numeric version of the long list, printing the UID (instead of user name) and GID (instead of group name) numbers associated with the files.
When the sizes of the files in a directory are listed, a total count of blocks, including indirect blocks, is printed.
Example 5 Providing Extended System Attributes Information
example% ls -/ c file (extended system attribute in compact mode) -rw-r--r-- 1 root root 0 May 10 14:17 file {AHRSadim-u}
In this example, av_quarantined is not set.
example% ls -/ v file (extended system attribute in verbose mode) -rw-r--r-- 1 root root 0 May 10 14:17 file {archive,hidden,readonly,system,appendonly\ nodump,immutable,av_modified,\ noav_quarantined,nounlink} example% ls -/ v file (no extended system attribute) -rw-r--r-- 1 root staff 0 May 16 14:48 file {} example% ls -/ c file (extended system attribute supported file system) -rw-r--r-- 1 root staff 3 Jun 4 22:04 file {A------m--}
archive and av_modified attributes are set by default on an extended system attribute supported file.
example% ls -/ c -%crtime file -rw-r--r-- root root 0 May 10 14:17 file {AHRSadim-u}
This example displays the timestamp as the creation time:
example% ls -l -%all file -rw-r--r-- 1 root root 0 May 10 14:17 file timestamp: atime Jun 14 08:47:37 2007 timestamp: ctime May 10 14:20:23 2007 timestamp: mtime May 10 14:17:56 2007 timestamp: crtime May 10 14:17:56 2007 example% ls -%crtime -tl file* -rw-r--r-- 1 foo staff 3 Jun 4 22:04 file1 -rw-r--r-- 1 root root 0 May 10 14:17 file -rw-r--r-- 1 foo staff 0 May 9 13:49 file.1
In this example the files are sorted by creation time.
See environ(5) for descriptions of the following environment variables that affect the execution of ls: LANG, LC_ALL, LC_COLLATE, LC_CTYPE, LC_TIME, LC_MESSAGES, NLSPATH, and TZ.
COLUMNS
0
>0
/etc/group
/etc/passwd
/usr/share/lib/terminfo/?/*
See attributes(5) for descriptions of the following attributes:
|
For all options except -A, -b, -e, -E, -h, -S, -v, -V, -@, -/ and -%, see standards(5).
|
For all options except -A, -b, -e, -E, -h, -S, -v, -V, -@, -/ and -%, see standards(5).
|
For all options except -A, -b, -e, -E, -h, -S, -v, -V, -@, -/ and -%, see standards(5).
chmod(1), cp(1), setfacl(1), fgetattr(3C), terminfo(4), acl(5), attributes(5), environ(5), fsattr(5), largefile(5), standards(5)
Unprintable characters in file names can confuse the columnar output options.
The total block count is incorrect if there are hard links among the files.
The sort order of ls output is affected by the locale and can be overridden by the LC_COLLATE environment variable. For example, if LC_COLLATE equals C, dot files appear first, followed by names beginning with upper-case letters, then followed by names beginning with lower-case letters. But if LC_COLLATE equals en_US.ISO8859-1, then leading dots as well as case are ignored in determining the sort order.
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |