Linux Bz2 目录中的每个文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6851550/
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
Bz2 every file in a dir
提问by Steven Kull
I am running centos and I have around 1,300 files in a folder that each need to be bzipped individually. What would be the easiest way of handing this?
我正在运行 centos,我在一个文件夹中有大约 1,300 个文件,每个文件都需要单独进行 bzip 压缩。处理这个问题的最简单方法是什么?
采纳答案by sagi
If all the files are in a single directory then:
如果所有文件都在一个目录中,则:
bzip2 *
Is enough. A more robust approach is:
足够。更稳健的方法是:
find . -type f -exec bzip2 {} +
Which will compress every file in the current directory and its sub-directories, and will work even if you have tens of thousands of files (using * will break if there are too many files in the directory).
这将压缩当前目录及其子目录中的每个文件,即使您有数万个文件也能工作(如果目录中的文件太多,使用 * 会中断)。
If your computer has multiple cores, then you can improve this further by compressing multiple files at once. For example, if you would like to compress 4 files concurrently, use:
如果您的计算机有多个内核,那么您可以通过一次压缩多个文件来进一步改进这一点。例如,如果您想同时压缩 4 个文件,请使用:
find . -type f -print0 | xargs -0 -n1 -P4 bzip2
回答by Carlos Campderrós
From inside the directory: bzip2 *
从目录内部: bzip2 *
回答by Carlos Campderrós
find PATH_TO_FOLDER -maxdepth 1 -type f -exec bzip2 -zk {} \;
回答by Shaheen Ghiassy
To bzip2 on a multi-core Mac, you can issue the following command (when you're inside the folder you want to bzip)
要在多核 Mac 上使用 bzip2,您可以发出以下命令(当您在要 bzip 的文件夹中时)
find . -type f -print0 | xargs -0 -n1 -P14 /opt/local/bin/bzip2
This will bzip every file recursively inside the folder your terminal is in using 14 CPU cores simultaneously.
这将在您的终端所在的文件夹中递归地 bzip 每个文件同时使用 14 个 CPU 内核。
You can adjust how many cores to use by editing
您可以通过编辑来调整要使用的核心数
-P14
If you don't know where the bzip2 binary is, you can issue the following command to figure it out
如果你不知道 bzip2 二进制文件在哪里,你可以发出以下命令来弄清楚
which bzip2
The output of that command is what you can replace
该命令的输出是您可以替换的内容
/opt/local/bin/bzip2
with
和