ls - List file and directory names and attributes
Format
ls [-AabCcDdEFfgHikLlmMnopqRrsTtuWx1] [pathname ...]
Description
ls lists files and directories. If the pathname is a file, ls displays information about the file according to the requested options. If it is a directory, ls displays information about the files and subdirectories therein. You can get information about a directory itself using the -d option.
If you do not specify any options, ls displays only the file names. When ls sends output to a pipe or a file, it writes one name per line; when it sends output to the terminal, it uses the -C (multicolumn) format.
Options
- -A
- Lists all entries including those starting with periods (
.
); but excluding any.
or..
entries. - -a
- Lists all entries including those starting with a period (
.
). - -b
- Displays nonprintable characters as octal bytes with the form
\ooo
. - -C
- Puts output into columns, sorted vertically; this is the default output format to the terminal.
- -c
- Uses the time of the last change of the file's attributes for sorting (-t) or displaying (-l).
- -D
- Displays from directories.
- -d
- Does not display the contents of named directories, but information about the directories themselves.
- -E
- Displays extended attributes for regular files:
- a
- Program runs APF-authorized if linked AC=1.
- p
- Program is considered program-controlled.
- s
- Program is enabled to run in a shared address space.
- l
- Program is loaded from the shared library region.
- -
- Attribute not set
- -F
- Puts a
/
after each directory name, a*
after every executable file, a|
after every FIFO file, a@
after every symbolic link, and a=
after every socket. It also puts an & character after an external link name. - -f
- Forces the pathname argument to be a directory; turns off sorting. ls gives the ordered list of file names in a directory file. The directory file is read and the file names are listed in the same order as they are returned. The contents of a directory file are shown.
- -g
- Same as -l except that it does not display owner.
-g turns on the Long Output Format. See Long output format for details.
- -H
- Displays file formats for regular files:
- --
- Not specified.
- bin
- Binary data.
- rec
- Record. (File data consists of records with prefixes. The record prefix contains the length of the record that follows. From the shell command perspective, files with this format will be treated as if they were binary files.)
Or the following text data delimiters:- nl
- Newline character.
- cr
- Carriage return.
- lf
- Line feed.
- crlf
- Carriage return followed by line feed.
- lfcr
- Line feed followed by carriage return.
- crnl
- Carriage return followed by new line.
-H turns on the Long Output Format. See Long output format for details.
- -i
- Displays file serial (inode) numbers along with file names.
- -k
- Uses 1024 bytes for block size.
- -L
- Follows symbolic links.
- -l
- Displays permissions, links, owner, group, size, time, name. See Long output format for details.
- -M
- Displays the security label of the file. ls -M does not turn on the -l option. ls -M can be used with other options. See Long output format for details.
- -m
- Displays names in a single line, with commas separating names.
- -n
- Displays UID number and GID number.
- -o
- Same as -l except that it does not display group.
-o turns on the long output format. See Long output format for details.
- -p
- Puts
/
after directory names. - -q
- Displays nonprintable characters as
?
. - -R
- Lists subdirectories recursively.
- -r
- Sorts in reverse of typical order; you can combine this with other options that sort the list.
- -s
- Displays size in blocks, after the file serial (inode) number, but before other information. The block size is 512 bytes unless the -k option is used.
- -T
- Displays file tag information associated with the file. The format of this output will be
similar to the output from chtag -p. An example output:
> ls -T file t IBM-1047 T=on file1
ls -T does not turn on the -l option. ls -T can be used with other options. See Long output format for details.
- -t
- Sorts by time. By default, this option sorts the output by the modification times of files. You can change this with the -c and -u options.
- -u
- Uses the last access time for sorting (-t) or displaying (-l).
- -W
- Enables the audit bits to be displayed. This option turns on the -l
option.
These bits are printed in a 6-character field directly after the field displaying the file permission bits. These 6 characters are really two groups of 3 bits each. The first group of 3 describes the user-requested audit information. The second group of 3 describes the auditor-requested audit information. Each 3 characters displayed are the read, write, and execute (or search) audit options. Each character indicates the audit option as:
s (Audit successful access attempts)
f (Audit failed access attempts)
a (Audit all accesses)
- (No audit)-W turns on the long output format. See Long output format for details.
- -x
- Puts output into sorted columns, with output going across the rows.
- -1
- Forces output to be one entry per line.
Long output format
total 11
drwxr-xr-x 3 ROOT SYS1 0 Mar 12 19:32 tmp
drwxrwxrwx 4 ROOT SYS1 0 Mar 12 19:32 usr
drwxr-xr-x 2 ROOT SYS1 0 Mar 12 19:32 bin
-rwxr--r-- 1 ROOT SYS1 572 Mar 12 19:32 foo
-rwxr--r-- 1 ROOT SYS1 640 Mar 12 19:33 abc
If -T is specified, file tag information is displayed first on the line.
The first character identifies the file type:
-
- Regular file
b
- Block special file (not supported for z/OS UNIX System Services)
c
- Character special file
d
- Directory
e
- External link
l
- Symbolic link
p
- FIFO
s
- Socket file type
r
- Permission to read the file.
w
- Permission to write on the file.
x
- Permission to execute the file.
x
) position of the output. S
- Same as
s
, except that the execute bit is turned off. s
- If in owner permissions section, the set-user-ID bit is on; if in group permissions section, the set-group-ID bit is on.
T
- Same as
t
, except that the execute bit is turned off. t
- The sticky bit is on.
- +
- n/a
ls -l file
-rwxrwxrw-+ WELLIE SYS 167 Jan 11 09:54 file
Use getfacl to display the extended ACL entries. You can set permissions with either chmod or setfacl.
- The number of links to the file.
- The name of the owner of the file or directory.
- The name of the group that owns the file or directory.
- The size of the file, expressed in bytes. For character special files, it displays the major and minor device types.
- For a file, the date and time the file was last changed. For a directory or symlink, when it was created. The -c and -u options can change which time value is used. If the date is more than 6 months old or if the date is in the future, the year is shown instead of the time.
- The name of the file or directory.
total 11
-rwxr-xr-x -ps- 1 ROOT SYS1 101 Mar 12 19:32 her
-rwxrwxrwx a-s- 1 ROOT SYS1 654 Mar 12 19:32 test
-rwxr-xr-x a-- 1 ROOT SYS1 40 Mar 12 19:32 temp
-rwxr--r-- ap-l 1 ROOT SYS1 572 Mar 12 19:32 foo
-rwxr--r-- --sl 1 ROOT SYS1 640 Mar 12 19:33 abc
total 32
-rwxr-xr-x ---- 1 ROOT SYS1 0 Mar 26 08:47 tmp
drwxr-xr-x 2 ROOT SYS1 8192 Mar 26 08:50 usr
-rwxr--r-- cr 1 ROOT SYS1 40 Mar 26 08:55 abc
-rwxr-x--- rec 1 ROOT SYS1 80 Dec 26 09:55 newfmt
ls -EH
-rwxr-xr-x ap-l bin 1 ROOT SYS1 101 Mar 12 19:21 foo
total 11
drwxr-xr-x fff--- 3 ROOT SYS1 0 Mar 12 19:32 tmp
drwxrwxrwx fff--- 4 ROOT SYS1 0 Mar 12 19:32 usr
drwxr-xr-x fff--- 2 ROOT SYS1 0 Mar 12 19:32 bin
-rwxr--r-- fff--- 1 ROOT SYS1 572 Mar 12 19:32 foo
-rwxr--r-- fff--- 1 ROOT SYS1 640 Mar 12 19:33 abc
Usage notes for the ls command
- To display information about a directory from a symbolic link
to the directory, either add a trailing slash to the symbolic link
name, or use the -L option. For example,
if the /etc directory was converted into a symbolic
link, issuing an ls on /etc without
a trailing slash gives you the following information:
However, if you add the trailing slash, the following information about /etc is displayed:> ls -l /etc lrwxrwxrwx 1 BPXROOT BIN 12 Oct 18 19:46 /etc -> $SYSNAME/etc
> ls /etc/
The same information is displayed when the -L option is used:Information IBM cmx ioepdcf rc yylex.c NetQ csh.cshrc ldap recover yyparse.c Printsrv csh.login log security zoneinfo TextTools dfs magic socks.conf booksrv imoisinf mailx.rc startup.mk bpe init.options profile utmpx ls -L /etc
Information IBM cmx ioepdcf rc yylex.c NetQ csh.cshrc ldap recover yyparse.c Printsrv csh.login log security zoneinfo TextTools dfs magic socks.conf booksrv imoisinf mailx.rc startup.mk bpe init.options profile utmpx - When issuing the ls command against a large directory structure, the
following message might be returned:
To alleviate this problem, set the _CEE_RUNOPTS="HEAP(,,,FREE)" environment variable before invoking the ls command. Language Environment will free all unused storage to avoid exhausting the user heap. For more information about heap tuning, see Tuning heap storage in z/OS Language Environment Programming Guide.FSUM6786 too many directory entries in "dir"
Environment variables
- COLUMNS
- Contains the terminal width in columns. ls uses this value to determine the number of output columns to write using the -C option.
- TZ
- Contains the time zone to be used when displaying date and time strings.
Localization
- LANG
- LC_ALL
- LC_COLLATE
- LC_CTYPE
- LC_MESSAGES
- LC_TIME
- LC_SYNTAX
- NLSPATH
Exit values
0
- Successful completion.
1
- Failure due to any of the following reasons:
- Out of memory.
- Inability to find a file's information.
- Too many directories.
- File or directory not found.
- Specified on the command line.
2
- Incorrect command-line option
Messages
- File or directory name is not found
- The requested file or directory does not exist.
- Cannot allocate memory for sorting
- To sort its output, ls needs to allocate memory; this message says that there was not enough memory for the sorting operation.
- Too many directory entries in dir
- This message appears only when ls runs out of dynamically allocated memory.
Portability
POSIX.2, X/Open Portability Guide, UNIX systems.
The -A, -b, -E, -f, -g, -L, -m, -n, -o, -p, -s, -W, and -x options are extensions of the POSIX standard.
Related information
TZ environment variable explains how to set the local time zone with the TZ environment variable.
ls -f, sh, tcsh