How to run all scripts in a directory on Linux
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]
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
Comments
Post a Comment