I Have mulitple files like
test-20050231-description.jpg
test-20050301-description.jpg
and i wanted to rename them to the format
test-2005-02-31-description.jpg
test-2005-03-01-description.jpg
I tried the rename command for that but couldnt get a solution.
Would be great if someone could help me.
Using the Perl rename utility:
rename -n 's/(\d{4})(\d{2})(\d{2})/$1-$2-$3/' test-*-description.jpg
Remove -n
if the output looks as expected.
assuming they are always in the same format you can do substring with loop:
cd /wanted/path/
for i in *.jpg; do mv "$i" "${i:0:9}-${i:9:2}-${i:11:2}${i:13}" ;done
What command did you type exactly as the rename command? AFAIK the best way to rename a file is to use the mv
command. Have you tried:
mv test-20050231-description.jpg test-2005-02-31-description.jpg
Another possibility I can think of is that you may be moving files you don't have permission to move. If you own the machine you're working on you can try typing sudo
before the mv
command.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.