0

I have a couple of commands that allow me to create a .tar archive and then extract the files from it.

I am using WSL and both commands work just fine if I enter them directly, but not if I run them as a .sh file - I get the find: missing argument to `-exec' error.

To create the .tar, I have:

find . -maxdepth 2 -mindepth 2 -type d -exec tar cvf {}.tar {} \;

And to extract files I have:

find . -name "*.tar" -exec tar xf {} \;

Where am I going wrong?

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
jim_e_jib
  • 3
  • 1
  • 3
    Please [check if you have maybe windows line endings in your .sh files](https://unix.stackexchange.com/questions/79702/how-to-test-whether-a-file-uses-crlf-or-lf-without-modifying-it) and if so, use `dos2unix` to convert them to unix line endings. – pLumo Oct 11 '22 at 19:53
  • 1
    Hi, thanks for the info - running dos2unix on the .sh file (thanks for the tip!) has fixed this. Thanks ever so much! – jim_e_jib Oct 11 '22 at 21:15
  • 1
    Creating a `tar` archive of a single file is pointless; you are only adding overhead, – tripleee Oct 12 '22 at 04:16
  • Hi triplee, thanks for the comments. I'm creating a tar archive of directories containing thousands, sometimes tens of thousand of files. Thanks for the link, it's interesting reading. @pLumo gave me the fix for my problem. – jim_e_jib Oct 12 '22 at 07:16
  • @jim_e_jib Great that this fixed the issue. Next time, you can create your files directly with Linux Line Endings, any proper Editor should be able to do that, e.g. [see here for notepad++](https://stackoverflow.com/questions/8195839/choose-newline-character-in-notepad). – pLumo Oct 12 '22 at 07:31
  • I can't see a thumbs up option for comments - thanks for the tip, I didn't realised notepad++ could do that :-) – jim_e_jib Oct 12 '22 at 12:55

0 Answers0