Júnior Júnior - 1 year ago 103
Bash Question

Compress multiple files individually with 7zip

Searching I noticed that it was possible to compress several files individually by gzip. Unfortunately this format is not useful to me.

I tried to compose with the following command.

Find. -type f -name "* .txt" -exec 7z {} \;


Answer Source

To add a file to archive, you should use "a" command: 7z a archive.7z file. So your command should be like this:

find . -type f -name "*.txt" -exec 7z a $(basename {}).7z {} \;

or, if you want archive names like ".txt.7z",

find . -type f -name "*.txt" -exec 7z a {}.7z {} \;

basename here is to get your file name without extension.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download