home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 22.20 Why Can't You Change File Ownership Under BSD UNIX? Chapter 22
File Security, Ownership, and Sharing
Next: 22.22 The su Command Isn't Just for the Superuser
 

22.21 How to Change File Ownership Without chown

UNIX systems with disk quotas (24.17 ) won't let you change the owner (22.20 ) of a file; only the superuser can use chown . Here's a workaround for those systems.

  1. The file's current owner should make sure that the new owner has write permission on the directory where the file is and read permission on the file itself:

    jerry% ls -ld . afile
    
    
    drwxr-xr-x   2 jerry    512  Aug 10 12:20 .
    -rw-r--r--   1 jerry   1934  Aug 10 09:34 afile
    jerry% chmod go+w .
    
    

  2. The new owner (logged in as herself) should rename the file, make a copy, and delete the original file. If the new owner is there at the same time, su (22.22 ) is probably the fastest way to change accounts:

    
    
    
    
    
    -f
     
    
    jerry% su laura
    
    
    Password:
    laura% mv afile afile.tmp
    
    
    laura% cp -p afile.tmp afile
    
    
    laura% ls -l afile
    
    
    -rw-r--r--   1 laura   1934  Aug 10 09:34 afile
    laura% rm -f afile.tmp
    
    
    laura% exit
    
    
    jerry% chmod go-w .
    
    

The cp -p (18.15 ) command preserves the file's original permissions and last modification time. After the new owner (laura ) is done copying, the old owner (jerry ) takes away the directory's write permission again.

- JP


Previous: 22.20 Why Can't You Change File Ownership Under BSD UNIX? UNIX Power Tools Next: 22.22 The su Command Isn't Just for the Superuser
22.20 Why Can't You Change File Ownership Under BSD UNIX? Book Index 22.22 The su Command Isn't Just for the Superuser

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System