Post History
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 ...
Answer
#14: Post edited
- ```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
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:```shfind . -type f -print0 \| grep -z -- '-min.jpg-[[:alnum:]]*$' \| while IFS= read -r -d '' f; dofind "$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:```shfind . -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
- 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
- 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:```shfind . -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
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
- ```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
- ```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
- ```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
- ```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
- ```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
- ```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
- ```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
- ```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
```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 :)