从不同目录中的同名文件制作存档
我有一些名称相同但位于不同目录下的文件。例如,path1/filea、path1/fileb、path2/filea、path2/fileb、...
将文件归档的最佳方法是什么?在这些目录下,还有许多其他文件我不想归档。我突然想到使用 Bash,可能是 ar、tar 和其他命令,但不知道具体该怎么做。
重命名文件似乎使文件名有点复杂。我倾向于将目录结构保留在存档中。或者我可能错了。欢迎其他想法!
谢谢和问候!
编辑:
例子真的很好!
I have some files with same names but under different directories. For example, path1/filea, path1/fileb, path2/filea, path2/fileb,....
What is the best way to make the files into an archive? Under these directories, there are many other files under these directories that I don't want to make into the archive. Off the top of my head, I think of using Bash, probably ar, tar and other commands, but am not sure how exactly to do it.
Renaming the files seems to make the file names a little complicated. I tend to keep the directory structure inside the archive. Or I might be wrong. Other ideas are welcome!
Thanks and regards!
EDIT:
Examples would be really nice!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以将
tar
与--exclude PATTERN
选项一起使用。有关更多信息,请参阅手册页。要排除文件,您可以参阅此页面获取示例。
you can use
tar
with--exclude PATTERN
option. See the man page for more.To exclude files, you can see this page for examples.
您可以给 find 命令指定多个目录来搜索。
You may give the find command multiple directories to search through.
要仅将文件名为“filea”或“fileb”的文件从 /path/to/source 递归复制到 /path/to/archive,您可以使用:
'*/'
是匹配“任意目录”的模式'隐藏,! */'
表示隐藏所有文件--include='file[ab]'
具有优先权,因此如果文件与'file[ab]'
匹配,则会包含该文件。任何其他文件都会从要传输的文件列表中排除。
Another alternative is to use the
find...exec
pattern:To recursively copy only files with filename "filea" or "fileb" from /path/to/source to /path/to/archive, you could use:
'*/'
is a pattern which matches 'any directory''! */'
matches anything which is not a directory (i.e. a file)'hide,! */'
means hide all files--include='file[ab]'
has precedence, so if a file matches'file[ab]'
, it is included.Any other file gets excluded from the list of files to transfer.
Another alternative is to use the
find...exec
pattern:我用来为不同目录中具有相同名称的文件制作 tar 球的方法是
希望这会有所帮助。
What I have used to make a tar ball for the files with same name in different directories is
Hope this helps.