how to rename a file based on it creation date
Hi,
I need to rename a bunch of files based on their creation date. I'd already search on google but without success. Any idea are welcome. thanks in advance |
Code:
for file in *; do NEW_FILENAME=$(stat "$file" --format %y); echo mv "$file" "$NEW_FILENAME"; done You could do some additional parsing to $NEW_FILENAME if the original format doesn't suit you. When you are happy about the new file names, just remove "echo" and the real work will be done. Be sure to check carefully or do backups. |
It should be pointed out that *nix filesystems don't keep track of the creation date of files. You can only get time of last modification, which is what the "%y" option of stat gives you in the string above.
|
Correct. I forgot to mention that. %y gives you the date of the last modification.
|
Quote:
|
@i92guboj & David the H: thanks your answer
@w1k0 the files are .mts files from my camcorder Canon HF10 (video:H264 audio:AC3). The file are stored on the memory card and are named based on a auto-increment index: 00001.mts 00002.mts etc i'm creating a script that will: -copy the .mts files to my HDD & rename it base on it's....last modified date :( (should be just fine since i do not edit the file on the device) -create an .avi "easy playable copy" of the file using ffmpeg (great tool by the way) Not a big deal, but it will be my first one. |
Quote:
Code:
for file in * |
Hi,
Just come back to post my final first script. ANY comments, improvements, optimizations, corrections are WELCOME. Thanks to all for your help Code:
#!/bin/bash soemthing like: Code:
Choose your source media: For ffmpeg installation, and on my system (Linux 2.6.30.5-43.fc11.i686.PAE #1 SMP 2009 i686 i686 i386 GNU/Linux), i did: install rpmfusion free-only repository Code:
su -c 'rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm Code:
yum -y install ffmpeg Code:
yum install gstreamer-ffmpeg.i586 |
Sorry, but there is a huge bug on my script...
it do not loop ! It perform the 2 task cp and ffmpeg for the first file listed by the find, then exit ! What's wrong ? |
You can debug using
Code:
#!/bin/bash Just FYI, you can have blank lines in a script, and I would, that's a bit dense for reading and will get harder for longer scripts. |
It's work !
Thanks Chris for your post, it help to isolate the problem and found out the solution; i split the original script in 2 files and and use option "-exec" with the "find" command.
The main that search for .MTS file: bckcamcorder.sh: Code:
#!/bin/bash Code:
#!/bin/bash Thanks all for your help ! |
and finally, the cherry on the cake...
and here the Media list choice
replace code: Code:
#--Display mounted media Code:
#--Build List menu with mounted media storage Code:
Choose the camcorder storage from the list below. |
All times are GMT -5. The time now is 04:40 PM. |