小编mus*_*usa的帖子

为什么未设置可执行位时root不能执行?

root即使未设置权限,用户也可以写入文件write

root即使未设置权限,用户也可以读取文件read

root即使未设置权限,用户也可以 cd进入目录execute

root未设置权限时,用户无法执行文件execute

为什么?

user$ echo '#!'$(which bash) > file
user$ chmod 000 file
user$ ls -l file
---------- 1 user user 12 Jul 17 11:11 file
user$ cat file                      # Normal user cannot read
cat: file: Permission denied
user$ su
root$ echo 'echo hello' >> file     # root can write
root$ cat file                      # root can read …
Run Code Online (Sandbox Code Playgroud)

bash root permissions executable

27
推荐指数
1
解决办法
5328
查看次数

取消引用硬链接

tar命令的手册页中,列出了跟踪硬链接的选项。

-h, --dereference
      follow symlinks; archive and dump the files they point to

--hard-dereference
      follow hard links; archive and dump the files they refer to
Run Code Online (Sandbox Code Playgroud)

如何tar知道文件是硬链接?它是如何遵循的

如果我不选择这个选项怎么办?它是如何硬解引用?

tar hard-link

26
推荐指数
2
解决办法
9755
查看次数

什么不是特定于 shell 的?

在一些答案下,我看到建议避免在答案中使用特定于 shell 的命令的评论。

我如何知道所有 shell 中存在哪些命令、运算符等?有标准清单吗?

  • man builtins给出命令列表。这些是我可以在适用于所有 shell 的便携式 shell 脚本中使用的唯一命令吗?
  • 内置可以是特定于外壳的吗?
  • Linux 的标准是否与其他 Unix 的标准不同?
  • 语法呢?某些 shell 中的标点符号、运算符等可以不同吗?

linux command-line shell standard shell-builtin

9
推荐指数
2
解决办法
445
查看次数

将选项卡完成可能性保存到文件

而不是在终端屏幕上显示所有可能性,如:

$ ls /etc/<TAB>
Display all 230 possibilities? (y or n)
Run Code Online (Sandbox Code Playgroud)

我想将所有可能性保存到一个文件中。

ls /etc/ > file.txt不会总是有效。apt-get 就是一个例子:

$ apt-get <TAB>
autoclean        check            install          update
autoremove       clean            purge            upgrade
build-dep        dist-upgrade     remove           
changelog        dselect-upgrade  source           
Run Code Online (Sandbox Code Playgroud)

我正在寻找类似tabcompletions 'ls /etc/'输出所有可能性的命令,以便我可以运行如下命令,该命令比较两个命令的选项卡完成可能性:

diff <(tabcompletions 'ls ') <(tabcompletions 'cd ')
Run Code Online (Sandbox Code Playgroud)

那可能吗?

bash autocomplete

6
推荐指数
1
解决办法
948
查看次数

删除重定向运算符不会更改输出。为什么?

我在某处看到了这种重定向的用法,并认为这是一个错字:

grep root < /etc/passwd
Run Code Online (Sandbox Code Playgroud)

但是在我运行它之后,我看到它给出了与以下相同的输出 grep root /etc/passwd

$ grep root < /etc/passwd
root:x:0:0:root:/root:/bin/bash

$ grep root   /etc/passwd
root:x:0:0:root:/root:/bin/bash
Run Code Online (Sandbox Code Playgroud)

同样的事情发生在

cat < /etc/passwd
cat   /etc/passwd
Run Code Online (Sandbox Code Playgroud)

但是,与 一起使用时,重定向将被忽略ls

ls < /etc/passwd
Run Code Online (Sandbox Code Playgroud)

不打印相同的输出

ls  /etc/passwd
Run Code Online (Sandbox Code Playgroud)

怎么了?

command-line shell bash io io-redirection

3
推荐指数
1
解决办法
420
查看次数