2

I want to make the files in the current directory, sub-directories, and sub-directories within the sub-directories.

Eg. Pretend my file structure is as follow

|
+-A
  + 1.file
  +-B
    + 2.file
    +-C
      + 3.file

I want to chown 1.file, 2.file, and 3.file, with one command. Is there anyway I can do it? And can I go deeper with this?

  • Do you want to change ownership of all files in a directory? – Arkadiusz Drabczyk Jun 9 '18 at 17:06
  • To make sure: you explicitly don't want to change ownership of the directories themselves? (A vague direction might be find . -type f ...) – Ulrich Schwarz Jun 9 '18 at 17:09
  • @ArkadiuszDrabczyk I want to change ownership of all the files within a directory. e.g. If my imaginary folder A had more files, I want to change those files too. – xcvr48 Jun 9 '18 at 17:11
1

IIUC, you want:

find . -type f  -print0 | xargs -0 -r chown <CHOWN_ARGS>
2

You can do it simply in one find command.

First, make sure you are getting the right result that you want:

find ./ -type f

If you are satisfied with the results:

find ./ -type f -exec chown <user>:<group> {} \;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.