知道为什么会有不同的输出。其中一些具有误导性
-bash-4.2$ mkdir -p new_dir/sub_dir/under_dir
-bash-4.2$ touch new_dir/sub_dir/under_dir/file.txt
-bash-4.2$
-bash-4.2$ ls -rlt
total 4
drwxrwxr-x 3 kony kony 4096 Oct 21 20:53 new_dir
-bash-4.2$
-bash-4.2$
-bash-4.2$ ls -rlt *
total 4
drwxrwxr-x 3 kony kony 4096 Oct 21 20:53 sub_dir
-bash-4.2$
-bash-4.2$
-bash-4.2$
-bash-4.2$ ls -rltd
drwxrwxr-x 3 kony kony 4096 Oct 21 20:53 .
-bash-4.2$
-bash-4.2$
-bash-4.2$ ls -rltd *
drwxrwxr-x 3 kony kony 4096 Oct 21 20:53 new_dir
-bash-4.2$
-bash-4.2$
-bash-4.2$
-bash-4.2$ ls -rtlR
.:
total 4
drwxrwxr-x 3 kony kony 4096 Oct 21 20:53 new_dir
./new_dir:
total 4
drwxrwxr-x 3 kony kony 4096 Oct 21 20:53 sub_dir
./new_dir/sub_dir:
total 4
drwxrwxr-x 2 kony kony 4096 Oct 21 20:53 under_dir
./new_dir/sub_dir/under_dir:
total 0
-rw-rw-r-- 1 kony kony 0 Oct 21 20:53 file.txt
-bash-4.2$
-bash-4.2$
-bash-4.2$
-bash-4.2$
-bash-4.2$ ls -rltR *
new_dir:
total 4
drwxrwxr-x 3 kony kony 4096 Oct 21 20:53 sub_dir
new_dir/sub_dir:
total 4
drwxrwxr-x 2 kony kony 4096 Oct 21 20:53 under_dir
new_dir/sub_dir/under_dir:
total 0
-rw-rw-r-- 1 kony kony 0 Oct 21 20:53 file.txt
-bash-4.2$
我不知道您期望得到什么输出,也不知道会误导您。您得到不同的输出,因为每次都提供不同的输入。
相关事实:
ls
没有操作数的情况就像唯一的操作数是一样.
。请注意-rltd
,此类是选项,而不是操作数。ls
则将在该目录中打印条目。这是一种特殊的处理方式,因为在大多数情况下(如果操作数是常规文件,特殊文件,fifo等),ls
仅显示有关操作数的信息。-d
对目录禁用此特殊行为。-R
使ls
递归列出遇到的子目录。*
在您的示例中ls
,甚至在开始之前就已通过Shell对其进行了扩展。*
扩展到名称不以开头的当前工作目录中的所有条目.
。显然,在您的情况下,当前目录中只有一个匹配的条目:new_dir
。这些是您键入的命令,为了便于阅读,我收集了它们:
ls -rlt
ls -rlt *
ls -rltd
ls -rltd *
ls -rltR
ls -rltR *
这些是您通过shell扩展后真正运行的;分别:
ls -rlt
ls -rlt new_dir
ls -rltd
ls -rltd new_dir
ls -rltR
ls -rltR new_dir
这些是带有显式操作数的等效命令。分别:
ls -rlt .
ls -rlt new_dir
ls -rltd .
ls -rltd new_dir
ls -rltR .
ls -rltR new_dir
这些是描述性查询(通用选项-rlt
未解释,因为我知道它们不是问题):
ls -rlt .
–里面是什么.
?ls -rlt new_dir
–里面是什么new_dir
?ls -rltd .
–什么.
?ls -rltd new_dir
–什么new_dir
?ls -rltR .
–内部.
以及遇到的每个子目录是什么?ls -rltR new_dir
–内部new_dir
以及遇到的每个子目录是什么?您得到了这些查询的答案。查询是不同的,答案也是如此。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句