Using the chown Command in Ubuntu¶
In the Ubuntu system, you can use the chown command to modify the owner and group of a file or folder. Here are the specific usage details:
1. Basic Syntax¶
chown [options] username:groupname filename/foldername
2. Common Operation Examples¶
- Change the owner of a file:
sudo chown username filename.txt
- Change the owner and group of a folder:
sudo chown username:groupname /path/to/directory
- Recursively change the owner and group of a folder and its contents:
sudo chown -R username:groupname /path/to/directory
3. Option Explanation¶
-
-R: Recursive processing, used for directories, which will apply to all files and subdirectories under the directory. -
To modify the group alone, use the
chgrpcommand:chgrp groupname filename
Note: Modifying a file’s owner usually requires administrative privileges, so sudo is generally needed. Verify the path and username/group name correctness before executing the command to avoid accidental operations.