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?
All options specified are passed directly to grep. If no file is specified, the standard input is decompressed if necessary and fed to grep. Otherwise, the given files are decompressed (if necessary) and fed to grep. If bzgrep is invoked as bzegrep or bzfgrep, egrep or fgrep is used instead of grep.
bz2 file is a Tar archive compressed with Bzip2. To extract a tar. bz2 file, use the tar -xf command followed by the archive name.
bzip2 command in Linux is used to compress and decompress the files i.e. it helps in binding the files into a single file which takes less storage space as the original file use to take. It has a slower decompression time and higher memory use.
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:
find . -type f -print0 | xargs -0 -n1 -P4 bzip2
To bzip2 on a multi-core Mac, you can issue the following command (when you're inside the folder you want to 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.
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
which bzip2
The output of that command is what you can replace
/opt/local/bin/bzip2
with
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With