Table of Contents

BASH - Commands - ls - ls output fields definitions

The output of the ls command depends on the version of “ls”, the options used, the platform used, etc.

ls -al

returns:

-rwxrw-r--    10    root   root 2048    Jan 13 07:11 afile.exe

-rwxrw-r--    10    root   root 2048    Jan 13 07:11 afile.exe
?UUUGGGOOOS   00  UUUUUU GGGGGG ####    ^             ^-- File name.
^ ^  ^  ^ ^    ^      ^      ^    ^     \-- Date Time stamp.
| |  |  | |    |      |      |    \--- File Size.
| |  |  | |    |      |      \-------- Group Name (for example, Users, Administrators, etc).
| |  |  | |    |      \--------------- Owner Name.
| |  |  | |    \---------------------- Link count (Usually refers to number of hard links; but can vary.)
| |  |  | \--------------------------- Alternative Access (blank means none defined, anything else varies)
| \--\--\----------------------------- File Mode Permissions.  Read, Write and Special access modes for [U]ser, [G]roup, and [O]thers (everyone else).
\------------------------------------- File Type flag.

NOTE: If you cannot find a man/info page for ls itself (man ls / info ls), try looking in the coreutils package (info coreutils).

Also note that among the more common platforms, Microsoft platforms tend not to translate very well to ls output, so you may see odd behavior, flags, or other unusual info in the output, depending on how your version of “ls” was compiled, what it was linked against, etc.


File Types flag

On most systems, the first field is also used to indicate the presence of extra attributes like ACLs, security attributes or other extended attributes.

-Regular file
bBlock special file
cCharacter special file
CHigh performance (“contiguous data”) file
dDirectory
DDoor (Solaris 2.5 and up)
lSymbolic link
MOff-line (“migrated”) file (Cray DMF)
nNetwork special file (HP-UX)
pFIFO (named pipe)
PPort (Solaris 10 and up)
sSocket
?Some other file type

File Mode Permissions

Each of the three characters represent the read, write, and execute permissions:

Usually in the form:

rwx rwx rwx
rReading is permitted.
wWriting is permitted.
xExecution is permitted. For directories it means you can attempt to access the directory contents.
-The specific permission is not allowed.

but ls can combine multiple bits into the third character of each set of permissions as follows:

sIf the set-user-ID or set-group-ID bit and the corresponding executable bit are both set.
SIf the set-user-ID or set-group-ID bit is set but the corresponding executable bit is not set.
tIf the restricted deletion flag or sticky bit, and the other-executable bit, are both set. The restricted deletion flag is another name for the sticky bit.
TIf the restricted deletion flag or sticky bit is set but the other-executable bit is not set.
xIf the executable bit is set and none of the above apply.

NOTE: Sometimes you may encounter an s or S for setuid and/or setgid programs, or other less common characters.

See your ls documentation for the mode characters it will show.


Alternative Access Types


Some platforms have an odd notion of what constitutes a link.

These usually include hard links and symbolic links, as well as directory entries (which is why directories often have high link counts – its parent has one link, the directory has a link to itself in the . entry, and each of its sub-directories has a link back via ..


File Size

Some versions and/or command line flags will list the number of blocks used instead of the number of bytes.

A filesystem with a block size of 1024 bytes will list all sizes up to 1024 bytes as “1”, meaning 1 block is used, from 1025 to 2048 as “2”, using 2 blocks, and so on.

But listing block sizes by default (without explicitly using a command line option) is rare on most modern un*x machines.

NOTE: The file size for a directory is only the size of the metadata of the directory, not the total size of the files under the directory.


Date Time stamp

The Date Time stamp is usually the date/time the file was last modified, not the time the file was created.

NOTE: On un*x-ish filesystems there is no record of the file creation time

The ctime field does NOT mean “creation time” as it does on FAT/NTFS filesystems, but rather, it means the “inode [C]hange time” – the time the inode itself was last modified.

The mtime (last [M]odified) and atime (last [A]ccesed/read) timestamps are the same on both systems – although the precision (FAT has a granularity of two seconds, for example) and time zone may vary.


References

https://en.wikipedia.org/wiki/Unix_file_types

https://en.wikipedia.org/wiki/File_system_permissions#Notation_of_traditional_Unix_permissions