-1

I'm very new to shell script and I'm having issues with archiving files.

I have a folder with .xlsm files and I want those files that passed the retention period. I was able to archive except I'm having issues with those files having spaces with their filename eg. X y z.xlsm. below is my sample code.

find ${work_dir} -type f -mtime +${retention} | xargs tar -cvf ${Destination}/archive.tar

Any idea how to achieve it? Thanks!

Poshi
  • 5,332
  • 3
  • 15
  • 32
YEH
  • 1
  • 3
  • I assume `+{retention}` was supposed to be `+${retention}`? Also, `Find` should be `find` — as `bash` is not case-insensitive. – Amadan Oct 11 '19 at 07:59
  • Hi thank u for responding yes you are correct just typo error – YEH Oct 11 '19 at 08:01

1 Answers1

0

Use NUL as delimiter (-print0 for find, and --null for xargs).

find ${work_dir} -type f -mtime +${retention} -print0 | xargs --null tar -cvf ${Destination}/archive.tar
Amadan
  • 191,408
  • 23
  • 240
  • 301