Is this script problematic? remove empty directorys


Recommended Posts

I want to remove all directorys after /mnt/user/1/this if its empty

 

so i use 

 

find /mnt/user/downloads/completed/this/ -type d -empty -exec rmdir {} \;
mkdir /mnt/user/downloads/completed/this
 

in user scripts, i mkdir, bc it deletes "this" also, but should only remove the dirs AFTER "this".

 

It works, but it is problematic for unraid in someway? (i dont think so)

 

Or is there a way to first only delete any folders AFTER "this" and keep "this", even if its empty?

 


BTW.  "this" is a user share

Edited by nuhll
Link to comment
2 hours ago, nuhll said:

Hmm, i "fixxed" it by touching a temp file before running the "delete empty folders script" in the folders i want to keep. 

 

This is a quite common trick in use. Same as checkout of source code from repositories often may check out place-holder files just to auto-create required directories.

 

You can also consider doing find /mnt/user/downloads/completed/this/* to make find run on the entries in the this/ directory instead of running on this/ itself.

 

  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.