search
HomeComputer TutorialsComputer KnowledgeFile permissions in Linux: Have you mastered the three types of read, write and execute?

File permissions in Linux: Have you mastered the three types of read, write and execute?

In the Linux system, file permissions play a key role, determining the user's access permissions and executable operations on files. This article will delve into the concept of Linux file permissions, different types of permissions, how to modify permissions, and frequently asked questions. It is suitable for readers with a certain Linux foundation.

The concept of file permissions

In Linux systems, each file has an owner and a group. File permissions are used to control user access rights to files, and are divided into three types: read, write, and execute. You can view the permission information of a file by using the command "ls -l".

$ ls -l file.txt
-rw-r--r-- 1 user user 0 May 16 2023 file.txt

In this example, we use the ls -l command to list the permissions and other information of the file.txt file. The first character - indicates that this is a normal file. The next 9 characters can be divided into 3 groups of 3 characters each. The first group rw- indicates that the owner has read and write permissions, the second group r– indicates that group users only have read permissions, and the third group r– indicates that other users also only have read permissions.

Permission type

Read permission

Read permissions allow the user to view the file contents, ensuring the user has the appropriate permissions to access the file.

$ chmod +r file.txt # 允许所有用户读取文件
$ chmod u-r file.txt# 取消所有者的读取权限
$ chmod g+r file.txt# 允许组用户读取文件

In this example, we use the chmod command to set the read permission of the file. r means to add read permission, u-r means to cancel the owner's read permission, and gr means to allow group users to read the file.

Write Permission

Write permission allows the user to edit the file contents. No write permission will restrict modifications. The following example shows setting file write permissions.

$ chmod +w file.txt # 允许所有用户写入文件
$ chmod u-w file.txt# 取消所有者的写入权限
$ chmod g+w file.txt# 允许组用户写入文件

In this example, we use the chmod command to set the write permissions of the file. w means to add write permissions, u-w means to remove the owner's write permissions, and g w means to allow group users to write files.

Execution permission

Execute permissions allow users to run specific files in the system. Not having execute permission prevents the user from running the file.

$ chmod +x file.txt # 允许所有用户运行文件
$ chmod u-x file.txt# 取消所有者的执行权限
$ chmod g+x file.txt# 允许组用户运行文件

In this example, we use the chmod command to set the execution permissions of the file. x means to add execution permissions, u-x means to remove the owner's execution permissions, and g x means to allow group users to run the file.

Permission modification

In Linux, we can use the chmod command to modify the permissions of files. Here is an example showing how to set permissions on a file:

$ chmod u+rwx file.txt# 允许所有者读写执行文件
$ chmod g+rw file.txt # 允许组用户读写文件
$ chmod o-rwx file.txt# 禁止其他用户读写执行文件

In this example, we use the chmod command to set the permissions of the file. u rwx indicates that the owner is allowed to read and write the executable file, g rw indicates that group users are allowed to read and write the file, and o-rwx indicates that other users are prohibited from reading and writing the executable file.

common problem

How to check the permissions of the current user?

To view the permissions of the current user, run the following command:

$ id

This command will display the UID and GID of the current user, as well as the group to which it belongs.

How to change the owner and group of a file?

To change the owner and group of a file, run the following command:

$ chown new_owner file.txt
$ chgrp new_group file.txt

These commands will change the file's owner and group respectively.

How to check the owner and group of a file?

To view the owner and group of a file, run the following command:

$ ls -l file.txt

In the output, column 3 is the owner of the file and column 4 is the group of the file.

How to set default permissions?

To set the default permissions of a file, use the umask command. This command allows you to set a default permission mask to use when creating new files. Here is an example:

$ umask 022# 设置默认权限掩码为022

In this example, we set the default permission mask to 022. This means that the permissions of the new file will be rw-r–r–.

in conclusion

In Linux, file permissions are one of the very important concepts. It determines which users can access the file and what operations can be performed. This article describes permission types, permission modifications, and common issues. We hope readers can master the concept and usage of file permissions in Linux.

The above is the detailed content of File permissions in Linux: Have you mastered the three types of read, write and execute?. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:每日运维. If there is any infringement, please contact admin@php.cn delete
[Fixed] You Need to Authenticate Microsoft Services in Minecraft? - MiniTool[Fixed] You Need to Authenticate Microsoft Services in Minecraft? - MiniToolApr 27, 2025 am 12:51 AM

In this post, php.cn provides several effective solutions to the “you need to authenticate to Microsoft services” issue in Minecraft on the PC. If you get stuck in this issue, you should pay attention to this post.

Top 4 Fixes for High Power Usage in Task ManagerTop 4 Fixes for High Power Usage in Task ManagerApr 27, 2025 am 12:49 AM

In Task Manager, you can view how much power the processes on your computer use. What if you receive high power usage in Task Manager constantly?  In this post from php.cn Website, we will explore how to address this issue easily and effectively.

2 Windows Folders in C Drive: How to Deal with Them?2 Windows Folders in C Drive: How to Deal with Them?Apr 27, 2025 am 12:48 AM

The Windows folder contains the Windows operating system and is a crucial folder in Windows computers. Sometimes, you may see 2 Windows folders in the C drive. How to delete one of them? This post from php.cn tells you how to do that.

Top 4 Halo Infinite Trackers to Track KD, Stats, Ranks, and More! - MiniToolTop 4 Halo Infinite Trackers to Track KD, Stats, Ranks, and More! - MiniToolApr 27, 2025 am 12:47 AM

Many people are looking for a feasible Halo Infinite tracker. In this post, php.cn introduces several available Halo Infinite trackers to help you track the Halo Infinite KD, ranks, stats, etc. Now, keep on your reading.

10 Best Google Sheets Add-ons You Must Have - MiniTool10 Best Google Sheets Add-ons You Must Have - MiniToolApr 27, 2025 am 12:46 AM

Have you ever heard of Google Sheets add-ons? Do you have any idea how to install them in your Google Sheets? Do you want to get the best and the free Google Sheets add-ons? This article on php.cn focuses on these questions and provides you with seve

Enable/Disable Ctrl Alt Delete Secure Sign-In on Windows 11 - MiniToolEnable/Disable Ctrl Alt Delete Secure Sign-In on Windows 11 - MiniToolApr 27, 2025 am 12:45 AM

Secure Sign-In is a handy way to keep your PC safe, but if you don't want it around, here's how to disable it for Windows 11. This post from php.cn provides 3 ways for you to enable or disable Ctrl Alt Delete secure sign-in on Windows 11.

How to Fix Word Dictation Not Working Issue in Windows 10 - MiniToolHow to Fix Word Dictation Not Working Issue in Windows 10 - MiniToolApr 27, 2025 am 12:44 AM

Have you ever heard of Microsoft Word dictation? What if Word dictation not working? This post from php.cn shows you the basic information about Word dictation and some feasible ways to fix the “Word dictation not working” issue.

What Is Atlas VPN? How to Free Download Atlas VPN for Use? - MiniToolWhat Is Atlas VPN? How to Free Download Atlas VPN for Use? - MiniToolApr 27, 2025 am 12:43 AM

What is Atlas VPN used for? Is Atlas VPN safe? Can you use Atlas VPN for free? How to download Atlas VPN & install it on your device for use? Refer to this post from php.cn and you can find details about this VPN service and Atlas VPN download fo

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.