Reputation: 37
I've got file that start with two dots located in different directories. I need to list them all and change their names in bulk and remove the dots completely.
Any suggestions how to do that?
Upvotes: 1
Views: 704
Reputation: 124774
Not very efficient, due to the sh
invocation for each file, but this should work, and is safe:
find path -type f -name '..*' -execdir sh -c 'fn=$1; dots=${fn%%[^.]*}; cleaned=${fn:${#dots}}; mv -nv "$fn" "$cleaned"' -- {} \;
How it works:
sh
(with a sequence of commands) in the directory of the file, passing the filename as parameter (sh -c '...' -- {}
)fn
dots
fn
, starting after the length of dots
mv
Upvotes: 1