I have these files, which were modified today and yesterday, respectively:
a.txt
b.png
And I want them renamed to:
2020-02-01.a.txt
2020-01-31.b.png
How to do that in a single Bash command?
I have these files, which were modified today and yesterday, respectively:
a.txt
b.png
And I want them renamed to:
2020-02-01.a.txt
2020-01-31.b.png
How to do that in a single Bash command?
ls | while read FILE; do mv "$FILE" "$(stat "$FILE" -c '%y' | cut -b -10). $FILE"; done
Tested on Git Bash on Windows and Linux Mint.
Using the Perl-based rename
utility:
$ rename -n 'use POSIX qw(strftime); s/^/strftime("%Y-%m-%d.",localtime((stat $_)[9]))/e' *.*
rename(a.txt, 2020-02-01.a.txt)
rename(b.png, 2020-02-01.b.png)
(On some systems, rename
may be provided as prename
).