Sign inSign up free

762. File Photos Into Year/Month Folders

medium 20 XP ~12 minHands-on lab

A phone backup dumped thousands of files into /home/student/photos/inbox/. Camera files are named like IMG_20260714_183205.jpg or VID_20251231_235959.mp4 (date YYYYMMDD, then time).

Task

Write /home/student/bin/sort-photos.sh SRC DEST that moves every file in SRC (not in sub-folders) whose name matches IMG_YYYYMMDD_HHMMSS.<ext> or VID_YYYYMMDD_HHMMSS.<ext> into DEST/YYYY/MM/, creating folders as needed. Then run it on /home/student/photos/inbox with DEST /home/student/photos/library.

  • Files that don't match the pattern stay where they are.
  • Never overwrite: if the target name already exists, add -1 before the extension (IMG_…-1.jpg), or -2, and so on.
  • Print one line per moved file: <old path> -> <new path>.

About this machine

Ubuntu 24.04 with no internet access. You are student with passwordless sudo. The grader checks the final state of the machine, not the commands you typed. Values like names and ports are generated for you.

Part of Shell Scripting for Automation. Next step: Read Files or Standard Input, Like cat

Teaching or writing about this? Embed this lab on your page

TerminalNot started

Your machine is ready to start

A fresh, isolated Ubuntu machine boots in a few seconds with the task already set up.

No account needed: 3 of 3 free tries left. Guest machines last 30 minutes.