Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

60%
+1 −0
Q&A Rename multiple files which have a variable suffix

find . -type f -print0 \ | grep -z -- '-min.jpg-[[:alnum:]]*$' \ | while IFS= read -r -d '' f; do find "$f" -print0 \ | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \ | xargs -0 mv ...

posted 7mo ago by alx‭  ·  edited 7mo ago by alx‭

Answer
#14: Post edited by user avatar alx‭ · 2023-10-15T22:08:02Z (7 months ago)
  • ```sh
  • find . -type f -print0 \
  • | grep -z -- '-min.jpg-[[:alnum:]]*$' \
  • | while IFS= read -r -d '' f; do
  • find "$f" -print0 \
  • | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs -0 mv "$f";
  • done;
  • ```
  • Or, if you prefer a one-liner:
  • ```sh
  • find . -type f -print0 | grep -z -- '-min.jpg-[[:alnum:]]*$' | while IFS= read -r -d '' f; do find "$f" -print0 | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' | xargs -0 mv "$f"; done;
  • ```
  • The code above is hardened against malicious, broken, or otherwise non-portable file names. That makes it slightly more complex than necessary.
  • Never use whitespace in file names. They are non-portable. See POSIX: <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282>.
  • For the hardened version, find(1)'s `-print0` and xargs(1)'s `-0` are common enough that don't need explanation (do an online search). grep(1)'s and sed(1)'s `-z` are less common, but still common enough. read(1)'s `-d ''` is a trick explained here: <https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find#comment98776168_9612232>.
  • Here's a simpler version, which you can run if you know your file names are portable:
  • ```sh
  • find . -type f \
  • | grep -- '-min.jpg-[[:alnum:]]*$' \
  • | while read f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • `find . -type f |`:
  • Find files
  • `| grep -- '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `--` is necessary to avoid interpreting the pattern as an option to grep(1).
  • `| while read f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • ```sh
  • find . -type f -print0 \
  • | grep -z -- '-min.jpg-[[:alnum:]]*$' \
  • | while IFS= read -r -d '' f; do
  • find "$f" -print0 \
  • | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs -0 mv "$f";
  • done;
  • ```
  • Or, if you prefer a one-liner:
  • ```sh
  • find . -type f -print0 | grep -z -- '-min.jpg-[[:alnum:]]*$' | while IFS= read -r -d '' f; do find "$f" -print0 | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' | xargs -0 mv "$f"; done;
  • ```
  • The code above is hardened against malicious, broken, or otherwise non-portable file names. That makes it slightly more complex than necessary.
  • Never use whitespace in file names. They are non-portable. See POSIX: <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282>.
  • For the hardened version, find(1)'s `-print0` and xargs(1)'s `-0` are common enough that don't need explanation (do an online search). grep(1)'s and sed(1)'s `-z` and read(1)'s `-r` are less common, but still common enough. read(1)'s `-d ''` is a trick explained here: <https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find#comment98776168_9612232>.
  • Here's a simpler version, which you can run if you know your file names are portable:
  • ```sh
  • find . -type f \
  • | grep -- '-min.jpg-[[:alnum:]]*$' \
  • | while read f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • `find . -type f |`:
  • Find files
  • `| grep -- '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `--` is necessary to avoid interpreting the pattern as an option to grep(1).
  • `| while read f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
