Suppose you've been working on a file called rowyourboat, and your boss decides to let a coworker, Merrilee, take over the project. In this case, to fully pawn off the project to your coworker, you need to change ownership of the file from you to her. Depending on how your system administrator set up the system, you can usually change ownership of files using chown (Code Listing 5.6).
To change ownership with chown:
1. | ls -l For starters, type ls -l at the shell prompt to verify the file's name and ownership, as in Code Listing 5.6. Remember that the ownership information is located after the permissions and linking information. |
2. | chown merrilee rowyourboat Type chown followed by the userid of the person you want to transfer ownership to and the file name. In this case, the chown command changes the ownership for rowyourboat to merrilee. rowyourboat and its associated problems will now be hers, and life will be but a dream. |
[ejr@hobbes merrilee]$ ls -l total 26 -rw-rw-r-- 1 ejr users 24850 Jul 24 15:17 rowtheboat [ejr@hobbes merrilee]$ chown merrilee rowtheboat [ejr@hobbes merrilee]$ ls -l total 26 -rw-rw-r-- 1 merrilee users 24850 Jul 24 15:17 rowtheboat [ejr@hobbes merrilee]$ |
Tip
After you change a file's ownership, what you can do with the file depends on the group and other permissions and memberships. The new owner, however, will be able to do anything with the file.
Tip
You can add the -R flag to chown to make it apply to subdirectories.
Tip
If your system administrator is particularly security-conscious and set up the system so that you cannot use chown, consider using cp to make your owncopy of a file to accomplish the same thing. If you copy someone else's file (that you have permission to read) to another name or location, the copy is fully yours. (In this giving-the-file-away example, the recipient should use cp.)
Tip
Even if your system administrator has set up the system so you can't use chown, you could still be able to request that he or she change file ownership for you: "Could you please change the ownership of my rowyourboat file to Merrilee, with chown merrilee /home/shared/me/rowyourboat. Thanks!"
18.222.111.24