Skip to content

Date Variables

F2 allows you to use file date and time attributes as part of the file renaming process, providing flexible options for organizing and managing files based on their timestamps.

This includes accessing key file properties like creation, modification, and access times, among others.

Here are the available date-related variables:

  • ctime: The time when the file's metadata was last changed (i.e., when the file permissions or ownership were modified).
  • btime: The file's creation or birth time (available only on Windows and macOS systems).
  • atime: The last time the file was accessed or read.
  • mtime: The last time the file's contents were modified.
  • now: The current system time, which can be useful for including the time of renaming in the new file name.

These variables must be combined with specific date tokens to customize the format of the dates in the file names.

Date tokens

TokenExplanationOutput
YYYYYear represented by a full four digits1970 1971 ... 2029 2030
YYYear represented only by the last two digits70 71 ... 29 30
MMMMName of the monthJanuary February ... November December
MMMAbbreviated name of the monthJan Feb ... Nov Dec
MMMonth as digits with leading zeros for single-digit months01 02 ... 11 12
MMonth as digits without leading zeros for single-digit months1 2 ... 11 12
DDDDName of the day of the weekMonday Tuesday ... Saturday Sunday
DDDAbbreviated name of the day of the weekMon Tue ... Sat Sun
DDDay of the month as digit with leading zeros01 02 ... 30 31
DDay of the month as digit without leading zeros1 2 ... 30 31
H24 Hours clock01 02 ... 22 23
hhHours with leading zeros for single-digit hours01 02 ... 11 12
hHours without leading zeros for single-digit hours1 2 ... 11 12
mmMinutes with leading zeros for single-digit minutes01 02 ... 58 59
mMinutes without leading zeros for single-digit minutes1 2 ... 58 59
ssSeconds with leading zeros for single-digit seconds01 02 ... 58 59
sSeconds without leading zeros for single-digit seconds1 2 ... 58 59
AAM PMAM PM
aam pmam pm

Usage Examples

To demonstrate how to use these variables and tokens, let's look at an example where we rename .webp image files based on the time they were last modified.

bash
f2 -f '.*webp$' -r '{mtime.MMM}-{mtime.DD}-{mtime.YYYY}_image{%003d}{ext}'

In this example:

  • {mtime.MMM} takes the abbreviated month name of the last modification date.
  • {mtime.DD} takes the day of the month, zero-padded.
  • {mtime.YYYY} takes the full four-digit year of the last modification date.
  • _image{%003d} appends a sequentially numbered suffix (e.g., image001, image002) to the file name.
  • {ext} preserves the original file extension.

Running this command on a set of .webp files would produce the following result:

text
*---------------------------------------------------------*
| ORIGINAL           | RENAMED                   | STATUS |
*---------------------------------------------------------*
| 34e7dcd7.webp      | Jun-18-2022_image001.webp | ok     |
| 7zwffegy91871.webp | Jun-03-2022_image002.webp | ok     |
| alan_p.webp        | May-29-2022_image003.webp | ok     |
| eiuz4tzc2le71.webp | Jun-03-2022_image004.webp | ok     |
| image-2-1.webp     | Apr-23-2022_image005.webp | ok     |
| qeila4tnvr971.webp | Jun-03-2022_image006.webp | ok     |
*---------------------------------------------------------*