2

I want to compress a folder with 100 files in batches of 10. I used the following script to do this. But what happens is when I unzip the gzipped file, it has all the folders from /.

find /home/ubuntu/reports/tmp -type f -print0 | split -t '\0' -l 5 -d --filter 'tar czf /home/ubuntu/reports/tmp/reports-$(date +"%F-%T")-$FILE.tar.gz --files-from=- --null'

Can anyone please tell me how to zip only the files without the containing folders?

1 Answer 1

1

The simplest way would be to simply cd to the directory and run find from there:

cd /home/ubuntu/reports/tmp
find . -type f -print0 | split -t '\0' -l 5 -d --filter 'tar czf /home/ubuntu/reports/tmp/reports-$(date +"%F-%T")-$FILE.tar.gz --files-from=- --null'

Note that you're creating the tar.gz files in the same directory as the files, which means they will come up in find's output and then get included in other tar.gz files. Put the tar.gz files in some other directory.

Also, for batches of 10, you need -l 10, not -l 5, which would be batches of 5.

3
  • Thank you and it worked! And, the files will be deleted once it is transferred to a backup location. So, they will not be included while using find. Thanks, again. Jan 24, 2018 at 10:28
  • You were warned.
    – muru
    Jan 24, 2018 at 10:29
  • I was just mentioning a random number. I have changed it to 500 to match my case. Thanks! Jan 31, 2018 at 10:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .