看看代码:
#!/bin/bash
read -p "Eneter 1 for UID and 2 for LOGNAME" choice
if [ $choice -eq 1 ]
then
read -p "Enter UID: " uid
logname=`cat /etc/passwd | grep $uid | cut -f1 -d:`
else
read -p "Enter Logname: " logname
fi
not=`ps -au$logname | grep -c bash`
echo "The number of terminals opened by $logname are $not"
Run Code Online (Sandbox Code Playgroud)
此代码用于查找用户在同一台 PC 上打开的终端数量。现在有两个用户登录,比如 x 和 y。我目前以 y 身份登录,用户 x 中打开了 3 个终端。如果我使用上面提到的不同方式在 y 中执行此代码,结果是:
$ ./file.sh
The number of terminals opened …Run Code Online (Sandbox Code Playgroud) 需要对.desktop文件的权限进行一些说明。我可以看到root拥有的所有.desktop文件/usr/share/applications/都有权限,
-rw-r--r--
Run Code Online (Sandbox Code Playgroud)
同时examples.desktop,在$HOME由用户拥有具有相同的权限。所有这些都运行正常。
但是当我要创建一个.desktop具有相同权限的自定义文件时,它会抛出以下错误消息,
不受信任的应用程序启动器
应用程序启动器“myapp.desktop”尚未标记为受信任。如果您不知道此文件的来源,启动它可能是不安全的。
但是添加执行权限可以让它毫无问题地运行。
问:为什么自定义
.desktop文件需要有+x权限才能运行,或者有些.desktop文件没有执行权限怎么能运行?是否可以在.desktop没有执行权限的情况下运行自定义文件?
我想我在这里误解了一些东西。我制作了一个简单的 python 测试文件来查看权限如何影响 python 文件的使用。我这样做是为了能够回答64bit ubuntu 12.04 python cannot run an existing python file
我已经制作了一个包含内容的 test.py 文件
print 'I am working'
Run Code Online (Sandbox Code Playgroud)
ls -al test.py
-rw-r--r-- 1 joey joey 25 Dec 24 11:11 test.py
python test.py
I am working
Run Code Online (Sandbox Code Playgroud)
chmod +x test.py?chmod 400 test.py
ls -al test.py
-r-------- 1 joey joey 25 Dec 24 11:11 test.py
python test.py
I am working
Run Code Online (Sandbox Code Playgroud)
所以显然python只需要读取权限才能执行我的文件?
chmod 200 test.py
ls -al test.py
--w------- …Run Code Online (Sandbox Code Playgroud)