#13: Post edited by user avatar alx‭ · 2023-10-15T17:34:38Z (7 months ago)
reorder, to put the safe version first
  • The first snippet is simple, but could be unsafe; you should only run it if you know that the file names that find(1) will find don't contain any whitespace. If the filenames may contain unportable characters, use the snippet at the bottom of this answer.
  • ```sh
  • find . -type f \
  • | grep -- '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . -type f |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • ----
  • Never use whitespace in file names. They are non-portable. See POSIX: <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282>. If your file system contains files or directories whose names are dangerous (i.e., contain whitespace), you'll want to use this safer version of the script:
  • ```sh
  • find . -type f -print0 \
  • | grep -z -- '-min.jpg-[[:alnum:]]*$' \
  • | while IFS= read -r -d '' f; do
  • find "$f" -print0 \
  • | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs -0 mv "$f";
  • done;
  • ```
  • find(1)'s `-print0` and xargs(1)'s `-0` are common enough that don't need explanation (do an online search). grep(1)'s and sed(1)'s `-z` are less common, but still common enough. read(1)'s `-d ''` is a trick explained here: <https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find#comment98776168_9612232>.
  • Or, if you prefer a one-liner:
  • ```sh
  • find . -type f -print0 | grep -z -- '-min.jpg-[[:alnum:]]*$' | while IFS= read -r -d '' f; do find "$f" -print0 | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' | xargs -0 mv "$f"; done;
  • ```
  • ```sh
  • find . -type f -print0 \
  • | grep -z -- '-min.jpg-[[:alnum:]]*$' \
  • | while IFS= read -r -d '' f; do
  • find "$f" -print0 \
  • | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs -0 mv "$f";
  • done;
  • ```
  • Or, if you prefer a one-liner:
  • ```sh
  • find . -type f -print0 | grep -z -- '-min.jpg-[[:alnum:]]*$' | while IFS= read -r -d '' f; do find "$f" -print0 | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' | xargs -0 mv "$f"; done;
  • ```
  • The code above is hardened against malicious, broken, or otherwise non-portable file names. That makes it slightly more complex than necessary.
  • Never use whitespace in file names. They are non-portable. See POSIX: <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282>.
  • For the hardened version, find(1)'s `-print0` and xargs(1)'s `-0` are common enough that don't need explanation (do an online search). grep(1)'s and sed(1)'s `-z` are less common, but still common enough. read(1)'s `-d ''` is a trick explained here: <https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find#comment98776168_9612232>.
  • Here's a simpler version, which you can run if you know your file names are portable:
  • ```sh
  • find . -type f \
  • | grep -- '-min.jpg-[[:alnum:]]*$' \
  • | while read f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • `find . -type f |`:
  • Find files
  • `| grep -- '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `--` is necessary to avoid interpreting the pattern as an option to grep(1).
  • `| while read f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • ----
#12: Post edited by user avatar alx‭ · 2023-10-15T17:28:34Z (7 months ago)
fix grep
  • The first snippet is simple, but could be unsafe; you should only run it if you know that the file names that find(1) will find don't contain any whitespace. If the filenames may contain unportable characters, use the snippet at the bottom of this answer.
  • ```sh
  • find . -type f \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . -type f |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • ---
  • Never use whitespace in file names. They are non-portable. See POSIX: <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282>. If your file system contains files or directories whose names are dangerous (i.e., contain whitespace), you'll want to use this safer version of the script:
  • ```sh
  • find . -type f -print0 \
  • | grep -z '-min.jpg-[[:alnum:]]*$' \
  • | while IFS= read -r -d '' f; do
  • find "$f" -print0 \
  • | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs -0 mv "$f";
  • done;
  • ```
  • find(1)'s `-print0` and xargs(1)'s `-0` are common enough that don't need explanation (do an online search). grep(1)'s and sed(1)'s `-z` are less common, but still common enough. read(1)'s `-d ''` is a trick explained here: <https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find#comment98776168_9612232>.
  • Or, if you prefer a one-liner:
  • ```sh
  • find . -type f -print0 | grep -z '-min.jpg-[[:alnum:]]*$' | while IFS= read -r -d '' f; do find "$f" -print0 | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' | xargs -0 mv "$f"; done;
  • ```
  • The first snippet is simple, but could be unsafe; you should only run it if you know that the file names that find(1) will find don't contain any whitespace. If the filenames may contain unportable characters, use the snippet at the bottom of this answer.
  • ```sh
  • find . -type f \
  • | grep -- '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . -type f |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • ---
  • Never use whitespace in file names. They are non-portable. See POSIX: <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282>. If your file system contains files or directories whose names are dangerous (i.e., contain whitespace), you'll want to use this safer version of the script:
  • ```sh
  • find . -type f -print0 \
  • | grep -z -- '-min.jpg-[[:alnum:]]*$' \
  • | while IFS= read -r -d '' f; do
  • find "$f" -print0 \
  • | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs -0 mv "$f";
  • done;
  • ```
  • find(1)'s `-print0` and xargs(1)'s `-0` are common enough that don't need explanation (do an online search). grep(1)'s and sed(1)'s `-z` are less common, but still common enough. read(1)'s `-d ''` is a trick explained here: <https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find#comment98776168_9612232>.
  • Or, if you prefer a one-liner:
  • ```sh
  • find . -type f -print0 | grep -z -- '-min.jpg-[[:alnum:]]*$' | while IFS= read -r -d '' f; do find "$f" -print0 | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' | xargs -0 mv "$f"; done;
  • ```
