1

I use gmusic to order and organise my folder structure. However this means I am left with some folders that do not have any files other then normally, a image cover.

I would like to sort through all my folders & subfolders and remove the parent folder if say, the folders are under 5mb.

Here is what I can see from another answer, but this does not handle sub-folders.

du --max-depth 1 | awk -v q='"' '$1 < 30000000 && $2 != "." {sub(/^[0-9\t ]+/, "", $0); print q $0 q}'

Below we would want to remove the folder Always Ascending and leave all over folders.

enter image description here

But here, we would want to remove George Harrison & 2017 - Guardians Of The Galaxy Vol. 2 Awesome Mix Vol. 2 & Disk 1.

enter image description here

1 Answer 1

1

find all folders, check size is smaller e.g. 5000. If smaller, rm -Rf the folder and use -prune to not descend into this folder. The second -exec and the -prune will run only if the first -exec is true.

find . -type d \
  -exec sh -c '[ $(du -s "$1" | cut -f1) -lt 5000 ]' find-sh {} \; \
  -exec echo rm -Rf {} \; \
  -prune

I put echo rm, please double check if the output is correct before removing the echo.

1
  • Wow that executed quickly! Thank yuo Mar 6, 2020 at 9:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .