I have few directories whose names looks like the following:
I want to remove the newline from the end recursively.
I checked Recursively rename directories
I also checked Remove newlines in file names
The solution it suggests is:
find -name $'*\n*' -exec rename $'s|\n| |g' '{}' \;
But in my case find -name $'*\n*'
returns nothing. If I remove the $
it can find the directories
% find . -name '*\n*'
./second?
% find . -name '*\r*'
./third?
./first?
However, when I run find . -name '*\n*' -exec rename $'s|\n| |g' '{}' \;
it does not rename the directory. I also tried find . -name $'*\n*' -exec rename $'\n' ' ' {} \;
from Recursively remove newline in file names. It is also not renaming the directories.
What can I do?
find -name $'*\n*'
works for me and finds filenames with hard newlines.-name '*\n*'
is the same as-name '*n*'
and finds names with ann
... What shell are you actually running? You tagged this with both bash and zsh, and they should both support$'...'
. Are you sure it's the actual newline character you have there, and not something different? What do you get if you runls --quoting-style=shell-escape
(with a recent-ish GNU ls) orprintf "%q\n" *
(in Bash or Zsh) in the directory with those dirs?$
from both strings, i.e.find . -depth -name '*\n*' -exec rename 's|\n|_|g' {} \;
rename
, you need to know if you have the Perl one, or the util-linux one... What doesrename --version
say? (see also unix.stackexchange.com/a/510583/170373 and links therein)printf "%q\n" *
showsfirst$'\342\200\251' second$'\342\200\251' third$'\342\200\251'
find . -type d -exec rename 's/[\n\r]|\342\200\251/ /g' {} +