I received great help in this thread about using command "rename" on folders with trailing whitespaces that are also in subdirectories. How to use the command "rename" on subdirectories as well
Thanks again @pa4080 and @steeldriver and @pm-b
In general the solution requires to be executed several times, when folders with trailing whitespaces that are also nested in subdirectories
When I am using a proposed solution that was supposed to not require to execute the command several times but to do this automatically, I get an error message.
I was asked to post this question in a new thread. So here I go.
Command:
find . -depth -name '* ' -execdir rename -n 's/ *$//' {} +
File Structure ("Good" means no whitespace at end, "Bad" means whitespace at end:
|-FolderBad1
| |-FolderGood1
| |-FolderBad2
| | |-FolderBad3
|-FolderGood
| |-Folder Good2
| | |-FolderGood3
| | | |-FolderGood4
| | | | |-FolderBad4
| | | | |-FolderBad5
Dry-Run (flag -n) gives this output as expected:
find . -depth -name '* ' -execdir rename -n 's/ *$//' {} +
'FolderBad3 ' would be renamed to 'FolderBad3'
'FolderBad2 ' would be renamed to 'FolderBad2'
'FolderBad1 ' would be renamed to 'FolderBad1'
'FolderBad5 ' would be renamed to 'FolderBad5'
'FolderBad4 ' would be renamed to 'FolderBad4'
Removing -n flag gives this error message:
find . -depth -name '* ' -execdir rename 's/ *$//' {} +
Can't rename 'FolderBad3 ' to 'FolderBad3': No such file or directory
Can't rename 'FolderBad2 ' to 'FolderBad2': No such file or directory
Can't rename 'FolderBad5 ' to 'FolderBad5': No such file or directory
Can't rename 'FolderBad4 ' to 'FolderBad4': No such file or directory
Running Dry-run again now:
find . -depth -name '* ' -execdir rename -n 's/ *$//' {} +
'FolderBad3 ' would be renamed to 'FolderBad3'
'FolderBad2 ' would be renamed to 'FolderBad2'
'FolderBad5 ' would be renamed to 'FolderBad5'
'FolderBad4 ' would be renamed to 'FolderBad4'
Rerunning the command without -n gives the same error message:
find . -depth -name '* ' -execdir rename 's/ *$//' {} +
Can't rename 'FolderBad3 ' to 'FolderBad3': No such file or directory
Can't rename 'FolderBad2 ' to 'FolderBad2': No such file or directory
Can't rename 'FolderBad5 ' to 'FolderBad5': No such file or directory
Can't rename 'FolderBad4 ' to 'FolderBad4': No such file or directory
So just the FolderBad1 was renamed but none of the other "Bad" folders in the subdirectories. So maybe it's the a similar question that I asked before already, how this command is applied to subdirectories.
Lots og text, I hope this clarified it.
Greetings, Chris
-noutput format is different from what I'd expect for the current Perl-basedrenamecommand - can you add the outputs oftype -a renameandrename --version? What is your Ubuntu version? – steeldriver Oct 28 '20 at 12:40FolderBad1, but does so first (defying the-depthdirective). Can you addfind --versionas well? – steeldriver Oct 28 '20 at 13:13