Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • Quite a few issues: (1) filenames can be made of several lines so can't be processed line-wise (2) you're not quoting that backslash or $. Should be grep '\.png$'. (3) s/image// removes the first image in the path, so for a ./my-images/image0001.png that would try and do mv ./my-images/image0001.png ./my-s/image0001.png and fail. You'd want to process the list depth first and only do the rename on the basename. Commented Dec 2, 2022 at 15:02
  • (continued) (4) xargs expects the words on input in a very specific format, which sed is not providing here. For instance, if the file paths contain quotes or blanks or backslash, that will fail. (5), echo can't be used for arbitrary data. (6), there are missing quotes around the $0, $1,$2. Commented Dec 2, 2022 at 15:03
  • @StéphaneChazelas feel free to edit my answer if you are willing to; my answer does not cover all the depth-in and many other things, it directly answers the question about one directory containing batch of images; from my perspective this rather simple solution Commented Dec 5, 2022 at 11:51
  • Because of the missing quotes, this \. doesn’t do what you think it does: echo \. prints ., without the backslash. Also, why waste resources piping find into grep when you can use -name? Commented Mar 11, 2024 at 17:54