using tar command to zip files - bash

tar -czf "/var/log/VirusVault/VirusFound_${Current_Date}.zip" -C "/var/log/VirusVault" "VirusFound_${Current_Date}" --remove-files

I couldn’t get zip to work with folders. So, I made this command. However, it creates a double layer compressed file. Can someone explain why it’s doing this?

I need the ability to compress as zip and other formats.

Maybe you should try to interprete

man tar

I did not even try to understand what exactly you are trying, but I find nowhere in the man page of tar a -C mentioned.

‘--directory=dir’
‘-C dir’
When this option is specified, tar will change its current directory to dir before performing any operations.

What tar definitely does not support is zip archives.

Yes, you are correct. I apologize. I tried with the the search functionality on the HTML page version of the man page, but should have made that case sensitive. Now I missed it :(.

I should not have answered this post because I never ventured further into tar then the traditional usage. Using in fact only a subset of the command characters like c, x, f and v. Nowadays I do use z, but was used to piping through the compressing tool of choice.

I can install the ‘zip’ command with Yast. It functions better, but I has to be installed. ‘gzip’ won’t work. I need a structured folder. Winrar linux also does this type.

Is there anyway to structure the ‘tar’ command to make it single level zip file?

What do you mean with “single level” and “double level” zip files. Please show computer facts instead of self invented expressions.

Why not? gzip is Linux “own” program to compress things (together with bzip2) while zip is more a Windows thing.

tar is not something that compresses things although it can do it as additional step, tar is a program to pack multiple files together.

Multi-level=nested zip files

file1.zip (click) –>

file2.zip (uncompressed - click to open the uncompressed file)

tar -czf "/root/bin/VirusFound.zip" -C "/root/bin" "VirusFound" --remove-files

If you run this command with some text files in the folder, you need to click once to open the zip and click the zip inside the zip file to get the folder.

tar does not create ZIP archives. Naming file “something.zip” does not make it ZIP archive.

‘gzip’ won’t do structured nested/multi-level folders. ‘tar’ will with this command with the double zip storage. ‘gzip’ will only compress all the files in those nested folders. The ‘zip’ (installed) command will do it.

‘gzip’ can’t do a structured folders. So far, no webpages tell me how to that with gzip. ( ‘-’ tr ’ [space]’ )

folder1
--------folder2
file1
--------folder3
file2
folder4
--------folder5
file3
--------folder6
file4

Probably relevant for this: The Unix Tools Philosophy

Yes, gzip can compress only one file, tar primary usage is to store multiple files in a single file (an archive)

If you do not want to use pipes, you can use tar’s compress options to specify what it should do as additional compress/decompress step:

**Compression options**
       **-a**, **--auto-compress**
              Use archive suffix to determine the compression program. 

       **-I**, **--use-compress-program**=COMMAND
              Filter data through COMMAND.  It must accept the **-d **option, for decompression.  The argument can contain command line options. 

       **-j**, **--bzip2**
              Filter the archive through **bzip2**(1). 

       **-J**, **--xz**
              Filter the archive through **xz**(1). 

       **--lzip **Filter the archive through **lzip**(1). 

       **--lzma **Filter the archive through **lzma**(1). 

       **--lzop **Filter the archive through **lzop**(1). 

       **--no-auto-compress**
              Do not use archive suffix to determine the compression program. 

       **-z**, **--gzip**, **--gunzip**, **--ungzip**
              Filter the archive through **gzip**(1). 

       **-Z**, **--compress**, **--uncompress**
              Filter the archive through **compress**(1). 

       **--zstd **Filter the archive through **zstd**(1).
tar -czf "/var/log/VirusVault/VirusFound_${Current_Date}.zip" -C "/var/log/VirusVault" "VirusFound_${Current_Date}" --remove-files

I’m currently filtering through gzip, but I have others to filter through.

It worked with this change. :slight_smile:

tar -caf “/var/log/VirusVault/VirusFound.zip” -C “/var/log/VirusVault” “VirusFound” --remove-files

Now, what compression format is it in to be compatible with mswin.

https://www.systranbox.com/how-to-convert-tar-file-to-zip-in-linux/

tar -caf "/var/log/VirusVault/VirusFound.tar.gz" -C "/var/log/VirusVault" "VirusFound" --remove-files

It works, only one level. I’ve seen ‘tar.gz’ to zip conversion scripts, but just letting the user convert it to zip format is simpler.

I need to look and see what linux compression formats mswin10 can use.

Unless someone has a better idea, this works. Thanks for the assistance…

These two commands create byte for byte identical files.

bor@bor-Latitude-E5450:/tmp$ tar -czf xxx.zip xxx
bor@bor-Latitude-E5450:/tmp$ tar -caf xxx.tar.gz xxx
bor@bor-Latitude-E5450:/tmp$ cmp xxx.zip xxx.tar.gz 
bor@bor-Latitude-E5450:/tmp$ echo $?
0
bor@bor-Latitude-E5450:/tmp$ 
tar -czf "/var/log/VirusVault/VirusFound.zip" -C "/var/log/VirusVault" "VirusFound" --remove-file

click on VirusFound–>
opens VirusFound arc –>
displays: VirusFound.zip ------------- uncompressed
click on VirusFound.zip –>
displays folder VirusFound

If it’s double level archive, how can the files be identical? -czf = -caf

Same compression for both commands?

KDE can do a zip with a right-click on file with the folder, holding the original file structure. How does KDE do this?

I’m getting off topic, so this topic is closed.

Thanks to all. The problem is fixed.