0

I have a very nested directory structure where only in the deepest folders are files. There folders I want to archive via shell with ZIP or RAR but not the parent folders.

   |
Directory
   |-----SubDir-1-----SubDir-1.1----File-1.1.1,File-1.1.2,File-1.1.3
            |            |
            |         SubDir-1.2----File-1.2.1,File-1.2.2,File-1.2.3
            |
         SubDir-2-----SubDir-2.1----SubDir-2.1.1----File-2.1.1.1,File-2.1.1.2
            |

When I tried to do this not only the deepest subdirs are stuffed but also SubDir-1, SubDir-2 and SubDir-2.1 are also packed to an archive with all subfolders and files in it.

Anyone an ideea? Tnx!

  • "When I tried to do this..." -- Please provide the exact command(s) you tried. – Kamil Maciorowski Dec 4 '18 at 13:53
0

Do you want to keep any folder at all? If not, you could use:

find ./Source -type f -print0 | xargs -0 mv -t ./Destination

This will move all the files inside subfolders of the Source directory into Destination, without the subfolders itself.

I tested this on Linux and it works, it will probably work on MacOS too, assuming you are using that based on your profile picture.

  • Thanks for your fast answer! Yes, the folder structure needs to be kept because it's the information what, from whom, from which date and what job the files are. – X-File Dec 4 '18 at 14:14
  • But not inside the ZIP file, right? If you use my comment and replace the mv with cp, it will copy all the files from the subdirectories directly inside the Destination folder. I recommend making a backup before running my commands, use it on your own risk! If it works, please mark the answer as accepted. – Eloy Dec 4 '18 at 15:22

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.