1

Trying to zip a backup directories inside a parent directory data/ which looks like this

data |- 2019-04-01 |- data.gz |- data2.gz |- 2019-04-09 |- data.gz |- data2.gz 

I would like to zip the timestamped directories in same named zips and delete the unzipped directories

data |- 2019-04-01.zip |- 2019-04-09.zip 

I have tried this find command to zip them but I'm having a no such file error find . -type d -execdir zip -r {}.zip {} ';' What am I doing wrong on this command?

3
  • I cannot reproduce with the command you mentioned. However, this looks like: unix.stackexchange.com/questions/115863/… You should do the -execdir and then do -delete, note that -execdir is probably useless, use -exec instead, since you appear to be in data/ already ? Commented Apr 24, 2019 at 6:23
  • 1
    @thecarpy Why you think he is in data dir? -execdir is fine here. @spy-killer Your command works, but you should use -mindepth 2 -maxdepth 2 to not also zip data and . folders. Commented Apr 24, 2019 at 7:17
  • I think he is in data because he mentions "parent directory" data/. Commented Apr 24, 2019 at 13:01

1 Answer 1

0

Your command works fine, but it also zips data and . directory.
Use -mindepth and -maxdepth options.

To delete the directories afterwards, use -execdir rm -Rf {} +:

find data -mindepth 1 -maxdepth 1 -execdir zip -r {}.zip {} \; -execdir rm -Rf {} + 
3
  • Op should probably use -delete iso -execdir rm... unix.stackexchange.com/questions/167823/find-exec-rm-vs-delete imho ;-) Commented Apr 24, 2019 at 12:57
  • 1
    afaik find -delete does not work on non-empty folders. Commented Apr 24, 2019 at 13:06
  • true, true, learned something new again today ;-) Commented Apr 25, 2019 at 11:07

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.