Off the top of my head (sorry, don't have a shell handy to test quoting etc.):
for _t in `find . -print |grep -v -E "\.bz$"`; do bzip2 -9 $_t && echo OK $_t || echo FAIL $_t; done
This uses find to find all files, grep to strip out the ones with a .bz2 extension and then feed them one at a time into bzip2. I expect some of the quoting is wrong, though - I'd test the bit in the backquotes separately first.
Good luck! You might want to use xz instead, though - it usually compresses better - or even tar everything up and bzip2 or xz instead.
This does the same as other answers, but you won't get warning messages about bzip2ing directories, and if there is nothing to bzip2 anymore, you won't get warning messages about bzip2ing compressed data to a terminal. It also uses xargs etc.
YOUR_DIR can have wild cards or multiple dirs, e.g. YOUR*DIR or the like.
find is your friend. I reckon the following ought to do it:
i.e. if the dir where the files you want to bzip are is /var/log/blah it would be:
Off the top of my head (sorry, don't have a shell handy to test quoting etc.):
This uses find to find all files, grep to strip out the ones with a .bz2 extension and then feed them one at a time into bzip2. I expect some of the quoting is wrong, though - I'd test the bit in the backquotes separately first.
Good luck! You might want to use xz instead, though - it usually compresses better - or even tar everything up and bzip2 or xz instead.
With zsh (
setopt extended_glob
must be on):**
recurses in subdirectories;^*.bz2
matches everything except*.bz2
;(.)
restricts to regular files.With bash 4, if you're ok with ignoring
bzip2
's complains about being invoked on directories:Here is a one liner. If necessary, install
ifne
first. On Ubuntu:And then:
This does the same as other answers, but you won't get warning messages about bzip2ing directories, and if there is nothing to
bzip2
anymore, you won't get warning messages about bzip2ing compressed data to a terminal. It also usesxargs
etc.YOUR_DIR can have wild cards or multiple dirs, e.g. YOUR*DIR or the like.
In the
fish
console, it's pretty straightforward, and you don't have to worry about pipes and weird backslashes: