I have many files that I want to process with a software that run via command line. Every execution will take around 8 hours, so I want to automate this process.

How can I make a script that automate this? I imagine the algorithm is like: call the command to process file 1, wait until it finish, call the command to process file 2, etc. It is like a queue. I can write in shell script, python, or java.

  • run it on every file in a directory?
    – Seth
    Feb 13, 2017 at 1:42
  • Yes. I will put the file inside a directory.
    – Bharata
    Feb 13, 2017 at 1:53

2 Answers 2


Using bash by default one command doesn't start until the first one finishes so you can use:

/path/to/command /path/to/file1
/path/to/command /path/to/file2
/path/to/command /path/to/file3

Put the commands in a script called for example ~/run-all-commands. Then mark it as executable using:

chmod +x ~/run-all-commands

Then call the bash script with batch of commands using:


make ls to get a list of your folders.

write a script and call it script arguments with the arguments being your folders.

the script does this:

sp = $(pwd)

for i in $@
  cd $i
  cp ../command .
  cd $sp

I'm assuming command is a local script itself. If its something in ~/bin or /bin you can just call it like any other.

  • First of all, you don't need to call cd $sp every single time. Just cd at the beginning of the script. Second, it makes no sense to provide directories as arguments,too, since you can cd into folder once. Feb 23, 2017 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.