Title basically, I need to parse the date modified, the time and seconds in order to reconstruct the filenames in the format of an android phone’s camera roll.
I should be able to make the script once I know how to parse the metadata is all
Title basically, I need to parse the date modified, the time and seconds in order to reconstruct the filenames in the format of an android phone’s camera roll.
I should be able to make the script once I know how to parse the metadata is all
Sure, here is a simple Bash script which uses the
statcommand to get the modification time of files. It looks specifically for.jpgand.mp4files in the current directory and prints out the modification date and time, including seconds:#!/bin/bash # Iterate over .jpg and .mp4 files in the current directory for file in *.{jpg,mp4}; do # Check if the file exists before trying to extract the date if [ -e "$file" ]; then # Use stat to extract modification date and print it out echo "$file - Modification Date: $(stat -c %y "$file")" fi doneThis script will print out the filename along with its modification date for each .jpg and .mp4 file.
You can use this script by saving it in a file (for example,
filedate.sh), making it executable withchmod +x filedate.sh, and running it with./filedate.sh.Please note that the date format of the
statcommand can vary based on your system. The%yformat outputs the last modification time in human readable format (yyyy-mm-dd hh:mm:ss.sssssssss +zone). You might need to adjust this if you are using a system wherestatbehaves differently.Also keep in mind that this script does not traverse directories recursively. It only looks for the specified files in the directory where it is executed. If you need to perform this operation on files in subdirectories, you will need to modify the script slightly or use a different approach.
@Pyrozo007@lemmy.dbzer0.com does it look like something you are looking for? The check for file existence is unneeded IMO and using the
filevariable name occludes another binary but in this case it shouldn’t hurt the execution