UNIX,如何维护目录结构? [英] UNIX, how to maintain directory structure?
本文介绍了UNIX,如何维护目录结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从非空目录树 bar1
创建一个空目录结构 bar2
.bar1
和 bar2
都在同一层级.如何以有效的方式使用 mkdir
以便自动创建中间目录?
I want to create an empty directory structure bar2
from a nonempty directory tree bar1
.
Both bar1
and bar2
are at the same hierarchical level. How can I use mkdir
in an efficient manner so that intermediate directories are automatically created?
- 从 bar1 创建目录列表,并在必要时对其进行查找和排序.
- 使用
awk
,从列表中删除所有分支,这样我就可以只在叶子上运行 `mkdir. - 使用列表运行
mkdir
以复制 bar1 的目录结构
- To create a directory list from bar1 with find and order it if necessary.
- Using
awk
, remove all branches from the list so that I can run `mkdir only on the leaves. - Run
mkdir
with the list to replicate the directory structure of bar1
推荐答案
问题的难点(如何仅列出叶目录)是 之前问过SO.您可以在那里使用 find
/awk
组合并在每个结果上运行 mkdir -p
:
The hard part of your question (how to list only leaf directories) has been asked before on SO. You can use the find
/awk
combo there and run mkdir -p
on each result:
[bar1] $ find . -type d | sort | awk '$0 !~ last {print last} {last=$0} END {print last}' | xargs -Ix mkdir -p ../bar2/x
这篇关于UNIX,如何维护目录结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文