查找文件并将其tar(用空格) [英] Find files and tar them (with spaces)
本文介绍了查找文件并将其tar(用空格)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
find。 -type f | xargs tar -czvf backup.tar.gz
问题是文件在名称中有一个空格因为tar认为它是一个文件夹。基本上有一种方法可以在查找结果周围添加引号?或者用不同的方法解决这个问题?
解决方案
使用这个:
find。 -type f -print0 | tar -czvf backup.tar.gz --null -T -
它会:
$ b
- 处理空格,换行符,大破折号和其他趣味的文件
- 处理无限数量的文件
- 不会像使用
tar -c
和xargs $>一样重复覆盖backup.tar.gz c $ c>会在您有大量文件时执行
另请参阅:
a>
Alright, so simple problem here. I'm working on a simple back up code. It works fine except if the files have spaces in them. This is how I'm finding files and adding them to a tar archive:
find . -type f | xargs tar -czvf backup.tar.gz
The problem is when the file has a space in the name because tar thinks that it's a folder. Basically is there a way I can add quotes around the results from find? Or a different way to fix this?
解决方案
Use this:
find . -type f -print0 | tar -czvf backup.tar.gz --null -T -
It will:
- deal with files with spaces, newlines, leading dashes, and other funniness
- handle an unlimited number of files
- won't repeatedly overwrite your backup.tar.gz like using
tar -c
withxargs
will do when you have a large number of files
Also see:
- GNU tar manual
- How can I build a tar from stdin?, search for null
这篇关于查找文件并将其tar(用空格)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文