LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Convert many files to individual .bz2 files retaining original name? (https://www.linuxquestions.org/questions/linux-newbie-8/convert-many-files-to-individual-bz2-files-retaining-original-name-798544/)

touser 03-28-2010 11:08 PM

Convert many files to individual .bz2 files retaining original name?
 
Hello everyone, i have a large directory of .bsp files that i would like to convert .bz2 archives. I've been searching for some time and all i can find is the obvious compress multiple files into one large archive. If anyone knows how to convert each file individually, while retaining the original file name (testmap.bsp would be archived as testmap.bsp.bz2) Any help is greatly appreciated!

pixellany 03-28-2010 11:15 PM

In the appropriate directory:
Code:

for filname in *.bsp; do
    <command to make a bz2> $filname $filname.bz2
done


robertstar20 03-28-2010 11:16 PM

What's wrong with:

$ bzip2 large_directory/*

?

touser 03-28-2010 11:21 PM

Wow, thank you for the quick response! That was far simpler than i expected, thanks for making me feel stupid haha :)

pixellany 03-28-2010 11:27 PM

Quote:

Originally Posted by robertstar20 (Post 3916165)
What's wrong with:

$ bzip2 large_directory/*

?

Nothing----except that it deletes the uncompressed version of the files and chokes when it comes to a directory. It's also "brute force"--ie it blindly converts everything in sight.

touser 03-29-2010 12:58 AM

This seems to do the trick without any errors:

Code:

for filname in *.bsp; do
    bzip2 -k $filname
done

I also found that:

Code:

find . -name "*.bsp" | xargs bzip2 -k
also works, although i figure that is going to be more system intensive. Thanks again for the help guys!


All times are GMT -5. The time now is 07:24 PM.