My knowledge of Unix is not very good.
I'm trying to write a shell script to rename a set of files in a directory, like 1709532255.mp4
to 20240304_070415.mp4
, where 1709532255
is always an epoch time.
I found that
date -d @1708532255 +'%Y%m%d_%H%M%S'
... gives me the wanted format, but I can't get it to work in the script.
Here my script:
#!/bin/bash
for file in /media/HAVideo/Eingang/Test/2/*.mp4
do
filename=`echo "${file}" | cut -d'.' -f1`
readable=`date -d @$filename +"%Y%m%d%H%M%S"`
mv "${file}" "${readable}"
done
The output is:
...
date: invalid date '@/media/HAVideo/Eingang/Test/2/1709532255'
mv: can't rename '/media/HAVideo/Eingang/Test/2/1709532255.mp4': No such file or directory
...
new_date=$(date -d @1708532255 +'%Y%m%d_%H%M%S')
– Bib Mar 11 '24 at 11:27