I wanted to write a bash script for to give permission to the directory path and the file path
chmod 750
chmod 644
Please help me out in this.
I wanted to write a bash script for to give permission to the directory path and the file path
chmod 750
chmod 644
Please help me out in this.
Use the -f
and -d
to determine if it is a dir or file and run chmod on it:
#!/bin/bash
input="$1"
# make sure we get the CLI input or dir with an error
[ "$input" == "" ] && { echo "Usage: $0 dir|filename"; exit 1; }
# is it a file?
[ -f "$input" ] && { echo "$input is a file"; chmod 750 "$input"; }
# is it a dir?
[ -d "$input" ] && { echo "$input is a dir"; chmod 644 "$input"; }
Run it as follows:
chmod +x script
./script /path/to/dir
./script /path/to/file