0

I just migrated from Fedora 20 to Arch and copied over some files-everything under my Documents, to be specific, and ls -lh outputs drwxr-xr-x 2 alex users 16K Jul 3 02:40 algo where alex is my account name. How do I chown all files in all subdirectories so that my new user on Arch owns them?

1 Answer 1

1

There are two ways:-

find Documents/ -exec chown user:group "{}" \;

Or, for as many levels of subdirectories as you have:-

chown user:group Documents/* Documents/*/* Documents/*/*/* ...

The first method needs less typing and does not follow symbolic links unless you add options to the find command; the second runs faster and will follow symbolic links.

You may need root privileges to be able to run the chown command.

After valuable feedback from user2313067 below, the optimal command is:-

chown -R user:group Documents/*

As in find there are other options to control whether symbolic links are followed.

5
  • The second ran instantly...did it work right? It still says users
    – user341106
    Jul 4, 2014 at 0:12
  • What did you mean by user:group, what do I put there?
    – user341106
    Jul 4, 2014 at 0:17
  • user:group refers to the user and group names (or numbers) that you want to take ownership. See man chown.
    – AFH
    Jul 4, 2014 at 11:23
  • I think there is a -R option to chown to make it recursive. Jul 4, 2014 at 16:50
  • @user2313067 - Thanks for pointing that out: I've not needed it myself, so didn't look for it. It makes the use of find completely redundant, since there are options to give the same control over whether symbolic links are followed. I'll update my answer.
    – AFH
    Jul 4, 2014 at 18:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .