首页 > 其他分享 >[Bash] chmod and chown

[Bash] chmod and chown

时间:2024-05-19 15:40:24浏览次数:20  
标签:group stands permission chmod chown Bash file testfile

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

标签:group,stands,permission,chmod,chown,Bash,file,testfile
From: https://www.cnblogs.com/Answer1215/p/18200400

相关文章

  • [Bash] sed command
    Thesedcommandisastreameditorusedforfilteringandtransformingtext.sed'command'fileCreateandviewtheinitialcontentofsample.txt:echo-e"HelloWorld\nThisisasamplefile\nBashscriptingispowerful\nLearninggrep,aw......
  • 通过BASH脚本实现DNS优选
    02***/root/mysqlbeifen.sh*/10****/root/dns_update.sh#!/bin/bashLOG_DIR="/var/log/dns_script"HOST_FILE="/etc/hosts_NC"DOMAIN="sso.ccnhub.com"DNS_SERVER="114.114.114.114"#ReplacewithyourDN......
  • bash脚本监控服务器SSH登录,每30分钟运行一次,发现登录发送到企业微信群
    //开始循环检测//loopCheck();//在每分钟的第30秒执行目标函数cron.schedule('358***',()=>{console.log('目标函数在8:35执行!');loopCheck_info();//在这里调用你想要定时执行的函数});cron.schedule('*/309-20***',()=>{con......
  • [shell:bash] ubuntu_remove_old_kernel_test
    [shell:bash]  ubuntu_remove_old_kernel_test    一、基本信息 1、os:Linuxubuntu6.5.0-35-generic#35-UbuntuSMPPREEMPT_DYNAMICFriApr2611:23:57UTC2024x86_64x86_64x86_64GNU/Linux 2、bash:GNUbash,version5.2.......
  • Linux错误:-bash: Su: command not found
     问题:使用su命令出错:-bash:Su:commandnotfound 解决:先查看/etc/sudoers.d文件是否存在find/etc/sudoers.d说明系统已经安装了sudo,只不过没有配置环境。解决一:使用vi或vim以下命令打开/etc/sudoers文件。vim/etc/sudoers esc-->:......
  • root用户登陆ssh报错 /bin/bash: Permission denied
    CentOS7.5 ssh服务升级后,sshd服务状态正常,root用户登陆成功Xshell7(Build0157)Copyright(c)2020NetSarangComputer,Inc.Allrightsreserved.Type`help'tolearnhowtouseXshellprompt.[C:\~]$Connectingto127.0.0.1:XXXXX...Connectionestablished......
  • 在Linux中,什么是Bash脚本,并且如何使用它。
    Bash脚本是使用BashShell(BourneAgainSHell)语言编写的脚本文件,用于在Linux和类Unix系统上自动化执行一系列命令。Bash是Unix/Linux系统中最常用的Shell之一,它不仅支持基本的命令执行,还提供了丰富的编程结构,如变量、控制结构(如if条件判断、for和while循环)、函数、字符串操作、文......
  • bash文件书写学习记录
    参考资料:基于Bash脚本自己开发ROS的一键启动-古月居(guyuehome.com)#!/bin/bash和#!/usr/bin/envbash的区别-CSDN博客几种常见shell解释器(sh,bash,csh,tcsh,ash)以及bash的优点_bash与ash-CSDN博客 第一个链接对于bash文件的书写写的挺好的通俗易懂;  launch文件......
  • 使用Git bash切换Gitee、GitHub多个Git账号
    使用Gitbash切换Gitee、GitHub多个Git账号​ Git是分布式代码管理工具,使用命令行的方式提交commit、revert回滚代码。这里介绍使用Gitbash软件来切换Gitee、GitHub账号。​ 假设在gitee.com上的邮箱是[email protected]、用户名为alice;在github上的邮箱是[email protected]、......
  • linux bash 的使用
    运行test.shecho"test"默认情况下test.sh并没有运行权限,需要使用以下的命令:$chmod+xtest.sh变量var="runoob.com"##用语句赋值##forfilein`ls/etc`##或##forfilein$(ls/etc)##使用变量echo$varforskillinAdaCoffeActionJava;do......