we want to check that all files and folders under /hadoop/hdfs are with permissions - hdfs:hadoop

is it possible to do this test with find command ?

in case find capture files/folder that not have this permissions then find will print these files/folders


You may list all entries under /hadoop/hdfs that does not belong to user hdfs and group hadoop with

find /hadoop/hdfs ! '(' -user hdfs -group hadoop ')' -ls

The -ls at the end will list the found pathnames in a format that is reminiscent of the output from ls -l.


Yes, this is possible using find with the arguments -user and -group. For example, find /path/to/your/directory/* -user uname -group gname lists all files (folders are also just files) in the specified directory, that have the specified user and group ownership. You might also want to use the argument -type to limit your results to only certain file types, see man find for list of known types if you are in need.

However, if you just want to make sure that all files and folders have the correct ownership, an easier solution could be to just overwrite all existing permissions, whatever they might be, using chown without checking the old permissions first, but it depends on your use case if this is tolerable. For example, you could just cd into your directory of choice, and traverse this and all subdirectories using chwon -R uname:gname. Granted you have the permissions, every file (read: all files and folders) will have the specified user and group ownership afterwards.

  • can you please give example of that syntax?
    – yael
    Apr 22 '18 at 9:40
  • find /path/to/files -user hdfs -group hadoop for instance. Or if you're referring to his second suggestion chown -R hdfs:hadoop /path/to/files/ (use the latter with caution since it can cause all kinds of problems if pointed at the wrong directory). Apr 22 '18 at 10:16
  • @yael see my updated answer for examples - however, given the recent answer from Kusalananda below, I think he might have grasped the intention of your question better than me, so this might be what you actually want
    – Wanderer
    Apr 22 '18 at 10:27

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.