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