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
1 个解决方案
#1
0
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. Be aware that this won't work with compressed tar archives.
使用--transform将文件即时重命名为所需格式。请注意,这不适用于压缩的tar档案。
#1
0
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. Be aware that this won't work with compressed tar archives.
使用--transform将文件即时重命名为所需格式。请注意,这不适用于压缩的tar档案。