vault backup: 2026-04-28 10:14:29
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Check if a filename was provided
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: $0 <filename>"
|
||||
exit 1
|
||||
@@ -8,29 +7,28 @@ fi
|
||||
|
||||
TARGET="$1"
|
||||
|
||||
# Check if the file actually exists
|
||||
if [ ! -f "$TARGET" ]; then
|
||||
echo "Error: File '$TARGET' not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get creation time (%W).
|
||||
# Note: Returns 0 or '-' if the filesystem doesn't support birth time.
|
||||
# Extract just the filename (e.g., "Lecture_1.pdf")
|
||||
# and the directory path (e.g., ".")
|
||||
FILENAME=$(basename "$TARGET")
|
||||
DIRNAME=$(dirname "$TARGET")
|
||||
|
||||
BTIME=$(stat -c %W "$TARGET")
|
||||
|
||||
# Fallback to last modification time (%Y) if birth time is unavailable
|
||||
if [ "$BTIME" -eq 0 ] || [ "$BTIME" == "-" ]; then
|
||||
BTIME=$(stat -c %Y "$TARGET")
|
||||
fi
|
||||
|
||||
# Calculate the minute-based timestamp (equivalent to Math.floor(ms / 60000))
|
||||
# Since stat returns seconds, we divide by 60.
|
||||
FORMATTED_DATE=$(( BTIME / 60 ))
|
||||
|
||||
# Define the new name
|
||||
NEW_NAME="${FORMATTED_DATE} - ${TARGET}"
|
||||
# Construct the new name using ONLY the filename,
|
||||
# then prepend the original directory path
|
||||
NEW_NAME="${DIRNAME}/${FORMATTED_DATE} - ${FILENAME}"
|
||||
|
||||
# Perform the rename
|
||||
mv "$TARGET" "$NEW_NAME"
|
||||
|
||||
echo "Renamed: '$TARGET' -> '$NEW_NAME'"
|
||||
|
||||
Reference in New Issue
Block a user