Bz2 every file in a dir

Viewed 19818

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?

5 Answers

I have written below script to bzip2 files to another directory

#!/bin/bash
filedir=/home/vikrant_singh_rana/test/*

for filename in $filedir; do
name=$(basename "$filename" | sed -e 's/\.[^.]*$//')
bzip2 -dc $filename > /home/vikrant_singh_rana/unzipfiles/$name
done

my sample file name was like

2001_xyz_30Sep2020_1400-30Sep2020_1500.csv.bz2

I was not able to get any direct command, hence made this. This is working fine as expected.

Related