I had a hard drive that couldn't mount on Linux Mint and to fix it I had to go to Windows and do chkdsk /f e:
. chkdsk fixed the problem but it renamed every file with special characters and moved those files to a found.000
directory. So now I have to move and rename again those files as they were before. If I run a command from time to time to rename the files with special characters I could avoid that happening again.
I want to recursively rename files AND DIRECTORIES from the current directory. The newlines should be replaced for space, the characters < > : " \ | ? *
should be removed or better yet substituted for similar characters which aren't reserved and the spaces at the start and end of a filename should be removed. Here is an example of what I want:
rename(' Fîlenämè\n\r\n$@<>:"\|?* \n ', 'Fîlenämè $@')
Here is what would be even better:
rename(' Fîlenämè\n\r\n$@<>:"\|?* \n ', 'Filename $@')
According to this answer it should be something like this:
LC_ALL=C find . -depth -execdir rename -n 's/[\r\n]+/ /g; s/:/./g; s/[\|]/-/g; s/[<>"?*]//g; s/[ \f\t\v]+$//g; s/^[ \f\t\v]+//g' {} +
I need to ignore the ..Trash-1000
directory as this command is giving me input/output ERRORS and the command stops working. Having a script that handles those errors in case there are files in that directory that can be renamed would be perfect.
I was told to prune the ..Trash-1000
directory as in this answer. I also took a look at this one. But doing this is not working:
LC_ALL=C find . -depth -path ./..Trash-1000 -prune -o -print -execdir rename -n 's/[\r\n]+/ /g; s/:/./g; s/[\|]/-/g; s/[<>"?*]//g; s/[ \f\t\v]+$//g; s/^[ \f\t\v]+//g' {} +
And it's still not deleting spaces at the start and end of the filenames.
I had to rewrite my question as the question Script to recursively replace invalid characters in filenames, not directories, with rename didn't answer mine.
..Trash-1000
path in yourfind
command? If so, take a look at Explain find's -path and -prune options