Practical cli tool f2 for organizing photos and videos

#cli

21 September 2025

f2 is a cli tool for renaming files. You can access exif metadata information and use regex patterns. This is great for organizing your photo and video library.

Useful pattern for file names

It makes sense to use a general file name pattern with a timestamp as prefix. This way you can sort your photos and videos easily even in case various file sources contain timestamp information in different metadata attributes or file attributes could get changed unintentionally.

My preferred file naming convention for photos and videos:

The Python code is provided for illustration purposes only.

  • I decided to use a timestamp with the following short format
    from datetime import datetime
    timestamp_pattern = datetime.now().strftime('%Y%m%d_%H%M%S%f')[:-3]
  • afterwards I add additional details which do not change the main sorting via timestamp. Often times I add parts of the original file name
    new_file_name = f"{timestamp_pattern}_<original_file_name>"
  • the extension will be changed to lowercase in case it is not lowercase already

f2 command examples

This sections contains a few examples for renaming files of different sources via f2.

For each command you have to add -x at the end in case you want to execute the rename action. Otherwise it will only preview the changes. So you can try out and adjust commands until you like the result and only then renames the files for real.

Google Pixel photos and videos

  • files from Google Pixel phones sometimes contain different suffixes (night modes, edit versions)

  • we could also include information from exif metadata but this examples only reorders the timestamp

  • input examples

    PXL_20250808_123955859.mp4
    PXL_20250809_133346071.NIGHT.jpg
    PXL_20250814_210445200~2.jpg
  • f2 example command

    f2 \
      -f '(?P<prefix>\w+)_(?P<date>\d+)_(?P<time>\d{9})(?P<suffix>.*)\.(?P<ext>\w+)' \
      -r '${date}-${time}_${prefix}${suffix}{ext.lw}'
  • output examples

    20250808-123955859_PXL.mp4
    20250809-133346071_PXL.NIGHT.jpg
    20250814-210445200_PXL~2.jpg

iOS photos shared as jpg

  • these files do not contain the timestamp as part of the filename
  • but you can extract this information via exiftool
  • f2 can access exiftool in case it is installed on your computer

  • with --timezone 'UTC' you can adjust the timezone to UTC.

  • be sure to use f2 date variables with {xt.DateTimeOriginal.dt}

  • the –dt flag allows you to define the timestamp pattern more easily

  • input examples

    IMG_8403.jpg
  • f2 example command

    # only working for nightly version and still ignoring timezone when using --dt flag
    f2 \
      -r '{YYYY}{MM}{DD}_{H}{mm}{ss}000_{f}{ext.lw}' \
    	--dt "xt.DateTimeOriginal" \
      --timezone 'UTC'
  • output examples
    20250805_021630000_IMG_8403.jpg
  • example command to check if the result makes sense (UTC conversion works as expected):
    exiftool -j IMG_8403.jpg | grep '"DateTimeOriginal"' -A4
    • -j: exiftool output as json
    • pipe through grep to filter result
    • -A4: add four following lines to the match to show timezone offsets too

WhatsApp photos and videos

in case some one shared photos or videos via WhatsApp

  • input examples
    IMG-20250809-WA0002.jpg
    VID-20250810-WA0009.mp4
  • f2 example command
    f2 \
      -f '(?P<type>\w+)-(?P<date>\d+)-(?P<id>\w+)\.(?P<ext>\w+)' \
      -r '${date}_000000000_${type}-${id}{ext.lw}'
    • time information gets set to 000000000 because
      • the original file does not contain time details
      • even the exif metadata did not contain correct creation timestamps in my case
  • output examples
    20250809_000000000_IMG-WA0002.jpg
    20250810_000000000_VID-WA0009.mp4

Replace dashes or spaces with underscore

you could also add this add the end of your main f2 command

  • this replaces all occurrences of dashes, spaces or underscores with a single underscore
  • so even repeated inputs get replaced by one single underscore
f2 -f '[\-\s\_]+' -r '_'

Renaming all your photos and videos with the same timestamp pattern as prefix has another big advantage:

You can create slideshows of photo and videos even if the source files contain creation timestamp information in different metadata fields.

I have written an article about how to create a photo and video slideshow with vlc media player.

Additional resources

Related content

Comments via Bluesky 🦋

Join the conversation using the links below.

0 likes | 0 reposts | 0 replies