UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 22.2 Tutorial on File and Directory Permissions Chapter 22
File Security, Ownership, and Sharing
Next: 22.4 Setting an Exact umask
 

22.3 Who Will Own a New File?

If you share files with other users, it's good to be able to tell who will own each file. On BSD-based systems, this is even more important because only the superuser can change file ownership (22.20, 22.21).

  1. When you create a new file, it belongs to you.

  2. When you append to a file with >>file, the owner doesn't change because UNIX doesn't have to create a new file.

  3. When you rename a file with mv, the ownership doesn't change.

    Exception: if you use mv to move a file to another filesystem (1.22), the moved file will belong to you - because, to move across filesystems, mv actually has to copy the file and delete the original.

  4. When you copy a file, the copy belongs to you because you created it (22.11).

  5. When you edit a file:

    • With an editor like vi (30.2), the file keeps its original owner because a new file is never created.

    • An editor like Emacs (32.1), which makes a backup copy, can be different. The backup copy could belong to you or to the original owner. If you replace the edited file with its backup, the file's ownership might have changed:

      % emacs filea
         ...Edit a lot, then decide you don't want your changes...
      % mv filea~ filea

If you aren't sure, use ls -l (22.2).

- JP


Previous: 22.2 Tutorial on File and Directory Permissions UNIX Power ToolsNext: 22.4 Setting an Exact umask
22.2 Tutorial on File and Directory Permissions Book Index22.4 Setting an Exact umask

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