#11: Post edited by user avatar alx‭ · 2023-10-15T17:24:54Z (7 months ago)
  • The first snippet is simple, but could be unsafe; you should only run it if you know that the file names that find(1) will find don't contain any whitespace. If the filenames may contain unportable characters, use the snippet at the bottom of this answer.
  • ```sh
  • find . -type f \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . -type f |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • Or, if you prefer a one-liner:
  • ```sh
  • find . -type f | grep '-min.jpg-[[:alnum:]]*$' | while read -r f; do echo $f | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' | xargs mv $f; done;
  • ```
  • ---
  • Never use whitespace in file names. They are non-portable. See POSIX: <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282>. If your file system contains files or directories whose names are dangerous (i.e., contain whitespace), you'll want to use this safer version of the script:
  • ```sh
  • find . -type f -print0 \
  • | grep -z '-min.jpg-[[:alnum:]]*$' \
  • | while IFS= read -r -d '' f; do
  • find "$f" -print0 \
  • | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs -0 mv "$f";
  • done;
  • ```
  • find(1)'s `-print0` and xargs(1)'s `-0` are common enough that don't need explanation (do an online search). grep(1)'s and sed(1)'s `-z` are less common, but still common enough. read(1)'s `-d ''` is a trick explained here: <https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find#comment98776168_9612232>.
  • The first snippet is simple, but could be unsafe; you should only run it if you know that the file names that find(1) will find don't contain any whitespace. If the filenames may contain unportable characters, use the snippet at the bottom of this answer.
  • ```sh
  • find . -type f \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . -type f |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • ---
  • Never use whitespace in file names. They are non-portable. See POSIX: <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282>. If your file system contains files or directories whose names are dangerous (i.e., contain whitespace), you'll want to use this safer version of the script:
  • ```sh
  • find . -type f -print0 \
  • | grep -z '-min.jpg-[[:alnum:]]*$' \
  • | while IFS= read -r -d '' f; do
  • find "$f" -print0 \
  • | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs -0 mv "$f";
  • done;
  • ```
  • find(1)'s `-print0` and xargs(1)'s `-0` are common enough that don't need explanation (do an online search). grep(1)'s and sed(1)'s `-z` are less common, but still common enough. read(1)'s `-d ''` is a trick explained here: <https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find#comment98776168_9612232>.
  • Or, if you prefer a one-liner:
  • ```sh
  • find . -type f -print0 | grep -z '-min.jpg-[[:alnum:]]*$' | while IFS= read -r -d '' f; do find "$f" -print0 | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' | xargs -0 mv "$f"; done;
  • ```
#10: Post edited by user avatar alx‭ · 2023-10-15T17:23:57Z (7 months ago)
  • The first snippet is unsafe, and you should only run it if you know that the file names that find(1) will find don't contain any whitespace. If the filenames may contain unportable characters, use the snippet at the bottom of this answer.
  • ```sh
  • find . -type f \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . -type f |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • Or, if you prefer a one-liner:
  • ```sh
  • find . -type f | grep '-min.jpg-[[:alnum:]]*$' | while read -r f; do echo $f | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' | xargs mv $f; done;
  • ```
  • ---
  • Never use whitespace in file names. They are non-portable. See POSIX: <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282>. If your file system contains files or directories whose names are dangerous (i.e., contain whitespace), you'll want to use this safer version of the script:
  • ```sh
  • find . -type f -print0 \
  • | grep -z '-min.jpg-[[:alnum:]]*$' \
  • | while IFS= read -r -d '' f; do
  • find "$f" -print0 \
  • | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs -0 mv "$f";
  • done;
  • ```
  • find(1)'s `-print0` and xargs(1)'s `-0` are common enough that don't need explanation (do an online search). grep(1)'s and sed(1)'s `-z` are less common, but still common enough. read(1)'s `-d ''` is a trick explained here: <https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find#comment98776168_9612232>.
  • The first snippet is simple, but could be unsafe; you should only run it if you know that the file names that find(1) will find don't contain any whitespace. If the filenames may contain unportable characters, use the snippet at the bottom of this answer.
  • ```sh
  • find . -type f \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . -type f |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • Or, if you prefer a one-liner:
  • ```sh
  • find . -type f | grep '-min.jpg-[[:alnum:]]*$' | while read -r f; do echo $f | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' | xargs mv $f; done;
  • ```
  • ---
  • Never use whitespace in file names. They are non-portable. See POSIX: <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282>. If your file system contains files or directories whose names are dangerous (i.e., contain whitespace), you'll want to use this safer version of the script:
  • ```sh
  • find . -type f -print0 \
  • | grep -z '-min.jpg-[[:alnum:]]*$' \
  • | while IFS= read -r -d '' f; do
  • find "$f" -print0 \
  • | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs -0 mv "$f";
  • done;
  • ```
  • find(1)'s `-print0` and xargs(1)'s `-0` are common enough that don't need explanation (do an online search). grep(1)'s and sed(1)'s `-z` are less common, but still common enough. read(1)'s `-d ''` is a trick explained here: <https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find#comment98776168_9612232>.
