When a user creates a new file, it belongs to the user who created it and to the current group of the user. Any user other than the owner of the file can't change ownership of a file, except the superuser. A user can change group membership of a file only if he or she is member of both the old and new groups. In normal circumstances, the system administrator needs to change file and group ownership when copying files to new user directories or when making files available to new users or groups.
In HP-UX, you use chown (CHange OWNer) for changing the owner of a file and chgrp (CHange GRouP) for changing group membership of a file. Let us see what happens when we change the owner of a file from user boota to jim .
$ ll file1 -rwxrwxrwx 1 boota users 0 Sep 8 18:06 file1 $ chown jim file1 $ ll file1 -rwxrwxrwx 1 jim users 0 Sep 8 18:06 file1 $
Note that the user name is changed in the third field. We don't need to mention the old owner name when changing ownership of a file with the chown command.
A similar method is used for changing the group ownership of file1 from users to root with the chgrp command.
$ ll file1 -rwxrwxrwx 1 jim users 0 Sep 8 18:06 file1 $ chgrp root file1 $ ll file1 -rwxrwxrwx 1 jim root 0 Sep 8 18:06 file1 $
Multiple file names and wildcard characters can also be used with chown and chgrp . Names of a new owner and group must be present in the /etc/passwd and /etc/group files, respectively. The chown command can also be used to change the owner and group in one step. See the following example, where the owner and group are used together with a colon symbol.
$ ll file1 -rwxrwxrwx 1 boota users 0 Sep 8 18:06 file1 $ chown jim:root file1 $ ll file1 -rwxrwxrwx 1 jim root 0 Sep 8 18:06 file1 $
To change the ownership or group of a directory tree, you can use the -R option with both of these commands and with the directory name as argument. Whenever you change ownership of a link file, ownership of the file to which the link points is also changed. To avoid this, use the -h option with the chown or chgrp commands.
Study BreakDealing with File Permissions
|
Top |