How to run all scripts in a directory on Linux

Question: I have a bunch of scripts in a directory. I want to automatically run all the scripts in the directory, regardless of how many these are.

If you want to run all scripts or executable binaries in a particular directory, you can use a command line utility called run-parts. This tool can automatically discover multiple scripts or programs in a directory, and run them all.

You can use run-parts command in the following format.

$ run-parts [options] <target-directory>

Scripts found in a directory will be run one by one in a lexically sorted order. run-parts will execute all the scripts whose names consist of alphanumeric letters, underscores and hyphens.

For example, to run all scripts in the current directory:

$ run-parts .

Optionally, you can run only those scripts whose names are matched with a regular expression. For that, use "--regex" option.

For example, to run all scripts in /etc whose names start with 'a' and end with '.sh':

$ run-parts --regex '^a.*\.sh$' /etc

With "--test" option, you can print the names of the scripts which would be executed, without actually running them. This is useful for testing purpose.

$ run-parts --test ./my_script_directory

Subscribe to Ask Xmodulo

Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.

2 thoughts on “How to run all scripts in a directory on Linux

  1. on my system I can see 'run-parts' processes being launched by cron, they are processing the cron folders in /etc.

Leave a comment

Your email address will not be published. Required fields are marked *

Current day month ye@r *