Previous Section  < Day Day Up >  Next Section

Recipe 9.6. Doing Batch Operations with chown

9.6.1 Problem

You want to change ownership of directories and their contents, or just the contents of directories, a list of files, or change ownership of files from one UID to another.

9.6.2 Solution

chown supports some batch operations, or you can use find, or you can use shell wildcards.

To change several files at once with chown, use a space-delimited list:

# chown carlas file.txt file2.txt file3.txt

Alternatively, you can use shell wildcards:

# chown carlas *.txt

To give all of a user's files to another user, use:

# chown -R -v  —from valh  piglet   /shared/scripts

You can do the same thing with find:

# find / -user valh -exec chown -v piglet {  } \;

find can also search by UID, which chown cannot:

# find / -uid 1050 -exec chown -v 1200 {  } \;

To change the ownership of a directory, including subdirectories and files, with verbose output, use:

# chown -R -v  piglet  /shared/scripts

changed ownership of `scripts' to piglet

changed ownership of `scripts/backups.tgz' to piglet

changed ownership of `scripts/fake-spec-rpm' to piglet

Either the user's login name or UID can be used. If you've deleted a user and the user has left behind orphan files, you'll need the UID.

9.6.3 See Also

  • info chown

  • Recipe 8.6, for how to hunt down and change all files on the system belonging to a particular user

    Previous Section  < Day Day Up >  Next Section