Bash script to check the group and permision

I am relatively new to the bash scripting

  1. I want to achieve a bash script that ensures the file /test/file is owned by the group ‘test’ and has the group read and write permissions.

  2. Update the bash script to allow an optional runtime parameter which ensures that anyone can list the contents of /test but only the owner and group can view and edit the files/directories within.


You can query all information of a file using the stat command. Consult man stat. You will see this allows you to granularly extract specific information such as owner and group using the --format option.

You can then change permissions and/or ownerships with chmod/chown according to your needs