Explorar o código

added script to datestamp files

George Jones hai 5 meses
pai
achega
be9016fcac
Modificáronse 1 ficheiros con 18 adicións e 0 borrados
  1. 18 0
      bin/datestamp-files.sh

+ 18 - 0
bin/datestamp-files.sh

@@ -0,0 +1,18 @@
+#!/bin/bash
+# for all files in one directory, rename the file adding it's mtime to the  filename
+# so foo.txt becomes 2023-12-04-foo.txt
+
+DIR=${1:-.}
+
+# Use find to get all files in the directory
+find $DIR -maxdepth 1 -type f | while read -r file
+do
+ # Use stat to get the modification time of the file
+ mtime=$(stat -c %y "$file")
+
+ # Format the modification time to YYYY-MM-DD
+ formatted_mtime=$(date -d "$mtime" "+%Y-%m-%d-%H-%M-%S")
+
+ # Rename the file by adding the modification time to the front of the filename
+ mv "$file" "$DIR/${formatted_mtime}-$(basename "$file")"
+done