Читать книгу Linux Bible - Christopher Negus - Страница 136
Changing file ownership
ОглавлениеAs a regular user, you cannot change ownership of files or directories to have them belong to another user. You can change ownership as the root user. For example, suppose that you created a file called memo.txt
in the user joe
's home directory while you were root user. Here's how you could change it to be owned by joe
:
# chown joe /home/joe/memo.txt # ls -l /home/joe/memo.txt -rw-r--r--. 1 joe root 0 Dec 19 11:23 /home/joe/memo.txt
Notice that the chown
command changed the user to joe
but left the group as root
. To change both user and group to joe
, you could enter the following instead:
# chown joe:joe /home/joe/memo.txt # ls -l /home/joe/memo.txt -rw-r--r--. 1 joe joe 0 Dec 19 11:23 /home/joe/memo.txt
The chown
command can be use recursively as well. Using the recursive option (-R
) is helpful if you need to change a whole directory structure to ownership by a particular user. For example, if you inserted a USB drive, which is mounted on the /media/myusb
directory, and you wanted to give full ownership of the contents of that drive to the user joe
, you could enter the following:
# chown -R joe:joe /media/myusb