我逐渐熟悉Linux(Debian 9)。但是我设法使自己对ls
命令手册感到困惑。我对测试进行了以下简单设置:
meouser:~/triv_dir$ ls -laR
.:
total 24
drwxr-xr-x 4 meouser meouser 4096 Mar 27 15:42 .
drwxr-xr-x 19 meouser meouser 4096 Mar 27 15:41 ..
drwxr-xr-x 4 meouser meouser 4096 Mar 27 15:55 a
drwxr-xr-x 2 meouser meouser 4096 Mar 27 15:42 b
-rw-r--r-- 1 meouser meouser 6 Mar 27 15:44 c
-rw-r--r-- 1 meouser meouser 6 Mar 27 15:44 d
./a:
total 24
drwxr-xr-x 4 meouser meouser 4096 Mar 27 15:55 .
drwxr-xr-x 4 meouser meouser 4096 Mar 27 15:42 ..
-rw-r--r-- 1 meouser meouser 4 Mar 27 15:50 aa
-rw-r--r-- 1 meouser meouser 4 Mar 27 15:50 ab
drwxr-xr-x 2 meouser meouser 4096 Mar 27 15:55 a_sub_1
drwxr-xr-x 2 meouser meouser 4096 Mar 27 15:55 a_sub_2
./a/a_sub_1:
total 12
drwxr-xr-x 2 meouser meouser 4096 Mar 27 15:55 .
drwxr-xr-x 4 meouser meouser 4096 Mar 27 15:55 ..
-rw-r--r-- 1 meouser meouser 4 Mar 27 15:55 aaa
./a/a_sub_2:
total 8
drwxr-xr-x 2 meouser meouser 4096 Mar 27 15:55 .
drwxr-xr-x 4 meouser meouser 4096 Mar 27 15:55 ..
./b:
total 16
drwxr-xr-x 2 meouser meouser 4096 Mar 27 15:42 .
drwxr-xr-x 4 meouser meouser 4096 Mar 27 15:42 ..
-rw-r--r-- 1 meouser meouser 4 Mar 27 15:50 ba
-rw-r--r-- 1 meouser meouser 4 Mar 27 15:50 bb
我想查看所有目录名称及其子目录,但看不到文件名。也就是说,我想要类似ls --insert-options-here
的东西,以便输出是上面的这个子集:
.:
total 24
drwxr-xr-x 4 meouser meouser 4096 Mar 27 15:42 .
drwxr-xr-x 19 meouser meouser 4096 Mar 27 15:41 ..
drwxr-xr-x 4 meouser meouser 4096 Mar 27 15:55 a
drwxr-xr-x 2 meouser meouser 4096 Mar 27 15:42 b
./a:
total 24
drwxr-xr-x 4 meouser meouser 4096 Mar 27 15:55 .
drwxr-xr-x 4 meouser meouser 4096 Mar 27 15:42 ..
drwxr-xr-x 2 meouser meouser 4096 Mar 27 15:55 a_sub_1
drwxr-xr-x 2 meouser meouser 4096 Mar 27 15:55 a_sub_2
根据ls
手册,该手册应由ls -ldR
完成。
meouser:~/triv_dir$ man ls
-a, --all
do not ignore entries starting with .
-d, --directory
list directories themselves, not their contents
-l use a long listing format
-R, --recursive
list subdirectories recursively
但这是相反的情况:仅显示'.'
。
meouser:~/triv_dir$ ls -ldR
drwxr-xr-x 4 meouser meouser 4096 Mar 27 15:42 .
手册中我缺少什么?
我从https://stackoverflow.com/a/29277454/11199684注意到,这可以通过以下方法实现
find . -maxdepth 2 -type d -print
这令人印象深刻,但是它提供的信息少于上面的ls输出。此外,我可能事先不知道正确的最大深度?最重要的是,对于将来的需求,我实际上对从手册中自我介绍很有兴趣。意见表示赞赏。
答案 0 :(得分:2)
-d
选项适用于作为输入提供的[FILE]
,在您的情况下,由于未给出输入,您将退回到默认目录:当前目录。递归不适用,因为没有目录返回。
要使用ls
命令获得与find
相同的输出,可以将它们组合在一起:
find . -type d -exec ls -ld {} \;