I'm trying to use a thumbnail generator python script I found on GitHub, which works awesomely.

It generates thumbnails in a folder called eaDir_temp, which then needs to be renamed on the NAS to @eaDir from a terminal. The author provides a command for this:

find . -type d -name 'eaDir_tmp' -exec mv '{}' @eaDir \;

Unfortunately, for each subfolder containing photos, it returns:

mv: cannot move ‘./subfolder/eaDir_tmp’ to ‘@eaDir/eaDir_tmp’: Directory not empty

What should I do instead?

  • Is it correct to say that the eaDir_temp directory has to be renamed only? I.e. should ./subfolder/eaDir_tmp simply become ./subfolder/@eaDir? Or is it meant to me moved to the current wotking directory (.)? – fra-san Sep 17 '20 at 22:02
  • ./subfolder/eaDir_tmp should become ./subfolder/@eaDir. . Is simply meant to denote that the search applies from the current folder. – mrgou Sep 17 '20 at 22:20

For the curious, what is likely happening: the command

find . -type d -name 'eaDir_tmp' -exec mv '{}' @eaDir \;

moves every ./whatever/eaDir_tmp directory it finds (i.e. the eaDir_tmp component) to the current working directory: ./whatever/eaDir_tmp./@eaDir. (Because @eaDir is seen by mv as a path component relative to the current working directory).

The first time, this creates ./@eaDir, if it doesn't exist yet.

The second ./whatever/eaDir_tmp found is moved into ./@eaDir, because the target directory given to mv (@eaDir) exists at this point: ./whatever/eaDir_tmp./@eaDir/eaDir_tmp.

Further ./subfolder/eaDir_tmp found are moved into ./@eaDir as well, and this step fails because ./@eaDir/eaDir_tmp already exists and is not empty.

What you can do: if your find implementation supports the -execdir action:

find . -depth -type d -name 'eaDir_tmp' -execdir mv '{}' @eaDir \;

-depth is actually only needed in case of nested eaDir_tmp directories (e.g. ./whatever/eaDir_tmp/whatever/eaDir_tmp).

Contrary to -exec, -execdir runs the specified command from the directory containing the matched file (and not from find's current working directory).

If your find doesn't support the non-standard -execdir:

find . -depth -type d -name 'eaDir_tmp' \
  -exec sh -c 'mv "$1" "${1%/*}/@eaDir"' mysh {} \;

Or, to avoid starting a shell for every single found directory:

find . -depth -type d -name 'eaDir_tmp' -exec sh -c '
  for dir
    mv "$dir" "${dir%/*}/@eaDir"
  done' mysh {} +
  • find . -depth -type d -name 'eaDir_tmp' -execdir mv '{}' @eaDir \; works perfectly, thank you! – mrgou Sep 18 '20 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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