如何以递归方式将文件以及所有子目录添加(或触摸)到当前目录中?
例如,
我想打开这个目录树:
.
├── 1
│ ├── A
│ └── B
├── 2
│ └── A
└── 3
├── A
└── B
└── I
9 directories, 0 files
进入
.
├── 1
│ ├── A
│ │ └── file
│ ├── B
│ │ └── file
│ └── file
├── 2
│ ├── A
│ │ └── file
│ └── file
├── 3
│ ├── A
│ │ └── file
│ ├── B
│ │ ├── file
│ │ └── I
│ │ └── file
│ └── file
└── file
9 directories, 10 files
怎么样:
find . -type d -exec cp file {} \;
来自man find
:
-type c
File is of type c:
d directory
-exec command ;
Execute command; All following arguments to find are taken
to be arguments to the command until an argument consisting
of `;' is encountered. The string `{}' is replaced by the
current file
因此,上面的命令将找到所有目录并cp file DIR_NAME/
在每个目录上运行。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句