Using inotifywait
As mentioned, you can use inotify-tools
(inotifywait
) to watch a specific directory for changes, for example by the script below, and subsequently set new files executable recursively.
The script uses the inotifywait
-command, which is triggered by specific events, set by the -e
-option. Luckily the command can be used in combination with multiple event types.
Since you want the files inside the directory to be executable, in the script, two events are set:
-e move
which will notice files moved into the directory, and
-e create
which will notice new files created inside the directory.
Furthermore, the options:
-m -r
are to make the command run indefinitely ("monitor") and recursively in the directory, while:
--format '%w%f'
outputs the directory (path to the file, %w
) plus the filename (%f
) that caused the event.
More on options of inotifywait
can be found here, or, as always, in man inotifywait
The script
#!/bin/sh
# you might want to change the directory below into the targeted directory
DIR="/home/jacob/Bureaublad/test123"
inotifywait -m -r -e move -e create --format '%w%f' "$DIR" | while read f
do
chmod +x "$f"
done
How to use
You will probably have to install inotify-tools
first:
sudo apt-get install inotify-tools
Copy the script into an empty file, save it as set_executable.sh
In the head of the script, set the path to the targeted folder:
# change the directory below into the targeted directory
DIR="/home/jacob/Bureaublad/test123"
...and test-run the script from a terminal.
- If all works fine, add the script to Startup Applications: Dash > Startup Applications > Add.
Note
Note that notifywait
acts on changes (events). That implies that files that were added or created before the script ran will not be effected. Nor will it re- set the files executable if you manually and deliberately set them not to be executable, while they are inside the targeted directory.