0

I have been away from scripting for years, so I was wondering if someone can help in the below.

I am migrating from Google Photos to Amazon Photos (about 40k photos). Here is an example of what I downloaded from Google:

IMG-20180601-WA0004-modifié.jpg
IMG-20180601-WA0004.jpg
IMG-20180601-WA0004.jpg.json
IMG-20180601-WA0005-modifié.jpg
IMG-20180601-WA0005.jpg
IMG-20180601-WA0005.jpg.json
IMG-20180601-WA0008-modifié.jpg
IMG-20180601-WA0008.jpg
IMG-20180601-WA0008.jpg.json
IMG-20180601-WA0009-modifié.jpg
IMG-20180601-WA0009.jpg
IMG-20180601-WA0009.jpg.json
IMG-20180601-WA0010-modifié.jpg
IMG-20180601-WA0010.jpg
IMG-20180601-WA0010.jpg.json
IMG-20180601-WA0011-modifié.jpg
IMG-20180601-WA0011.jpg
IMG-20180601-WA0011.jpg.json
IMG-20180601-WA0013-modifié.jpg
IMG-20180601-WA0013.jpg
IMG-20180601-WA0013.jpg.json
IMG-20180601-WA0014-modifié.jpg
IMG-20180601-WA0014.jpg
IMG-20180601-WA0014.jpg.json
IMG-20180601-WA0015-modifié.jpg
IMG-20180601-WA0015.jpg
IMG-20180601-WA0015.jpg.json
IMG-20180601-WA0020.jpg
IMG-20180601-WA0020.jpg.json
IMG-20180601-WA0036-modifié.jpg
IMG-20180601-WA0036.jpg
IMG-20180601-WA0036.jpg.json
VID-20180601-WA0012.mp4.json
VID_20180601_195857.mp4.json
métadonnées.json

I want the following:

  1. Search across all the directories within the main folder of the downloaded photos,
  2. delete all the video files such as mov, mp4, mpeg, mpg, avi, m4v and wmv (note that sometimes the file extension is in caps)
  3. for the photos, you will notice that most of the file names are duplicated (one without the word "modifié" and the other with). Note that not all of them have a "modifié" version, e.g. IMG-20180601-WA0020.jpg. I would like to delete all photos where the filename does not contain the word "modifié" except if the original file does not have a "modifié" version then keep it (IMG-20180601-WA0020.jpg is an example to keep).
  4. I prefer to keep the json files as is if they are not related to a video file otherwise delete them.
2
  • Can you please add the script you have so far? Do all the JPG file names end with a number before the suffix?
    – nohillside
    Feb 3 at 15:44
  • Unfortunately, I can't say I have a script. All I did was just counting the number of files per extension and then I gave up. I've been away from scripting for more than 15 years now. Regarding your second question, no necessarily. Here is another example of a filename: 1495267_10203328387516077_910506315287260810_o.jpg in another directory.
    – HimaTech
    Feb 4 at 2:22

2 Answers 2

0

Deleting all video files can be accomplished with

find . -type f \( -iname '*.mp4' -o -iname '*.mp4.json' \) -delete

Add more -o -iname '*.suffix' parts for the other suffixes you need.


To get rid of the originals for modified pictures, run something like

find . -name '*-modifié.jpg' -exec sh -c 'rm -f $(echo "$1" | sed s/-modifié//)' _ {} \;

which will find any files with -modifié and remove their unmodified version (rm -f suppresses an error message in case there is no unmodified version).

PS: I strongly recommend a backup before modifying/running these commands, in case things go wrong.

0

With zsh:

zmodload zsh/files # for a builtin rm to avoid the "too many args" limit
                   # of the system one

set -o nocaseglob

echo rm -f -- **/*.(mp4|mpeg|mpg|mov|wmv|avi|m4v)(|.json)(N.)

echo rm -f -- **/*-modifié.jpg(N.e['reply=( ${REPLY%-*}.jpg(|.json)(N.) )'])

Remove the echos to actually do it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .