如何获取具有绝对路径的所有最低目录的列表?
我正在尝试复制目录结构(不是文件)以进行备份和迁移。我一直在搜索,但不太知道如何表达我的搜索以获得我想要的结果。我不断发现人们提到以下命令,第二个命令最接近我想要得到的命令。我需要确保它在 KSH 和 BASH 中运行。
ls -Rl |egrep '^d'
and
find / -type d -print
文件结构的示例以及我希望如何获取所有最低(?)目录及其完整路径前缀的列表。
/var/www
└── site
├── dir1
│ ├── dir11
│ ├── dir12
│ ├── dir13
│ │ └── dir131
│ └── dir14
├── dir2
└── dir3
├── dir31
└── dir32
└── dir321
├── dir3211
└── dir3212
##### Will generate the following list. #####
/var/www/site/dir1/dir11
/var/www/site/dir1/dir12
/var/www/site/dir1/dir13/dir131
/var/www/site/dir1/dir14
/var/www/site/dir2
/var/www/site/dir3/dir31
/var/www/site/dir3/dir32/dir321/3211
/var/www/site/dir3/dir32/dir321/3212
谢谢你,
低频4
I'm trying to copy a directory structure(not the files) for backup and migration. I've been searching all over but I don't quite know how to phrase my search to get the results I want. I keep finding people mentioning the following commands the second being closest to what I am trying to get. I need to make sure it runs in KSH and BASH.
ls -Rl |egrep '^d'
and
find / -type d -print
An example of the file structure and how I'd like to get a list of all the lowest(?) directories with their full path prefix.
/var/www
└── site
├── dir1
│ ├── dir11
│ ├── dir12
│ ├── dir13
│ │ └── dir131
│ └── dir14
├── dir2
└── dir3
├── dir31
└── dir32
└── dir321
├── dir3211
└── dir3212
##### Will generate the following list. #####
/var/www/site/dir1/dir11
/var/www/site/dir1/dir12
/var/www/site/dir1/dir13/dir131
/var/www/site/dir1/dir14
/var/www/site/dir2
/var/www/site/dir3/dir31
/var/www/site/dir3/dir32/dir321/3211
/var/www/site/dir3/dir32/dir321/3212
Thank you,
LF4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
执行 ls -R | grep ./ 将给出所有目录和子目录的列表,并且可以输入到其他内容中,该内容将为所有条目创建 mkdir 。
这假设您位于目录 /var/www/html 中。您可以更改 grep,以便使用 /var/www/html 或其他内容代替 ./。
Doing ls -R | grep ./ will give the list of all directories and subdirectories and could be fed into something else which will mkdir for all the entries.
This assumes you are in the directory /var/www/html. You could alter the grep so that instead of ./ it uses /var/www/html or whatever.