Rename based on file modification time (Linux)

Rename based on file modification time

command

Assuming that LOGFILE contains the file name you want to rename

if [ -e $LOGFILE ]; then
   TIMESTAMP=$(date -r $LOGFILE "+%Y-%m-%d_%H_%M_%S")
   mv $LOGFILE $LOGFILE.$TIMESTAMP
fi

And it is sufficient.

Description

You can get the modification time of the file specified by filename with date -r filename. " +% Y-% m-% d_% H_% M_% S " is in the format of returning with date -r.

You can assign the execution result of command to a variable by using$ (command).

Perform the actual renaming with mv.

reference

https://stackoverflow.com/questions/16391208/print-a-files-last-modified-date-in-bash/16391221

Recommended Posts

Rename based on file modification time (Linux)
Post the subject of Gmail on twitter
Rename based on file modification time (Linux)
On Linux, the time stamp of a file is a little past.
syslog file rename
[Linux] File search
I want to log file I / O on Linux
Unzip a ZIP file larger than 4GB on Linux.
Daemonizing processes on Linux
jblas on Arch Linux
Linux (WSL) on Windows
NAT router on Linux
Linux command [File operation]
Hack Linux file descriptors
Linux kernel build time
Develop .NET on Linux
Wake on lan on Linux
Monitor traffic on Linux
Update vscode on linux
Try NeosVR on Linux
Check capacity on Linux
LiveUSB creation on Linux
Linux operation on Win10
How to create an ISO file (CD image) on Linux