Appending the file modified date to the file name
Robert Moskowitz
rgm at htt-consult.com
Tue Dec 1 00:49:49 UTC 2015
On 11/30/2015 07:21 PM, Gordon Messmer wrote:
> On 11/30/2015 03:50 PM, Robert Moskowitz wrote:
>> Now I want to rename these files, which are all lectures to have the
>> date of creation/lastmodified in the file name.
>
> Does the date require a specific format?
>
> You could:
>
> mv "$file" "$file-$(stat -c %y "$file")"
Not quite as the script:
#!/bin/bash
for i in `seq 20 42`;
do
file="Voice "0${i}.m4a
mv $file "$file-$(stat -c %y "$file")"
done
is producing:
mv: target ‘Voice 036.m4a-2015-05-07 06:51:59.000000000 -0400’ is not a
directory
mv: target ‘Voice 037.m4a-2015-05-08 06:56:27.000000000 -0400’ is not a
directory
mv: target ‘Voice 038.m4a-2015-05-20 06:55:35.000000000 -0400’ is not a
directory
mv: target ‘Voice 039.m4a-2015-05-21 06:50:57.000000000 -0400’ is not a
directory
mv: target ‘Voice 040.m4a-2015-05-22 06:56:27.000000000 -0400’ is not a
directory
mv: target ‘Voice 041.m4a-2015-05-26 06:56:11.000000000 -0400’ is not a
directory
mv: target ‘Voice 042.m4a-2015-05-27 06:54:43.000000000 -0400’ is not a
directory
so I need to take only the date from the stat.
>
> Or if you want to define your own (and assuming no file names contain
> quote characters):
>
> find $files -type f -printf 'mv "%p" "%p-%TY%Tm%Td"\n' | sh
>
More information about the users
mailing list