Black Friday 2025 – NPI EA (cat = Baeldung on Linux)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

Baeldung Pro – Linux – NPI EA (cat = Baeldung on Linux)
announcement - icon

Learn through the super-clean Baeldung Pro experience:

>> Membership and Baeldung Pro.

No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.

Partner – Orkes – NPI EA (tag=Kubernetes)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

1. Overview

The find command is a useful tool for finding files and directories on our filesystem that match certain criteria. Some examples of these criteria are file size, creation time, modified time, and permissions.

While it’s straightforward to find files that have certain permissions, it is not immediately obvious how to do the opposite.

In this tutorial, we’ll see how to find files that don’t have certain permissions.

2. Finding Files With Specified Permissions

Let’s say we have a few files with various permissions:

$ ls -l
-rw------- 1 user user 0 Feb 17 19:31 file1
--w------- 1 user user 0 Feb 17 19:31 file2
-rwxr--r-- 1 user user 0 Feb 17 19:31 file3
-rw-r--r-- 1 user user 0 Feb 17 19:31 file4
-rw-r--r-- 1 user user 0 Feb 17 19:31 file5
-rw-r--r-- 1 user user 0 Feb 17 19:31 file6

We can use the -perm flag of the find command to search these, based on their permissions. For example, let’s look for files that are user-executable:

$ find . -type f -perm -u+x
./file3

But now, let’s say we want the list of files that are not group readable. We might be tempted to use the -perm flag with -g-r as the parameter:

$ find . -type f -perm -g-r
./file3
./file2
./file4
./file5
./file6
./file1

This command has returned all files that are readable by the group, which is the opposite of what we’re looking for.

3. Negating the Values of the -perm Flag

To find files that do not have specific permissions, we can use the negation (!) symbol along with the -perm flag:

$ find . -type f ! -perm -g+r
./file2
./file1

That’s exactly what we wanted. Files file1 and file2 are not readable by other users belonging to the group.

Let’s try to understand this usage a bit further. We started by finding files that were group-readable, using the flag “-perm -g+r” to do that. Then, we negated the whole thing: “! -perm -g+r”.

Let’s try another example to get the hang of it. Here’s how we can find files that are not readable by the owner:

$ find . -type f ! -perm -u+r
./file2

And, that gives us the expected output.

4. Variations Between find Versions

The solution discussed above works on most of the common Unix-like operating systems. However, the GNU find variant has an easier way with the -readable, -writable, and -executable flags. These flags only work relative to the owner and can’t be used to find files that lack other permissions.

Let’s list all files that are executable by the logged-in user:

$ find . -type f -executable
./file3

Likewise, we can find files that are not readable by the owner:

$ find . -type f ! -readable
./file2

However, these options don’t work on BSD, macOS, or other Unix variants.

5. Conclusion

In this tutorial, we first saw how to use the find command to find files matching specific permissions. Then we saw how to use negation to find files not matching the specified permissions.