回顾 UNIX 中的文件权限概念 [英] review file permissions concept in the UNIX

查看:27
本文介绍了回顾 UNIX 中的文件权限概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

umask 设置为 022,创建的文件权限为 -rw- r-- r--,即 644.我用这种方式制作了一个文件

the umask is set to 022 and the created files permission would be -rw- r-- r-- which is 644. the I made a file in this way

echo date > date.sh
./date.sh

运行代码后,我会得到错误权限被拒绝,但如果我使用 sh 命令调用该文件

after running the code I will get the error permission denied but if I call the file by using sh command

sh date.sh

它有效.

我最近开始练习 UNIX,想知道为什么会这样.

I have started practicing UNIX recently and was wondering why it happens.

推荐答案

您尚未设置可执行位,因此 UNIX 不会运行该文件.但是,sh 实用程序是可执行的,并且可以执行 date.sh 的内容,而不管其权限如何.

You've not set the executable bit, so UNIX won't run the file. The sh utility is executable, however, and can execute the contents of date.sh regardless of its permissions.

您可以使用以下命令将文件设置为可执行文件:$ chmod +x date.sh

You can set the file as executable with: $ chmod +x date.sh

$ ls -l观察date.sh的权限,你会看到它现在对所有人都可以执行(-rwxrwxr-x).

Observe the permissions of date.sh with $ ls -l, and you'll see that it's now executable for everyone (-rwxrwxr-x).

这篇关于回顾 UNIX 中的文件权限概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