The chgrp command changes the group ownership of a file or directory to a specified group.
Click to reveal answer
beginner
How do you change the group of a file named report.txt to staff?
Use the command: chgrp staff report.txt to change the group ownership of report.txt to staff.
Click to reveal answer
intermediate
Can chgrp change the group of multiple files at once? How?
Yes. You can list multiple files after the group name, like chgrp staff file1.txt file2.txt, to change their group ownership all at once.
Click to reveal answer
intermediate
What option do you use with chgrp to change groups recursively for directories and their contents?
Use the -R option: chgrp -R staff /path/to/directory changes the group for the directory and all files inside it.
Click to reveal answer
beginner
Who can change the group ownership of a file using chgrp?
Only the file owner or the superuser (root) can change the group ownership of a file using chgrp.
Click to reveal answer
What does the command chgrp developers project.txt do?
ACreates a new group called developers
BChanges the owner of project.txt to developers
CDeletes the project.txt file
DChanges the group of project.txt to developers
✗ Incorrect
The chgrp command changes the group ownership of the file to the specified group.
Which option allows chgrp to change groups for all files inside a directory?
A-f
B-a
C-R
D-v
✗ Incorrect
The -R option makes chgrp work recursively on directories and their contents.
Who can use chgrp to change a file's group?
AOnly the file owner or root
BOnly users in the new group
COnly root
DAny user
✗ Incorrect
Only the file owner or the superuser (root) can change the group ownership.
What happens if you run chgrp staff file1.txt file2.txt?
AChanges group of file1.txt only
BChanges group of both files to staff
CChanges group of file2.txt only
DCreates two new files
✗ Incorrect
Listing multiple files changes the group for all listed files.
If you want to see what chgrp is doing, which option should you add?
A-v
B-q
C-s
D-n
✗ Incorrect
The -v (verbose) option shows details of the changes made.
Explain how to change the group ownership of a file and what permissions are needed.
Think about who owns the file and the command format.
You got /3 concepts.
Describe how to change the group ownership of all files inside a directory.
Consider how to apply changes to multiple files at once.
You got /3 concepts.
Practice
(1/5)
1. What does the chgrp command do in Linux?
easy
A. Changes the file name
B. Changes the user ownership of a file or directory
C. Changes the permissions of a file or directory
D. Changes the group ownership of a file or directory
Solution
Step 1: Understand the purpose of chgrp
The chgrp command is specifically designed to change the group ownership of files or directories.
Step 2: Differentiate from similar commands
Changing user ownership is done by chown, and changing permissions is done by chmod. Renaming files uses mv.
Final Answer:
Changes the group ownership of a file or directory -> Option D
Quick Check:
chgrp changes group ownership [OK]
Hint: Remember: chgrp = change group ownership [OK]
Common Mistakes:
Confusing chgrp with chown (user ownership)
Thinking chgrp changes permissions
Mixing up chgrp with mv (rename)
2. Which of the following is the correct syntax to change the group of a file named report.txt to staff?
easy
A. chgrp report.txt staff
B. chgrp staff report.txt
C. chgrp -g staff report.txt
D. chgrp -u staff report.txt
Solution
Step 1: Recall the basic syntax of chgrp
The correct syntax is chgrp [group] [file]. So the group name comes first, then the file name.
Step 2: Analyze each option
chgrp staff report.txt matches the correct syntax. chgrp report.txt staff reverses the order. chgrp -g staff report.txt uses an invalid flag -g. chgrp -u staff report.txt uses -u which is not valid for chgrp.
Final Answer:
chgrp staff report.txt -> Option B
Quick Check:
Syntax: chgrp group file [OK]
Hint: Group name first, then file name in chgrp [OK]
Common Mistakes:
Swapping group and file arguments
Using invalid flags like -g or -u
Confusing chgrp syntax with chown
3. What will be the output or effect of the command: sudo chgrp -R developers /home/project?
medium
A. Change the group ownership of /home/project and all its contents to developers
B. Change the user ownership of /home/project to developers
C. Change the group ownership of /home/project only, not its contents
D. Show an error because -R is invalid with chgrp
Solution
Step 1: Understand the -R option
The -R flag means recursive, so it applies the group change to the directory and all files and subdirectories inside it.
Step 2: Understand the use of sudo
sudo is used to run the command with root privileges, which is often needed to change group ownership on files you don't own.
Final Answer:
Change the group ownership of /home/project and all its contents to developers -> Option A
Quick Check:
chgrp -R changes group recursively [OK]
Hint: Use -R to change group recursively on directories [OK]
Common Mistakes:
Thinking -R only changes the directory itself
Confusing group change with user change
Assuming -R is invalid for chgrp
4. You run chgrp staff report.txt but get the error: chgrp: changing group of 'report.txt': Operation not permitted. What is the most likely fix?
medium
A. Use chmod instead of chgrp
B. Change the file name to staff
C. Run the command with sudo to get permission
D. Restart the system and try again
Solution
Step 1: Understand the error message
The error means you don't have permission to change the group ownership of the file.
Step 2: Use elevated privileges
Using sudo runs the command as root, which usually has permission to change group ownership.
Final Answer:
Run the command with sudo to get permission -> Option C
Quick Check:
Permission errors need sudo [OK]
Hint: Use sudo if permission denied on chgrp [OK]
Common Mistakes:
Trying to rename file instead of changing group
Using chmod which changes permissions, not group
Restarting system won't fix permission issues
5. You want to change the group ownership of all files with extension .log inside /var/logs and its subdirectories to adm. Which command will do this correctly?
hard
A. sudo find /var/logs -type f -name '*.log' -exec chgrp adm {} +
B. sudo chgrp -R adm /var/logs/*.log
C. chgrp adm /var/logs/*.log
D. sudo chgrp adm /var/logs -name '*.log'
Solution
Step 1: Understand the requirement
You need to change group ownership of all .log files inside /var/logs and all its subdirectories.
Step 2: Analyze each option
sudo find /var/logs -type f -name '*.log' -exec chgrp adm {} + uses find to locate all .log files recursively and runs chgrp adm on them, which is correct. sudo chgrp -R adm /var/logs/*.log tries to use chgrp -R on a wildcard which only expands in the current directory, not recursively. chgrp adm /var/logs/*.log lacks sudo and is not recursive. sudo chgrp adm /var/logs -name '*.log' uses invalid syntax with -name directly on chgrp.
Final Answer:
sudo find /var/logs -type f -name '*.log' -exec chgrp adm {} + -> Option A
Quick Check:
Use find with exec for recursive selective chgrp [OK]
Hint: Use find with exec to change group on specific files recursively [OK]
Common Mistakes:
Using chgrp -R with wildcards which is not recursive
Forgetting sudo for permission
Trying to use -name option with chgrp
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.