You can use the ls command to list the files in any directory to which you have access. For a simple directory listing, at the Unix prompt, enter:
lsThis command will list the names of all the files and directories in the current working directory.
- You can limit the files that are described by using fragments of filenames and
wildcards. Examples of this are:
ls hello Lists files whose complete name is hello; if hello is a directory, displays the contents of the hello directory.
ls hel* Lists all files in the directory that begin with the characters hel [for example, files named hel, hello, and hello.officer].
ls hell? Lists files that begin with hell followed by one character, such as helli, hello, and hell1.
The * represents any number of unknown characters, while ? represents only one unknown character. You can use * and ? anywhere in the filename fragment.
- If you would like to list files in another directory, use the ls command along with the path to the directory. For example, if you are in your home directory and want to list the contents of the /etc directory, enter: ls /etc
This will list the contents of the /etc directory in columns.
- Several options control the way in which the information you get is displayed. Options are used in this format: ls -option filename
Neither the options nor the filename are required [you may use ls by itself to see all the files in a directory]. You may have multiple options and multiple filenames on a line.
The options available with ls are far too numerous to list here, but you can see them all in the online manual [man] pages.
Some of the more helpful options for ls are:
-a Shows all files, including those beginning with . [a period]. The dot is special in the Unix file system.
-d Shows directory names, but not contents
-F Marks special files with symbols to indicate what they are: / for directories, @ for symbolic links, * for executable programs
-l Shows the rights to the file, the owner, the size in bytes, and the time of the last modification made to the file. [The l stands for "long".]
-R Recursively lists subdirectories
The options can be combined. To list all the files in a directory in the long format, with marks for the types of files, you would enter:
ls -Flg - As with many other Unix commands, you can redirect the output from ls to a file, or pipe it to another command. If you want to save a list of the files in your directory to a file named foo, you would use the following command combination: ls > foo
For a more complete discussion of the ls command, see the online manual pages. At the Unix prompt, enter:
man lsRelated documents
This is document abds in the Knowledge Base.
Last modified on 2019-06-18 14:44:19.
SYNOPSIS
ls [-AabCcdFfghikLlmnopqRrstux1] [-timeout seconds] [-streams] [-X attr] [pathname...]
DESCRIPTION
ls lists files and directories. If the pathname is a file, ls displays information on the file according to the requested options. If the pathname is a directory, ls displays information on the files and subdirectories therein. You may obtain information on a directory itself using the -d option.
If you do not specify any options, ls displays only the file name[s]. 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 [multi-column] format.
Options
-Alists all entries including those starting with periods [.], but excluding any . or .. entries.
-alists all entries including those starting with a period [.].
-bdisplays non-printable characters as octal bytes with the form \ooo.
-Cputs output into columns, sorted vertically; this is the default output format to the terminal.
-cuses the creation time of the file for sorting [-t] or displaying [-l].
-ddoes not display the contents of named directories, but show information on the directories themselves.
-Fputs 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.
Note:Windows systems do not support FIFO files or sockets [as files] and consider all files that are not directories or symbolic links to be executable files. This option of the ls utility labels the files and directories display accordingly.
-fenables the -a option and disables the -C, -g, -l, -n, -o, -r, -s, and -t options. For each argument that is a directory, all directory entries are listed in the same order they are retrieved from the system [POSIX-compliant and UNIX systems only].
-gdisplays only the group ID numbers [on 8.1/2012R2/10/2016/2019/11/2022, POSIX-compliant and UNIX systems].
-hdisplays file sizes using more human-friendly units. Units used are:
B Bytes KB Kilobytes MB Megabytes GB Gigabytes TB Terabytes PB Petabytes EB Exabytes
When this option is specified, each file size is displayed using the most appropriate unit and is rounded to two decimal places.
-idisplays inode numbers along with file names [only on systems that support inode numbers, such as POSIX-compliant and UNIX systems].
-kdisplays size in kilobytes instead of blocks when specified with the -s option. If the -s option is not specified, this option has no effect.
-Lfollows symbolic links.
Note:Symbolic links are only available on 8.1/2012R2/2016/2019/2022 systems with the NTFS file system.
-ldisplays permissions, links, owner, group, size, time, name; see Long Output Format.
-mdisplays names in single line, with commas separating names.
-ndisplays user ID and group IDs as numbers instead of names.
-odisplays only the user ID of owner [POSIX-compliant and UNIX systems only].
-pputs / after directory names.
-qdisplays non-printable characters as ?.
-Rlists subdirectories recursively.
-rsorts in reverse of usual order; you can combine this with other options that sort the list.
-sdisplays size in blocks [after the inode number, but before other information]. If the -k option is also specified, the size is displayed in kilobytes instead.
-tsorts entries 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.
In long output, display number of streams [for file systems with alternate streams] after number of links, and enumerate those streams on a separate line [like -X]. If -l is not specified, -streams has no effect.
-timeout secondsspecifies the number of seconds that ls has to complete the operation before timing out and issuing an error. seconds is given in seconds.
-uuses the last access time for sorting [-t] or displaying [-l].
-X attrdisplays extended security attributes under Windows. This option turns on the -l [long listing] option. The attr argument is a string containing some of these characters:
Character | Meaning |
A | file attributes in verbose format |
a | file attributes in terse format |
D | verbose file Discretionary Access Control Entries [8.1/2012R2/10/2016/2019/11/2022 only] |
d | terse file Discretionary Access Control Entries [8.1/2012R2/10/2016/2019/11/2022 only] |
If both A and a or both D and d are in attr, ls uses the last one given on the command line. See Extended Attribute Descriptions.
-xputs output into columns sorted across the rows.
-1forces single column output.
Note:When you specify options that are mutually exclusive [for example, -c and -u], the option that appears last on the command line is used.
Long Output Format
The output from ls -l summarizes all the most important information about the file on one line. If the specified pathname is a directory, ls displays information on every file in that directory [one file per line]. It precedes this list with a status line that indicates the total number of file system blocks [512 byte units] occupied by the files in that directory. Here is a sample of the output along with an explanation.
-rw-rw-rw- 1 root dir 104 Dec 25 19:32 file
The first character identifies the file type:
- Regular file b Block special file c Character special file d Directory l Symbolic link n Network file p FIFO s Socket
For a regular file the '-' may be replaced by:
D Demand recall file E Encrypted file O Offline file S Sparse file
The next nine characters are in three groups of three; they describe the permissions on the file. The first group of three describes owner permissions; the second describes group permissions; the third describes other [or world] permissions. Because Windows systems do not support group and other permissions, these are copies of the owner's permissions. Characters that may appear are:
r Permission to read file w Permission to write to file x Permission to execute file a Archive bit is on [file has not been backed up] c Compressed file s System file h Hidden file t Temporary file
On Windows systems, most of the permissions shown are artificial, with no real meaning. The w bit is set according to the ReadOnly attribute, and the rx bits are always set on.
You can change some permissions with the chmod command.
After the permissions comes the number of links to the file.
Next comes the name of the owner of the file or directory. On file systems that don't support 8.1/2012R2/10/2016/2019/11/2022 security, the owner name cannot be determined and the owner ID number is displayed instead. Under 8.1/2012R2/10/2016/2019/11/2022 the name of the owner of a file is displayed if the file's SIDs can be obtained and if these SIDs have an associated name in the SAM database. If the file has a SID associated with it, but the name of the SID cannot be determined, then the value of the SID is displayed. [This can happen when the current user is not in the domain that was used when the file was created.] If the file does not have a SID [for example, if it is on a non-NTFS file system], or if the file security information cannot be accessed because the file is locked by another process, then the user name appears as .
Note:When a listed file is owned by the local computer, the owner is displayed as computer_name\ where computer_name is the name of the local computer.
Then comes the name of the group that owns the file or directory. On Windows systems, the same rules are followed for the group name as for the owner name.
Following this is the size of the file, expressed in bytes.
After this comes a date and time. For a file, this is the time that the file was last changed; for a directory, it is the time that the directory was created. The -c and -u options can change which time value is used. If the date is more than six months old or if the date is in the future, the year is shown instead of the time.
The last item on the line is the name of the file or directory.
Extended Attribute Descriptions
On 8.1/2012R2/10/2016/2019/11/2022 systems, ls supports the -X option, which displays the extended attributes of the file[s]. This description is shown beneath the long output format already described.
For ls -X A or ls -X a, the display format is:
Attributes: attributelist
where attributelist is a comma-separated list of one or more of:
Verbose | Terse |
Archive | A |
Compressed | C |
Directory | D |
Encrypted | E |
Hidden | H |
Normal | N |
Offline | O |
ReparsePoint | R |
ReadOnly | RO |
Sparse | SP |
System | S |
Temporary | T |
For ls -X D or ls -X d, the display format is:
ACE: perm usergrpname ace_flags accessmode
where:
is one of Allow or Deny.
usergrpnameis the user or group name as taken from the 8.1/2012R2/10/2016/2019/11/2022 Security Access Manager registry. Any spaces embedded in the name are replaced by + characters.
ace_flagsis a comma-separated list of the flags for Discretionary Access Control Entities:
Verbose | Terse |
ContainerInheritAce | CIA |
FailedAccessAceFlag | FAAF |
InheritOnlyAce | IOA |
NoPropagateInheritAce | NPIA |
ObjectInheritAce | OIA |
SuccessAccessAceFlag | SAAF |
If no flags are set, ls displays a single -. ACE stands for Access Control Entry; for more information, see your 8.1/2012R2/10/2016/2019/11/2022 system documentation.
accessmodeis the set of access permissions [if Allow is displayed] or restrictions [if Deny is displayed] for this ACE. These can be any or none of the following:
Verbose | Terse | Note |
Read | R | Read file data or list directory entries |
Write | W | Write file data or create new file in directory |
eXecute | X | Execute a file or traverse a directory |
Append | A | Append data to a file or add subdirectory |
DeleteChild | DC | For a directory, delete entries in directory |
ReadEa | RE | Read extended attributes |
WriteEa | WE | Write extended attributes |
ReadAttr | RA | Read attributes |
WriteAttr | WA | Write attributes |
Delete | D | Delete access |
ReadControl | RC | Read access to the owner, group, and discretionary access control list [ACL] of the security descriptor |
WriteDac | WD | Write access to the owner, group, and discretionary access control list [ACL] of the security descriptor |
takeOwnership | O | Write access to the owner |
Synchronize | S | Synchronize access |
ENVIRONMENT VARIABLES
COLUMNScontains the terminal width in columns. ls uses this value to determine the number of output columns to write using the -C option.
TK_NTLINKS_OFFMKS Toolkit supports hard links under 8.1/2012R2/10/2016/2019/11/2022 on NTFS file systems. There is a slight loss of performance for this support. If you do not require hard link support, you should set and export the environment variable TK_NTLINKS_OFF to disable this support.
TK_NTSECURITYINFO_OFFMKS Toolkit supports 8.1/2012R2/10/2016/2019/11/2022 security information on NTFS file systems. There is a slight loss of performance for this support. If you do not require any security information, you should set and export the environment variable TK_NTSECURITYINFO_OFF to disable this feature.
TK_NTSECURITYINFO_SID_TERSEUnder 8.1/2012R2/10/2016/2019/11/2022, files having an associated SID, whose name cannot be determined, display the value of the SID instead. SID values are usually very large. You should set and export the TK_NTSECURITYINFO_SID_TERSE which causes all SID values to be shortened by replacing all the subauthority values, except the last one, with the string -...-.
TK_USE_CURRENT_LOCALEWhen set, this environment variable causes months and days of the week to be displayed as defined in the current locale. By default, PTC MKS Toolkit utilities display months and days of the week in English.
TZcontains the time zone to be used when displaying date and time strings. On 8.1/2012R2/10/2016/2019/11/2022, PTC MKS Toolkit uses the built-in timezone support, and you should not set the TZ environment variable.
DIAGNOSTICS
Possible exit status values are:
0Successful completion.
1Failure due to any of the following:
— out of memory — inability to find a file's information — too many directories — file/directory not found 2Failure due to an invalid command line option.
File or directory "name" is not foundThe requested file or directory does not exist.
Cannot allocate memory for sortingTo 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 only appears when ls runs out of dynamically allocated memory.
PORTABILITY
POSIX.2. x/OPEN Portability Guide 4.0. All UNIX systems. Windows 8.1. Windows Server 2012 R2. Windows 10. Windows Server 2016. Windows Server 2019. Windows 11. Windows Server 2022.
On Windows systems, ls treats files and directories marked with the hidden attribute like POSIX and UNIX file names beginning with . [period].
On Windows systems, ls -a on the root of a partition [e.g. ls -a c:/] will behave in the Windows way and not enumerate and not display dot [.] and dot-dot [..] directories.
The -A, -b, -f, -g, -h, -L, -m, -n, -o, -p, -s, -X, and -x options are extensions to the POSIX and XPG.4 standard.
The -X option is specific to the 8.1/2012R2/10/2016/2019/11/2022 version of ls.
AVAILABILITY
PTC MKS Toolkit for Power Users
PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for
Interoperability
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
SEE ALSO
Commands:chmod, lcMiscellaneous:security, statPTC MKS Toolkit 10.4 Documentation Build 39.