简体   繁体   English

如何从不同目录中归档特定文件?

[英]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.

相关问题 如何使用tar来存档不同目录结构的不同目录中的文件 - How to use tar to archive files from different directories without directory structure 如何从多个目录中提取多个文件,而不同目录中的不同文件可能具有相同的名称 - how to scp multiple files from multiple directories, while different files in different directories may have the same name 从tar归档中提取选定/特定文件会导致SunOS和Linux上的行为不同 - Extraction of selected/specific files from tar archive results in different behavior on SunOS and Linux 如何递归删除两个目录中的不同文件 - How to recursively remove different files in two directories 使用tar将文件从多个源目录收集到一个普通存档 - using tar to collect files from several source-directories to one plain archive 从文件中复制数据并粘贴到 Linux 中不同目录的文件中 - copy data from files and paste in files in different directories in Linux 使用 .tarignore 文件从 tar 存档中排除目录 - Exclude directories from tar archive with a .tarignore file 如何检查名称相同但扩展名不同的目录中的文件 - How to check files in different directories with same name but different extensions 从 Ansible Playbook 中删除服务器所有目录中的特定文件夹/文件 - Delete specific folder/files in all the directories of the server from the Ansible Playbook Linux-如何仅压缩包含特定文件的目录? - Linux - how can I tar only directories that contain specific files?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM