Solved - Re: Appending the file modified date to the file name

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Here is what works:

#!/bin/bash
for i in `seq 20 42`;
    do
        file="Voice "0${i}.m4a
        mv "$file" "$file-$(stat -c %y "$file"|awk '{print $1}')"
    done

I suspect there are better ways, but this will do for now...

thanks

On 11/30/2015 07:49 PM, Robert Moskowitz wrote:


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



--
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux