-
Notifications
You must be signed in to change notification settings - Fork 0
Real world examples
F2 can help your organise your books by author or title thanks to exiftool variables. In this example, books downloaded from Project Gutenberg are given new identifiable names.
Below is an image of the current working directory. The books are currently named according to their IDs on Project Gutenberg but this is not ideal because it makes it difficult to select a specific book.
It's easy to rename all the files using their respective titles and authors in the new file names:
f2 -r '{xt.Title} by {xt.Creator}{ext}' -x
The aftermath:
You may want to rename music files in one folder with meaningful and
identifiable title or you may want to organise them by album or artist. With F2,
this task is so easy because it allows you to utilise
ID3 variables
in the new file name. In this example, we'll organise the audio files in a
folder into the following directory structure: artist/album/track
.
First, let's see the current state of the working directory:
As you can see, we have both mp3 and m4a files from different artists in the same folder. ID3 tags are supported for both formats (and more), so we'll go ahead and use it to structure the files in the desired order:
$ f2 -f '(\d+).*' -r '{id3.artist}/{id3.album}/$1-{id3.title}{ext}'
+--------------------------------------+-------------------------------------------------------------------+--------+
| INPUT | OUTPUT | STATUS |
+--------------------------------------+-------------------------------------------------------------------+--------+
| 13. Note To Self.mp3 | J. Cole/2014 Forest Hills Drive/13-Note to Self.mp3 | ok |
| 12. Love Yourz.mp3 | J. Cole/2014 Forest Hills Drive/12-Love Yourz.mp3 | ok |
| 11. Apparently.mp3 | J. Cole/2014 Forest Hills Drive/11-Apparently.mp3 | ok |
| 10. Hello.mp3 | J. Cole/2014 Forest Hills Drive/10-Hello.mp3 | ok |
| 09. No Role Modelz.mp3 | J. Cole/2014 Forest Hills Drive/09-No Role Modelz.mp3 | ok |
| 08. G.O.M.D.mp3 | J. Cole/2014 Forest Hills Drive/08-G.O.M.D..mp3 | ok |
| 05. A Tale of 2 Citiez.mp3 | J. Cole/2014 Forest Hills Drive/05-A Tale of 2 Citiez.mp3 | ok |
| 04. 03' Adolescence.mp3 | J. Cole/2014 Forest Hills Drive/04-03' Adolescence.mp3 | ok |
| 03. Wet Dreamz.mp3 | J. Cole/2014 Forest Hills Drive/03-Wet Dreamz.mp3 | ok |
| 02. January 28th.mp3 | J. Cole/2014 Forest Hills Drive/02-January 28th.mp3 | ok |
| 01. Intro.mp3 | J. Cole/2014 Forest Hills Drive/01-Intro.mp3 | ok |
| 10. 4 Your Eyez Only.mp3 | J. Cole/4 Your Eyez Only/10-4 Your Eyez Only.mp3 | ok |
| 09. She's Mine, Pt. 2.mp3 | J. Cole/4 Your Eyez Only/09-She's Mine, Pt. 2.mp3 | ok |
| 08. Foldin Clothes.mp3 | J. Cole/4 Your Eyez Only/08-Foldin Clothes.mp3 | ok |
| 07. Neighbors.mp3 | J. Cole/4 Your Eyez Only/07-Neighbors.mp3 | ok |
| 06. Change.mp3 | J. Cole/4 Your Eyez Only/06-Change.mp3 | ok |
| 05. She's Mine, Pt. 1.mp3 | J. Cole/4 Your Eyez Only/05-She's Mine, Pt. 1.mp3 | ok |
| 04. Ville Mentality.mp3 | J. Cole/4 Your Eyez Only/04-Ville Mentality.mp3 | ok |
| 03. Deja Vu.mp3 | J. Cole/4 Your Eyez Only/03-Deja Vu.mp3 | ok |
| 02. Immortal.mp3 | J. Cole/4 Your Eyez Only/02-Immortal.mp3 | ok |
| 01. For Whom The Bell Tolls.mp3 | J. Cole/4 Your Eyez Only/01-For Whom the Bell Tolls.mp3 | ok |
| 14 Goner.m4a | twenty one pilots/Blurryface/14-Goner.m4a | ok |
| 13 Not Today.m4a | twenty one pilots/Blurryface/13-Not Today.m4a | ok |
| 12 Hometown.m4a | twenty one pilots/Blurryface/12-Hometown.m4a | ok |
| 11 Message Man.m4a | twenty one pilots/Blurryface/11-Message Man.m4a | ok |
| 10 We Don't Believe What's On TV.m4a | twenty one pilots/Blurryface/10-We Don't Believe What's on TV.m4a | ok |
| 09 Polarize.m4a | twenty one pilots/Blurryface/09-Polarize.m4a | ok |
| 08 Doubt.m4a | twenty one pilots/Blurryface/08-Doubt.m4a | ok |
| 07 The Judge.m4a | twenty one pilots/Blurryface/07-The Judge.m4a | ok |
| 06 Lane Boy.m4a | twenty one pilots/Blurryface/06-Lane Boy.m4a | ok |
| 05 Tear In My Heart.m4a | twenty one pilots/Blurryface/05-Tear in My Heart.m4a | ok |
| 04 Fairly Local.m4a | twenty one pilots/Blurryface/04-Fairly Local.m4a | ok |
| 03 Ride.m4a | twenty one pilots/Blurryface/03-Ride.m4a | ok |
| 02 Stressed Out.m4a | twenty one pilots/Blurryface/02-Stressed Out.m4a | ok |
| 01 Heavydirtysoul.m4a | twenty one pilots/Blurryface/01-Heavydirtysoul.m4a | ok |
+--------------------------------------+-------------------------------------------------------------------+--------+
Append the -x flag to apply the above changes
Notice how the ID3 tags are used in the replacement string to organise the files
in the desired order. The presence of the path separator (/
) will cause the
directory components in the output to be auto created once the changes are
committed to the filesystem. Let's go ahead and do just that:
f2 -f '(\d+).*' -r '{id3.artist}/{id3.album}/$1-{id3.title}{ext}' -x
Here's the result:
Assuming the image files in a directory are taken in the same location but at different times and using different cameras, we can organise them by the location name, year, and use a consistent naming scheme for the files.
Let's rename the files using
Exif variables
so that they conform to this structure:
<location>/<year>/<month-day-year>_<time>_<camera maker>-<camera model>.<extension>
$ f2 -r 'Olumo-Rock/{x.cdt.YYYY}/{x.cdt.MMM}-{x.cdt.DD}-{x.cdt.YYYY}_{x.cdt.H}-{x.cdt.mm}-{x.cdt.ss}_{x.make}-{x.model}{ext}'
+---------------------------+-------------------------------------------------------------------+--------+
| INPUT | OUTPUT | STATUS |
+---------------------------+-------------------------------------------------------------------+--------+
| 20181202_095611.jpg | Olumo-Rock\2018\Dec-02-2018_09-56-11_samsung-SAMSUNG-SM-G935A.jpg | ok |
| 20181202_095610.jpg | Olumo-Rock\2018\Dec-02-2018_09-56-10_samsung-SAMSUNG-SM-G935A.jpg | ok |
| 20181202_095608.jpg | Olumo-Rock\2018\Dec-02-2018_09-56-08_samsung-SAMSUNG-SM-G935A.jpg | ok |
| 20181202_095604.jpg | Olumo-Rock\2018\Dec-02-2018_09-56-04_samsung-SAMSUNG-SM-G935A.jpg | ok |
| 20181202_095558.jpg | Olumo-Rock\2018\Dec-02-2018_09-55-58_samsung-SAMSUNG-SM-G935A.jpg | ok |
| 20181202_095557.jpg | Olumo-Rock\2018\Dec-02-2018_09-55-57_samsung-SAMSUNG-SM-G935A.jpg | ok |
| 20181202_095553.jpg | Olumo-Rock\2018\Dec-02-2018_09-55-53_samsung-SAMSUNG-SM-G935A.jpg | ok |
| 20181202_095551.jpg | Olumo-Rock\2018\Dec-02-2018_09-55-51_samsung-SAMSUNG-SM-G935A.jpg | ok |
| 333.dng | Olumo-Rock\2019\Nov-15-2019_17-40-16_Apple-iPhone 7.dng | ok |
| 208.dng | Olumo-Rock\2019\Nov-15-2019_17-02-51_Apple-iPhone 7.dng | ok |
| 334.dng | Olumo-Rock\2019\Nov-15-2019_17-40-17_Apple-iPhone 7.dng | ok |
| 283.dng | Olumo-Rock\2019\Nov-15-2019_17-30-33_Apple-iPhone 7.dng | ok |
| 336.dng | Olumo-Rock\2019\Nov-15-2019_17-40-26_Apple-iPhone 7.dng | ok |
| 210.dng | Olumo-Rock\2019\Nov-15-2019_17-02-52_Apple-iPhone 7.dng | ok |
| 206.dng | Olumo-Rock\2019\Nov-15-2019_17-01-45_Apple-iPhone 7.dng | ok |
| 207.dng | Olumo-Rock\2019\Nov-15-2019_17-01-54_Apple-iPhone 7.dng | ok |
| 335.dng | Olumo-Rock\2019\Nov-15-2019_17-40-18_Apple-iPhone 7.dng | ok |
| 20190813_120838.jpg | Olumo-Rock\2019\Aug-13-2019_12-08-38_samsung-SM-G975F.jpg | ok |
| 20190813_120832.jpg | Olumo-Rock\2019\Aug-13-2019_12-08-32_samsung-SM-G975F.jpg | ok |
| 20190813_120913.jpg | Olumo-Rock\2019\Aug-13-2019_12-09-13_samsung-SM-G975F.jpg | ok |
| 2019-09-23 05.36.54 1.jpg | Olumo-Rock\2019\Aug-13-2019_12-31-21_samsung-SM-G975F.jpg | ok |
| 2019-09-23 05.39.23 1.jpg | Olumo-Rock\2019\Aug-13-2019_12-31-15_samsung-SM-G975F.jpg | ok |
| 20190813_120841.jpg | Olumo-Rock\2019\Aug-13-2019_12-08-41_samsung-SM-G975F.jpg | ok |
| 20190813_120853.jpg | Olumo-Rock\2019\Aug-13-2019_12-08-54_samsung-SM-G975F.jpg | ok |
| 20190813_120908.jpg | Olumo-Rock\2019\Aug-13-2019_12-09-08_samsung-SM-G975F.jpg | ok |
| 20190813_120828.jpg | Olumo-Rock\2019\Aug-13-2019_12-08-28_samsung-SM-G975F.jpg | ok |
| 2019-09-23 05.43.10 1.jpg | Olumo-Rock\2019\Aug-13-2019_12-30-12_samsung-SM-G975F.jpg | ok |
| 20200110_174738.jpg | Olumo-Rock\2020\Jan-10-2020_17-47-38_samsung-SM-G975F.jpg | ok |
| 20200110_174439.jpg | Olumo-Rock\2020\Jan-10-2020_17-44-39_samsung-SM-G975F.jpg | ok |
| 20200110_174741.dng | Olumo-Rock\2020\Jan-10-2020_17-47-41_samsung-SM-G975F.dng | ok |
| 20200110_174441.jpg | Olumo-Rock\2020\Jan-10-2020_17-44-41_samsung-SM-G975F.jpg | ok |
| 20200110_174741.jpg | Olumo-Rock\2020\Jan-10-2020_17-47-41_samsung-SM-G975F.jpg | ok |
| 20200110_174441.dng | Olumo-Rock\2020\Jan-10-2020_17-44-41_samsung-SM-G975F.dng | ok |
| 20200110_174443.jpg | Olumo-Rock\2020\Jan-10-2020_17-44-43_samsung-SM-G975F.jpg | ok |
| 20200110_174738.dng | Olumo-Rock\2020\Jan-10-2020_17-47-38_samsung-SM-G975F.dng | ok |
| 20200110_174443.dng | Olumo-Rock\2020\Jan-10-2020_17-44-43_samsung-SM-G975F.dng | ok |
| IMG_1330.jpg | Olumo-Rock\2019\Nov-17-2019_17-55-36_Apple-iPhone 7.jpg | ok |
| IMG_1331.jpg | Olumo-Rock\2019\Nov-17-2019_17-55-38_Apple-iPhone 7.jpg | ok |
| IMG_1333.jpg | Olumo-Rock\2019\Nov-17-2019_17-55-58_Apple-iPhone 7.jpg | ok |
| IMG_1334.jpg | Olumo-Rock\2019\Nov-17-2019_17-55-59_Apple-iPhone 7.jpg | ok |
+---------------------------+-------------------------------------------------------------------+--------+
Append the -x flag to apply the above changes
Executing the renaming operation produces the following directory structure:
f2 -r 'Olumo-Rock/{x.dt.YYYY}/{x.dt.MMM}-{x.dt.DD}-{x.dt.YYYY}_{x.dt.H}-{x.dt.mm}-{x.dt.ss}_{x.make}-{x.model}{ext}' -x
tree
.
└── Olumo-Rock
├── 2018
│ ├── Dec-02-2018_09-55-51_samsung-SAMSUNG-SM-G935A.jpg
│ ├── Dec-02-2018_09-55-53_samsung-SAMSUNG-SM-G935A.jpg
│ ├── Dec-02-2018_09-55-57_samsung-SAMSUNG-SM-G935A.jpg
│ ├── Dec-02-2018_09-55-58_samsung-SAMSUNG-SM-G935A.jpg
│ ├── Dec-02-2018_09-56-04_samsung-SAMSUNG-SM-G935A.jpg
│ ├── Dec-02-2018_09-56-08_samsung-SAMSUNG-SM-G935A.jpg
│ ├── Dec-02-2018_09-56-10_samsung-SAMSUNG-SM-G935A.jpg
│ └── Dec-02-2018_09-56-11_samsung-SAMSUNG-SM-G935A.jpg
├── 2019
│ ├── Aug-13-2019_12-08-28_samsung-SM-G975F.jpg
│ ├── Aug-13-2019_12-08-32_samsung-SM-G975F.jpg
│ ├── Aug-13-2019_12-08-38_samsung-SM-G975F.jpg
│ ├── Aug-13-2019_12-08-41_samsung-SM-G975F.jpg
│ ├── Aug-13-2019_12-08-54_samsung-SM-G975F.jpg
│ ├── Aug-13-2019_12-09-08_samsung-SM-G975F.jpg
│ ├── Aug-13-2019_12-09-13_samsung-SM-G975F.jpg
│ ├── Aug-13-2019_12-30-12_samsung-SM-G975F.jpg
│ ├── Aug-13-2019_12-31-15_samsung-SM-G975F.jpg
│ ├── Aug-13-2019_12-31-21_samsung-SM-G975F.jpg
│ ├── Nov-15-2019_17-01-45_Apple-iPhone 7.dng
│ ├── Nov-15-2019_17-01-54_Apple-iPhone 7.dng
│ ├── Nov-15-2019_17-02-51_Apple-iPhone 7.dng
│ ├── Nov-15-2019_17-02-52_Apple-iPhone 7.dng
│ ├── Nov-15-2019_17-30-33_Apple-iPhone 7.dng
│ ├── Nov-15-2019_17-40-16_Apple-iPhone 7.dng
│ ├── Nov-15-2019_17-40-17_Apple-iPhone 7.dng
│ ├── Nov-15-2019_17-40-18_Apple-iPhone 7.dng
│ ├── Nov-15-2019_17-40-26_Apple-iPhone 7.dng
│ ├── Nov-17-2019_17-55-36_Apple-iPhone 7.jpg
│ ├── Nov-17-2019_17-55-38_Apple-iPhone 7.jpg
│ ├── Nov-17-2019_17-55-58_Apple-iPhone 7.jpg
│ └── Nov-17-2019_17-55-59_Apple-iPhone 7.jpg
└── 2020
├── Jan-10-2020_17-44-39_samsung-SM-G975F.jpg
├── Jan-10-2020_17-44-41_samsung-SM-G975F.dng
├── Jan-10-2020_17-44-41_samsung-SM-G975F.jpg
├── Jan-10-2020_17-44-43_samsung-SM-G975F.dng
├── Jan-10-2020_17-44-43_samsung-SM-G975F.jpg
├── Jan-10-2020_17-47-38_samsung-SM-G975F.dng
├── Jan-10-2020_17-47-38_samsung-SM-G975F.jpg
├── Jan-10-2020_17-47-41_samsung-SM-G975F.dng
└── Jan-10-2020_17-47-41_samsung-SM-G975F.jpg