[Bash] chmod and chown

Understanding File Permissions:
File permissions in Unix-like systems determine who can read, write, or execute a file. They are represented as a combination of three groups: user (u), group (g), and others (o).

-rwxr-xr--

r stands for read permission.
w stands for write permission.
x stands for execute permission.

chmod

chmod: Change file permissions.

chmod 755 filename

touch testfile
ls -l testfile

# Change the file permissions to make it executable by the owner and readable by everyone:
chmod 744 testfile
ls -l testfile

# Change the file permissions using symbolic notation:
chmod u+x,g+r,o=r testfile
ls -l testfile

Explain

Explanation of chmod u+x,g+r,o=r testfile
The chmod command is used to change the permissions of a file or directory. The syntax of the command includes specifying the users (user, group, others), the operation (add, remove, set), and the permissions (read, write, execute).

u stands for "user" (the owner of the file).

g stands for "group" (the group to which the file belongs).

o stands for "others" (everyone else).

  • means adding a permission.

= means setting a permission explicitly.

r stands for "read" permission.

w stands for "write" permission.

x stands for "execute" permission.

Command Breakdown:
u+x: Add execute permission for the user (file owner).
g+r: Add read permission for the group.
o=r: Set read permission for others (removes any other permissions for others).

Chown

chown: Change file owner and group.

chown [owner][:group] file

# Change the owner of testfile to yourusername:
chown $USER testfile
# > -rwxr--r--  1 zhentianwan  staff  0 May 19 10:35 testfile

# Change the owner and group of testfile:
chown $USER:Staff testfile
posted @   Zhentiw  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2022-05-19 [Spring Data JPA] Derived Query Methods
2021-05-19 [AWS] DynamoDB: Designing Partition Keys to Distribute Your Workload Evenly
2020-05-19 [Cypress] Change a viewport width and height in a cypress test
2020-05-19 [SCSS] Access Theme Color Values With Sass
2019-05-19 [Spring Boot] Using @Around advice to implement performance tracing and @Pointcut for custom Annotation
2017-05-19 [AngularJS] Directive for top scroll bar
点击右上角即可分享
微信分享提示