I have many files in folders and subfolders.
I need remove some chars (same position) from all filenames.
Example:
IMG-20230226-WA0002.jpg -> 20230226-WA0002.jpg
I think simple way is to use echo ${i:N:N}
, so I did this.
for i in $(find . -type f); do mv "$i" "${i:5}; done
As I supposed, it shows me files with full path, so how can I do it correctly?
PS: And how can I do it for "string"? For example remove only string IMG-
from files?
PS2: I don't want use rename
command.
Thanks.
find
command again by mistake, file20230226-WA0002.jpg
will now be renamed to0226-WA0002.jpg
. I assume that's not what you need. Consider changing your question to how to remove a certain pattern from a beginning of the filename (like IMG-), for instance, if that's indeed what you want. Also, what's wrong with therename
command? Why don't you want to use it? – aviro Apr 23 '23 at 14:29rename
? Perl-rename is really one of the best tools for the job, is it that you cannot install it on your machine? – terdon Apr 23 '23 at 14:36