bash: /bin/tar: 使用 tar 压缩许多文件时参数列表太长

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23817787/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 10:31:04  来源:igfitidea点击:

bash: /bin/tar: Argument list too long when compressing many files with tar

linuxbashtar

提问by Giancarlo Ventura Granados

I am trying compress files from an archive with the command

我正在尝试使用以下命令从存档中压缩文件

tar -czvf compress_file.tar.gz $(cat file_list.txt)

And I have an error

我有一个错误

-bash: /bin/tar: Argument list too long

The files numbers is too long, how can I resolve this?

文件编号太长,如何解决?

回答by Mark Setchell

Use the "-T" option to pass a file to tar that contains the filenames to tar up.

使用“-T”选项将包含要压缩的文件名的文件传递给 tar。

tar -cv -T file_list.txt -f tarball.tar

回答by user3648948

and how to make list of files to tar up: first ls > temp ## create the list of files to tar up then tar cvzf dicionario_ultra.tgz -X FILE -T temp and finally rm temp

以及如何制作要压缩的文件列表:首先 ls > temp ## 创建要压缩的文件列表,然后是 tar cvzf dicionario_ultra.tgz -X FILE -T temp,最后是 rm temp