查找文件并将其tar(用空格) [英] Find files and tar them (with spaces)

查看:215
本文介绍了查找文件并将其tar(用空格)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这里简单的问题。我正在做一个简单的备份代码。它工作正常,除非文件中有空格。这是我如何找到文件,并将它们添加到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>会在您有大量文件时执行



另请参阅:


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 with xargs will do when you have a large number of files

Also see:

这篇关于查找文件并将其tar(用空格)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