Unix Questions and Answers – Changing File Ownership and Permissions – 2

This set of Unix Questions and Answers for Experienced people focuses on “Changing File Ownership and Permissions – 2”.

1. While changing permissions in an absolute manner, we explicitly set all the nine bits irrespective of the previous permissions of the file.
a) True
b) False
View Answer

Answer: a
Explanation: The expression used by chmod in an absolute manner is a string of three octal numbers (base 8). A set of 3 bits represent a single octal digit.
-> Read permission –4 (100 in octal)
-> Write permission –2(010 in octal)
-> Execute permission –1(001 in octal)
For each category, we add up these numbers. For example, if we have to set read and write permission then an octal number will be 110 (4+2).

2. What are the permission of file01 after executing this command?

   chmod  777  file01

a) rwxrwxrwx
b) rw-rw-rw
c) r–r–r–
d) r–r—-
View Answer

Answer: a
Explanation: Since the octal number for the above command is 777 and we know that 7(111) represents all the three sets of permissions (read, write and execute) for a category of user. As we have 777, the file is readable, writable and executable by anyone.
advertisement
advertisement

3. A file named file01 should be readable, writable and executable only by the user(owner). Which one of the following set of command will be used?
a) chmod 700 file01
b) chmod 000 file01
c) chmod 477 file01
d) chmod 777 file01
View Answer

Answer: a
Explanation: Since 7(111) represents read, write, execute permission. So 700 will represent read, write, execute permission only for the user (owner).
Note: Join free Sanfoundry classes at Telegram or Youtube

4. A file has a permission set as 000 i.e. — — —. Can the file be deleted?
a) Yes
b) No
View Answer

Answer: a
Explanation: The file having permission set as 000 is useless i.e. it is not readable, writable or executable. But we can delete the file using directory permissions. If the directory has write permission, we can easily add or remove a file from it.

5. A file has a permission set as 777 ie rwxrwxrwx but the directory permissions are 400. If the user tries to delete the file, will he be able to do it?
a) Yes
b) No
View Answer

Answer: b
Explanation: Since we have only read permissions for the directory and the directory permissions do not allow us to add or remove a file from it we cannot delete a file no matter what is the permission set of that file.
advertisement

6. Which command is used to change the ownership of a file?
a) chmod
b) change
c) ch
d) chown
View Answer

Answer: d
Explanation: For changing the file ownership, we use the chown command. chown transfer the ownership of a file to another user. The command requires the user-ID (UID) of the recipient. To change the ownership of a file from user01 to user02, use the following commands:

1. Change your status to a super user.
2. # chown mash  file01            // # indicates another shell 
3. exit

advertisement

7. Which option is used for the recursive functioning of chmod command?
a) -R
b) -r
c) -l
d) -i
View Answer

Answer: a
Explanation: Like other UNIX commands, chmod can also descend a directory hierarchy and apply the expression to every file and subdirectories it finds. This is done using -R option. For example,

chmod -R a+w  dir01

This command will make all files and subdirectories found in the tree walk executable by all users.

8. Which command is used to change the group owner of the file?
a) chown
b) ch
c) chgrp
d) chmod
View Answer

Answer: c
Explanation: A user can change the group owner of a file but only to that group to which he belongs. A user can belong to more than one group and the one shown in /etc/psswd is the user’s main group.

9. A user can change the group ownership of a file to another group to which he does not belong.
a) True
b) False
View Answer

Answer: b
Explanation: Group ownership can be changed only to that group to which the user also belongs otherwise a user cannot change the group ownership of a file to another group to which he does not belong.

10. Like chmod, chown and chgrp can also use ___ option.
a) -R
b) -r
c) -x
d) -i
View Answer

Answer: a
Explanation: Like chmod, chown and chgrp use the -R option to perform their operations in a recursive manner.

11. UNIX allows the system administrator to use the only chown to change both owner and group.
a) True
b) False
View Answer

Answer: a
Explanation: UNIX provides a special privilege for the system administrator to change both the owner and group using chown command only. The syntax requires two arguments to be separated by a (:). For example,

 
chown  abd:grp01  file01.txt     // ownership to abd, group to grp01

12. Which symbol is used to change permissions for hidden files?
a) .
b) &
c) $
d) *
View Answer

Answer: a
Explanation: To change permissions for hidden files, use the (.) symbol with chmod command.

 
$ chmod 755  .    // works on hidden files

Sanfoundry Global Education & Learning Series – Unix.

To practice all areas of Unix for Experienced people, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.