[英]how to archive specific files from the different directories?
Actually I have a file in my linux that is very important to me, the name of this file is yz.tmp
So, I want to search all directories and archive them,how is it possible ? 其实我的Linux中有一个文件对我来说很重要,这个文件的名称是
yz.tmp
所以,我想搜索所有目录并将其归档,这怎么可能?
first I find all of them via this command : 首先,我通过以下命令找到所有这些对象:
find . -name "yz.tmp"
now how can I archive them without directory? 现在如何在没有目录的情况下归档它们? like this:
像这样:
yz01.tmp
yz02.tmp
.
.
.
yz100.tmp
This appends the files one by one to an uncompressed tar archive test.tar
: 这会将文件一个接一个地附加到未压缩的tar归档文件
test.tar
:
#!/bin/bash
i=1
for file in $(find . -name 'yz.tmp'); do
NEW_NAME=$(printf "yz%03d.tmp" $i)
tar rf test.tar --transform "s,.*,$NEW_NAME," "$file"
i=$(($i+1))
done
Using --transform
renames the files on-the-fly into your desired format. 使用
--transform
将文件重命名为所需的格式。 Be aware that this won't work with compressed tar archives. 请注意,这不适用于压缩的tar存档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.