Veracious Network More than just a game, it's a community!

Bash script to update file timestamps by filename

# Find files within the current directory which match the filename pattern of "YYYYMMDD..."
# and update their modified timestamp to the filename
#
# Example, a file named "20210405_test_file.jpg" will have its timestamp
# set to 2021 April 5.

find . -type f -regex '\.\/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*' | while read i; do
    D=$(echo "$i" | sed 's:./\([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\).*:\1:')
    touch "$i" -t "${D}0000"
done

Some products listed here may contain referral links to help fund this site and the effort required to write articles.

Proudly managed by Wort Technologies hosted by eVAL Agency

Powered by MarkdownMaster CMS software