-3

I want to know how to list only the name of the sub directory that has a certain permission.

The command I got so far is this:

find */* -maxdepth 2 -perm 770

but this just gives me this:

file1/file2

That file2 is that one with the permission 770; I just want to print out "file2"

  • You're specifying -maxdepth 2, if you only want to print that file, you must find inside file1. Remember find is recursive and it will show you the location of the files you're looking for. $ find /file1/ -maxdepth 2 -perm 770 unless you use some extra command – tachomi Mar 3 '16 at 22:12
  • It doesn't seem like it would be generally useful to know only the basename of the result of find. How would you know which directory it's in? (And why on earth do you have a directory named file1?) – Wildcard Mar 3 '16 at 22:16
2

There are several ways to do this. Here are two:

  1. use basename with find:

    find . -type f -perm 770 -exec basename {} \;

  2. use sed to strip off the path:

    find . -type f -perm 770 | sed -e 's:^.*/::'

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.