-1

I was trying to run a program in Linux with syntax like this:

BET2 <input file> <output file>

This program would take an image and perform some preprocessing on it then save to a new file. Now I could run the program correctly. However, I have about 1 million images and I don't want to run them one by one manually.
So, my question is, is there any way I could do the following:

  1. find all the images (.jpg file) under the current directory
  2. let each image (something.jpg) be the input of the preprocessing program and name the output with something_processed.jpg
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Ke Xu
  • 35
  • 3
  • Possible duplicate of [Loop through all the files with a specific extension](https://stackoverflow.com/q/14505047/608639), [How to get the list of files in a directory in a shell script?](https://stackoverflow.com/q/2437452/608639), [find a pattern in files and rename them](https://stackoverflow.com/q/15290186/608639), [Find multiple files and rename them in Linux](https://stackoverflow.com/q/16541582/608639), etc. Where are you having trouble? – jww Mar 26 '19 at 04:06

2 Answers2

-1

You could use something like

 ls *.jpg | xargs -I{} BET2 {} processed_{}
BlackPearl
  • 1,662
  • 1
  • 8
  • 16
  • This would break if the list of files generated in this way would be larger than the maximum number of files in the command line. Also, files which have names with embedded newline would cause trouble. It should also be noted that this finds only files in the current directory. Maybe this is, maybe this is not what the OP wants. He writes (a bit unclear) "**under** the current directory", not "**in** the current directory", and I understood this to mean "some subdirectory below the current directory". – user1934428 Mar 26 '19 at 07:07
-1

You can achieve your task by executing a command similar to the one below:

cd "/path/to/the/folder/containing/your/images"
for CURRENT_IMAGE in `find *.jpg -maxdepth 0`; do
  echo "Preprocessing image file $CURRENT_IMAGE"
  # Your program that performs the image preprocessing 
  BET2 "$CURRENT_IMAGE" "${CURRENT_IMAGE}_processed.jpg"
done

Hope it helps :)