Search code examples
linuxshellunixgziparchive

Archive all the files from source directory into a xyz.gz file and move that to target directory using UNIX shell script


Requirement: Archive files using UNIX shell script into .gz format without directory structure

I am using below command

tar -C source_dir -zcvf target_dir/xyz.gz source_dir

example:

tar -C /home/log -zcvf /home/archive/xyz.gz /home/log

here xyz.gz contains /home/log

It's creating xyz.gz file maintaining the directory structure. I want only files to be archive without directory structure.


Solution

  • You can try the following command:

    $ cd /home/log
    
    $ tar zcvf /home/archive/xyz.gz *