Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: using tar command to zip files - bash

  1. #1

    Default using tar command to zip files - bash

    Code:
    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.

  2. #2
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    31,731

    Default Re: using tar command to zip files - bash

    Maybe you should try to interprete
    Code:
    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.
    Henk van Velden

  3. #3
    Join Date
    Sep 2012
    Posts
    8,222

    Default Re: using tar command to zip files - bash

    Quote Originally Posted by hcvv View Post
    I find nowhere in the man page of tar a -C mentioned.
    Code:
    ‘--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.

  4. #4
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    31,731

    Default Re: using tar command to zip files - bash

    Quote Originally Posted by arvidjaar View Post
    Code:
    ‘--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.
    Henk van Velden

  5. #5

    Default Re: using tar command to zip files - bash

    Quote Originally Posted by hcvv View Post
    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?

  6. #6
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    31,731

    Default Re: using tar command to zip files - bash

    What do you mean with "single level" and "double level" zip files. Please show computer facts instead of self invented expressions.
    Henk van Velden

  7. #7
    Join Date
    Oct 2014
    Location
    Rotterdam
    Posts
    861

    Default Re: using tar command to zip files - bash

    Quote Originally Posted by lord_valarian View Post
    'gzip' won't work.
    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.

  8. #8

    Default Re: using tar command to zip files - bash

    Quote Originally Posted by hcvv View Post
    What do you mean with "single level" and "double level" zip files. Please show computer facts instead of self invented expressions.
    Multi-level=nested zip files

    file1.zip (click) -->

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


    Code:
    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.

  9. #9
    Join Date
    Sep 2012
    Posts
    8,222

    Default Re: using tar command to zip files - bash

    Quote Originally Posted by lord_valarian View Post
    open the zip
    tar does not create ZIP archives. Naming file "something.zip" does not make it ZIP archive.

  10. #10

    Default Re: using tar command to zip files - bash

    Quote Originally Posted by marel View Post
    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.
    '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

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •