0

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.

3
  • Can you give us a use case with examples?
    – Nmath
    Commented Aug 19, 2021 at 0:56
  • 1
    Read man stat;man -a chmod. Your owner/group/world question is a classic Linux permission use case.
    – waltinator
    Commented Aug 19, 2021 at 1:07
  • 1
    Explore your permission/ownership problems with https://github.com/waltinator/pathlld. A bash script to answer "Why can't I Read/Write that file?".
    – waltinator
    Commented Aug 19, 2021 at 1:08

1 Answer 1

2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .