0

This is basic questions. I need to find folders in the current working directory(not recursively) and if they are older than 5 days archive them. zip or tar.gz is fine.

I can find the folders with following commands

find ./ -maxdepth 1 -type d -mtime +5

And i know i can pass this output of the find using xargs. But i do not know how to archive with folder name intact.

That is the directory test1 should be archived to test1.zip and directory "test2" should be archived to "test2.zip".

Any inputs are welcome.

Regards

MadHatter
  • 78,442
  • 20
  • 178
  • 229
Abdul
  • 85
  • 1
  • 2
  • 9

1 Answers1

1

You can use the -exec function of find:

find ./ -maxdepth 1 -type d -mtime +5 -exec tar cvzf {}.tar.gz {} \;
Guido Vaccarella
  • 1,418
  • 14
  • 13
  • Thank you. It worked. I had to specify the full path rather than "./". Otherwise a ".tar.gz" is getting created. – Abdul Nov 06 '13 at 20:32