#9: Post edited by user avatar alx‭ · 2023-10-15T17:23:08Z (7 months ago)
  • ```sh
  • find . -type f \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . -type f |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • Or, if you prefer a one-liner:
  • ```sh
  • find . -type f | grep '-min.jpg-[[:alnum:]]*$' | while read -r f; do echo $f | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' | xargs mv $f; done;
  • ```
  • ---
  • Never use whitespace in file names. They are non-portable. See POSIX: <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282>. If your file system contains files or directories whose names are dangerous (i.e., contain whitespace), you'll want to use this safer version of the script:
  • ```sh
  • find . -type f -print0 \
  • | grep -z '-min.jpg-[[:alnum:]]*$' \
  • | while IFS= read -r -d '' f; do
  • find "$f" -print0 \
  • | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs -0 mv "$f";
  • done;
  • ```
  • find(1)'s `-print0` and xargs(1)'s `-0` are common enough that don't need explanation (do an online search). grep(1)'s and sed(1)'s `-z` are less common, but still common enough. read(1)'s `-d ''` is a trick explained here: <https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find#comment98776168_9612232>.
  • The first snippet is unsafe, and you should only run it if you know that the file names that find(1) will find don't contain any whitespace. If the filenames may contain unportable characters, use the snippet at the bottom of this answer.
  • ```sh
  • find . -type f \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . -type f |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • Or, if you prefer a one-liner:
  • ```sh
  • find . -type f | grep '-min.jpg-[[:alnum:]]*$' | while read -r f; do echo $f | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' | xargs mv $f; done;
  • ```
  • ---
  • Never use whitespace in file names. They are non-portable. See POSIX: <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282>. If your file system contains files or directories whose names are dangerous (i.e., contain whitespace), you'll want to use this safer version of the script:
  • ```sh
  • find . -type f -print0 \
  • | grep -z '-min.jpg-[[:alnum:]]*$' \
  • | while IFS= read -r -d '' f; do
  • find "$f" -print0 \
  • | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs -0 mv "$f";
  • done;
  • ```
  • find(1)'s `-print0` and xargs(1)'s `-0` are common enough that don't need explanation (do an online search). grep(1)'s and sed(1)'s `-z` are less common, but still common enough. read(1)'s `-d ''` is a trick explained here: <https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find#comment98776168_9612232>.
#8: Post edited by user avatar alx‭ · 2023-10-15T17:21:41Z (7 months ago)
  • ```sh
  • find . -type f \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . -type f |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • Or, if you prefer a one-liner:
  • ```sh
  • find . -type f | grep '-min.jpg-[[:alnum:]]*$' | while read -r f; do echo $f | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' | xargs mv $f; done;
  • ```
  • ---
  • Never use whitespace in file names. They are non-portable. See POSIX . If your file system contains files or directories whose names are dangerous (i.e., contain whitespace), you'll want to use this safer version of the script:
  • ```sh
  • find . -type f -print0 \
  • | grep -z '-min.jpg-[[:alnum:]]*$' \
  • | while IFS= read -r -d '' f; do
  • find "$f" -print0 \
  • | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs -0 mv "$f";
  • done;
  • ```
  • find(1)'s `-print0` and xargs(1)'s `-0` are common enough that don't need explanation (do an online search). grep(1)'s and sed(1)'s `-z` are less common, but still common enough. read(1)'s `-d ''` is a trick explained here: <https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find#comment98776168_9612232>.
  • ```sh
  • find . -type f \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . -type f |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • Or, if you prefer a one-liner:
  • ```sh
  • find . -type f | grep '-min.jpg-[[:alnum:]]*$' | while read -r f; do echo $f | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' | xargs mv $f; done;
  • ```
  • ---
  • Never use whitespace in file names. They are non-portable. See POSIX: <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282>. If your file system contains files or directories whose names are dangerous (i.e., contain whitespace), you'll want to use this safer version of the script:
  • ```sh
  • find . -type f -print0 \
  • | grep -z '-min.jpg-[[:alnum:]]*$' \
  • | while IFS= read -r -d '' f; do
  • find "$f" -print0 \
  • | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs -0 mv "$f";
  • done;
  • ```
  • find(1)'s `-print0` and xargs(1)'s `-0` are common enough that don't need explanation (do an online search). grep(1)'s and sed(1)'s `-z` are less common, but still common enough. read(1)'s `-d ''` is a trick explained here: <https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find#comment98776168_9612232>.
