Score:0

Bash script to check the group and permision

ug flag

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.

Nmath avatar
ng flag
Can you give us a use case with examples?
waltinator avatar
it flag
Read `man stat;man -a chmod`. Your owner/group/world question is a classic Linux permission use case.
waltinator avatar
it flag
Explore your permission/ownership problems with `https://github.com/waltinator/pathlld`. A `bash` script to answer "Why can't I Read/Write that file?".
Score:2
cn flag

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

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.