What is the command to check file permissions in Linux?

青灯夜游
Release: 2023-03-01 18:42:31
Original
26306 people have browsed it

Linux command ls to view file permissions. ls is the abbreviation of list. Its main function is to display the contents of the current directory, including file permissions. The basic syntax is "ls [option] directory name"; the ls command needs to be used with the "-l" option parameter to view all the directories. For the permission information of the file or folder, check the syntax "ls -l [directory name]", which can be abbreviated as "ll [directory name]".

What is the command to check file permissions in Linux?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

Linux command to view file permissionsls.

In the directory where the file is located, use the following command to view the permission information of all files or folders in the directory.

ls -l
Copy after login

or enter

ll
Copy after login

. The two commands have the same effect, but the latter is the abbreviation of the former.

What is the command to check file permissions in Linux?

We can see the permissions of the file, -rw-rw-r--, there are 10 digits in total.

Among them: The first one - represents the type (details are shown in the map below)

  • The middle three rw- represent It is the owner (user)

  • and the three rw- represent the group (group)

  • The last three r-- represent other people

Then let me explain the next 9 digits:

  • #r Indicates that the file can be read (read)

  • w Indicates that the file can be written (write)

  • x means the file can be executed (if it is a program)

  • - means the corresponding Permission has not been granted

File and folder operation permission:

PermissionAbbreviation Effect on ordinary files Effect on folders
ReadrView file contentList the files in the folder (ls)
WritewModify the file ContentDelete, add or rename files (folders) in folders
ExecutionxFiles can be used as programs Execute cd to the folder

图解:

What is the command to check file permissions in Linux?What is the command to check file permissions in Linux?

需要注意的一点是,一个目录同时具有读权限和执行权限才可以打开并查看内部文件,而一个目录要有写权限才允许在其中创建其它文件,这是因为目录文件实际保存着该目录里面的文件的列表等信息。

linux ls命令介绍

ls 命令,list 的缩写,是最常见的目录操作命令,其主要功能是显示当前目录下的内容。此命令的基本格式为:

# ls [选项] 目录名称
Copy after login

表 1 列出了 ls 命令常用的选项以及各自的功能。

表 1 ls 命令常用选项及功能
选项 功能
-a 显示全部的文件,包括隐藏文件(开头为 . 的文件)也一起罗列出来,这是最常用的选项之一。
-A 显示全部的文件,连同隐藏文件,但不包括 . 与 .. 这两个目录。
-d 仅列出目录本身,而不是列出目录内的文件数据。
-f ls 默认会以文件名排序,使用 -f 选项会直接列出结果,而不进行排序。
-F 在文件或目录名后加上文件类型的指示符号,例如,* 代表可运行文件,/ 代表目录,= 代表 socket 文件,| 代表 FIFO 文件。
-h 以人们易读的方式显示文件或目录大小,如 1KB、234MB、2GB 等。
-i 显示 inode 节点信息。
-l 使用长格式列出文件和目录信息。
-n 以 UID 和 GID 分别代替文件用户名和群组名显示出来。
-r 将排序结果反向输出,比如,若原本文件名由小到大,反向则为由大到小。
-R 连同子目录内容一起列出来,等於将该目录下的所有文件都显示出来。
-S 以文件容量大小排序,而不是以文件名排序。
-t 以时间排序,而不是以文件名排序。
--color=never
--color=always
--color=auto
never 表示不依据文件特性给予颜色显示。
always 表示显示颜色,ls 默认采用这种方式。
auto 表示让系统自行依据配置来判断是否给予颜色。
--full-time 以完整时间模式 (包含年、月、日、时、分)输出
--time={atime,ctime} 输出 access 时间或改变权限属性时间(ctime),而不是内容变更时间。

注意,当 ls 命令不使用任何选项时,默认只会显示非隐藏文件的名称,并以文件名进行排序,同时会根据文件的具体类型给文件名配色(蓝色显示目录,白色显示一般文件)。除此之外,如果想使用 ls 命令显示更多内容,就需要使用表 1 相应的选项。

相关推荐:《Linux视频教程

The above is the detailed content of What is the command to check file permissions in Linux?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template