#7: Post edited by user avatar alx‭ · 2023-10-15T17:19:18Z (7 months ago)
Add safe version
  • ```sh
  • find . -type f \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . -type f |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • Or, if you prefer a one-liner:
  • ```sh
  • find . -type f | grep '-min.jpg-[[:alnum:]]*$' | while read -r f; do echo $f | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' | xargs mv $f; done;
  • ```
  • ```sh
  • find . -type f \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . -type f |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • Or, if you prefer a one-liner:
  • ```sh
  • find . -type f | grep '-min.jpg-[[:alnum:]]*$' | while read -r f; do echo $f | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' | xargs mv $f; done;
  • ```
  • ---
  • Never use whitespace in file names. They are non-portable. See POSIX . If your file system contains files or directories whose names are dangerous (i.e., contain whitespace), you'll want to use this safer version of the script:
  • ```sh
  • find . -type f -print0 \
  • | grep -z '-min.jpg-[[:alnum:]]*$' \
  • | while IFS= read -r -d '' f; do
  • find "$f" -print0 \
  • | sed -z 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs -0 mv "$f";
  • done;
  • ```
  • find(1)'s `-print0` and xargs(1)'s `-0` are common enough that don't need explanation (do an online search). grep(1)'s and sed(1)'s `-z` are less common, but still common enough. read(1)'s `-d ''` is a trick explained here: <https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find#comment98776168_9612232>.
#6: Post edited by user avatar alx‭ · 2023-10-15T00:21:40Z (7 months ago)
  • ```sh
  • find . -type f \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . -type f |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • ```sh
  • find . -type f \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . -type f |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • Or, if you prefer a one-liner:
  • ```sh
  • find . -type f | grep '-min.jpg-[[:alnum:]]*$' | while read -r f; do echo $f | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' | xargs mv $f; done;
  • ```
#5: Post edited by user avatar alx‭ · 2023-10-14T11:02:57Z (7 months ago)
  • ```sh
  • find . -type f \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . -type f |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • ```sh
  • find . -type f \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . -type f |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*$/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
#4: Post edited by user avatar alx‭ · 2023-10-14T11:01:20Z (7 months ago)
  • ```sh
  • find . -type f \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . -type f |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the file name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • ```sh
  • find . -type f \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . -type f |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the path name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
#3: Post edited by user avatar alx‭ · 2023-10-13T22:48:20Z (7 months ago)
Find only files
  • ```sh
  • find . \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the file name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • ```sh
  • find . -type f \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . -type f |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the file name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
#2: Post edited by user avatar alx‭ · 2023-10-13T22:45:39Z (7 months ago)
  • ```sh
  • find . \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the file name in `$f`.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
  • ```sh
  • find . \
  • | grep '-min.jpg-[[:alnum:]]*$' \
  • | while read -r f; do
  • echo $f \
  • | sed 's/-min.jpg-[[:alnum:]]*/-min.jpg/' \
  • | xargs mv $f;
  • done;
  • ```
  • This should work. Be careful; I didn't try it, so it may need small corrections.
  • `find . |`:
  • Find files
  • `| grep '-min.jpg-[[:alnum:]]*$' |`:
  • Filter those that have interesting file names.
  • `| while read -r f; do`:
  • For each path name (each line), store the file name in `$f`, and run the nested commands on it.
  • `echo $f |`:
  • Echo the full path name.
  • `| sed 's/-min.jpg-[[:alnum:]]*/-min.jpg/' |`:
  • Remove the part of the file name that we don't like.
  • `| xargs mv $f;`:
  • Move the file $f (this was the old path name), to the path resulting of the previous filter.
  • `done;`:
  • Have a nice sleep :)
#1: Initial revision by user avatar alx‭ · 2023-10-13T22:43:55Z (7 months ago)
```sh
find . \
| grep '-min.jpg-[[:alnum:]]*$' \
| while read -r f; do
    echo $f \
    | sed 's/-min.jpg-[[:alnum:]]*/-min.jpg/' \
    | xargs mv $f;
done;
```

This should work.  Be careful; I didn't try it, so it may need small corrections.

`find . |`:

Find files

`| grep '-min.jpg-[[:alnum:]]*$' |`:

Filter those that have interesting file names.

`| while read -r f; do`:

For each path name (each line), store the file name in `$f`.

`echo $f |`:

Echo the full path name.

`| sed 's/-min.jpg-[[:alnum:]]*/-min.jpg/' |`:

Remove the part of the file name that we don't like.

`| xargs mv $f;`:

Move the file $f (this was the old path name), to the path resulting of the previous filter.

`done;`:

Have a nice sleep :)