kir*_*iri 11 permissions executable
如何在不授予自己执行权限(具有chmod u+x)的情况下执行文件?
如果我尝试勾选“允许将文件作为程序执行”复选标记,则该复选标记会立即删除。
kir*_*iri 14
请在进一步操作之前执行此操作(除非您确定您拥有该文件)。
检查并确保您拥有要使用以下方法之一执行的文件。
在终端中执行此命令
[ ! -O "/path/to/file" ] && echo "You don't own the file"
Run Code Online (Sandbox Code Playgroud)
如果打印“ You don't own the file”,请参阅下面的“更改文件所有权”。
在终端中执行此命令
sudo chown $USER:$(id -gn $USER) "/path/to/file"
Run Code Online (Sandbox Code Playgroud)
答案我从发现评论通过Lekensteyn上回答了一个问题,关于chmod上,我认为值得它自己的问题和答案,充分肯定Lekensteyn NTFS分区。
对可执行文件使用此命令(替换/path/to/executable为正确的路径):
64位可执行文件:
/lib64/ld-linux-x86-64.so.2 /path/to/executable
Run Code Online (Sandbox Code Playgroud)
32位可执行文件:
/lib/ld-linux.so.2 /path/to/executable
Run Code Online (Sandbox Code Playgroud)
如果以上不起作用(或引发文件未找到错误),请尝试在上述命令之前使用它
cd "$(dirname /path/to/executable)"
Run Code Online (Sandbox Code Playgroud)
以上所有命令都不适用于基于文本的脚本(Bash、Python、Perl 等),请参见下文。
使用此命令可确定可执行文件是 32 x86( x86-64) 位还是 64 ( ) 位
objdump -f "$file" | grep '^architecture' | cut -d, -f1 | sed 's/architecture: //'
Run Code Online (Sandbox Code Playgroud)
如果它说i386:x86-64,那么它是 64 位。如果它只说i386,那么它是 32 位。
对于基于文本的脚本(Bash、Python、Perl 等),您应该使用#!文件第一行中指定的命令。
例如,如果文件的第一行是
#!/usr/bin/env python3
Run Code Online (Sandbox Code Playgroud)
然后在终端中运行这些命令(/path/to/file用正确的路径替换)
cd "$(dirname /path/to/file)" # Not strictly necessary, see section below
# Replace '/usr/bin/env python3' with the first line without the front #!
/usr/bin/env python3 /path/to/file # Use './file' if you want
Run Code Online (Sandbox Code Playgroud)
.jar文件对于 Java 可执行 jar,您可以简单地使用这些命令(替换/path/to/jar为正确的路径):
cd "$(dirname /path/to/jar)" # Not strictly necessary, see section below
java -jar /path/to/jar
Run Code Online (Sandbox Code Playgroud)
cd "$(dirname /path/to/file)"在使用cd "$(dirname /path/to/file)"任何方法运行程序之前,您不需要使用这些可能的情况:如果至少有一个为真,则您不需要cd首先使用。
apt-get)cd(或同等学历)更改为绝对路径做任何文件操作之前(例如:cd "$(dirname "$0")")./以斜杠开头或不以斜杠开头的路径)如果不确定,请添加cd "$(dirname "$0")"(或等效)到脚本的顶部(如果适用)或cd "$(dirname /path/to/file)"无论如何使用。