Explanation of the ls -l command in Linux? [closed

2019-08-28 10:02发布

I use the following command:

ls -l

As a result, I get the name of the files in the folder that I'm currently in, along with when they were last accessed, etc. On the left side, there are a string of characters and sometimes dashes. I was wondering if anyone can provide me a quick guide as to what each of the characters represent?

I can assume the first 'd' stands for directory, since that is the name of one of my folders. I'm assuming 'x' is for executable? Not sure, so can someone break it down for me?

This is what I'm referring to:

dr-xr-xr-x

Thanks for all of help.

标签: linux
4条回答
forever°为你锁心
2楼-- · 2019-08-28 10:33

From left to right every three letters together is a permission set designated for each kind of user. There are three kinds of permissions in every set

r-read
w-write
x-execute

From left to right each set designate the permissions for

 1) owner
 2) group
 3) others(other users)

respectively on that file

So in your case the directory has read and execute permissions for owner, group and others('-' specifies that particular permission is not there). Permissions can be changed using the chmod command provided that you have the access privileges on that file/directory to do so.

查看更多
祖国的老花朵
3楼-- · 2019-08-28 10:51

From the man page of chmod:

read (r), write (w), execute (or access for directories) (x), execute only if the file is a directory or already has execute permis- sion for some user (X), set user or group ID on execution (s), sticky (t), the permissions granted to the user who owns the file (u), the permissions granted to other users who are members of the file's group (g), and the permissions granted to users that are in neither of the two preceding categories (o).

meaning

  user can read
  | user can execute
  | | group can not write
  | | | others can read
  | | | | others can execute
  | | | | |
 dr-xr-xr-x
 | | | | |
 | | | | others can not write
 | | | group can execute
 | | group can read
 | user can not Write  
 it is a directory
查看更多
仙女界的扛把子
4楼-- · 2019-08-28 10:52

The first character is the type of file, usually you will see d for directory, - for regular file, or l for link.

The next nine characters represent three different types of permissions for the file: user permissions, group permissions, and other permissions.

The first character will either be r or -, indicating read permission.

The second character will either be w or -, indicating write permission.

The last character will either be x or -, or a number of different characters depending upon special properties of the file as described in the manual for ls (below).

There may also be another character after these nine, specifying special access permissions, which are described manual for ls (below).

From the manual for ls

The file type is one of the following characters:

`-' regular file

`b' block special file

`c' character special file

`C' high performance ("contiguous data") file

`d' directory

`D' door (Solaris 2.5 and up)

`l' symbolic link

`M' off-line ("migrated") file (Cray DMF)

`n' network special file (HP-UX)

`p' FIFO (named pipe)

`P' port (Solaris 10 and up)

`s' socket

`?' some other file type

The file mode bits listed are similar to symbolic mode specifications (*note Symbolic Modes::). But `ls' combines multiple bits into the third character of each set of permissions as follows:

`s' If the set-user-ID or set-group-ID bit and the corresponding executable bit are both set.

`S' If the set-user-ID or set-group-ID bit is set but the corresponding executable bit is not set.

`t' If 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. *Note Mode Structure::.

`T' If the restricted deletion flag or sticky bit is set but the other-executable bit is not set.

`x' If the executable bit is set and none of the above apply.

`-' Otherwise.

Following the file mode bits is a single character that specifies whether an alternate access method such as an access control list applies to the file. When the character following the file mode bits is a space, there is no alternate access method. When it is a printing character, then there is such a method.

GNU ls' uses a.' character to indicate a file with an SELinux security context, but no other alternate access method.

A file with any other combination of alternate access methods is marked with a `+' character.

查看更多
Animai°情兽
5楼-- · 2019-08-28 11:00

From the OpenBSD Manual Pages. Note that this also could be view in the command prompt using man ls. (Handy for future similar look-ups, eh!)

The Long Format If the -g, -l, or -n options are given, the following information is displayed for each file: mode, number of links, owner (though not for -g), group, size in bytes, time of last modification (“mmm dd HH:MM”), and the pathname. In addition, for each directory whose contents are displayed, the first line displayed is the total number of blocks used by the files in the directory. Blocks are 512 bytes unless overridden by the -k option or BLOCKSIZE environment variable.


If the owner or group name is not a known user or group name, respectively, or the -n option is given, the numeric ID is displayed.


If the file is a character special or block special file, the major and minor device numbers for the file are displayed in the size field.


If the -T option is given, the time of last modification is displayed using the format “mmm dd HH:MM:SS ccyy”.


If the file is a symbolic link, the pathname of the linked-to file is preceded by “->”.


The file mode printed under the -g, -l, or -n options consists of the entry type, owner permissions, group permissions, and other permissions. The entry type character describes the type of file, as follows:

  • - regular file
  • b block special file
  • c character special file
  • d directory
  • l symbolic link
  • p FIFO
  • s socket link

The next three fields are three characters each: owner permissions, group permissions, and other permissions. Each field has three character positions:

  • If r, the file is readable; if -, it is not readable.
  • If w, the file is writable; if -, it is not writable.

The first of the following that applies: - S - If in the owner permissions, the file is not executable and set-user-ID mode is set. If in the group permissions, the file is not executable and set-group-ID mode is set. - s - If in the owner permissions, the file is executable and set-user-ID mode is set. If in the group permissions, the file is executable and setgroup-ID mode is set. - x - The file is executable or the directory is searchable. - - The file is neither readable, writable, executable, nor set-user-ID, nor set-group-ID, nor sticky (see below).


These next two apply only to the third character in the last group (other permissions):

  • T - The sticky bit is set (mode 1000), but neither executable nor searchable (see chmod(1) or sticky(8)).
  • t - The sticky bit is set (mode 1000), and is searchable or executable (see chmod(1) or sticky(8)).

In addition, if the -o option is specified, the file flags (see chflags(1)) are displayed as comma-separated strings in front of the file size, abbreviated as follows:

  • - no flags
  • arch archived
  • nodump do not dump
  • sappnd system append-only
  • schg system immutable
  • uappnd user append-only
  • uchg user immutable
查看更多
登录 后发表回答