Explaining Find Command's "-perm mode", "-perm -mode" & "-perm /mode" in Linux

  • Thread starter shivajikobardan
  • Start date
  • Tags
    Linux
In summary, the conversation discusses the use of the "find" command and its different options for finding files based on permissions. The commands "-perm 644", "-perm -600", and "-perm /700" are explained and their potential use cases are mentioned, such as checking for vulnerable files or monitoring for unauthorized changes.
  • #1
shivajikobardan
674
54
TL;DR Summary
When to use "-perm mode", "-perm -mode" and "-perm /mode" in find command Linux?
I am reading the find documentation and find this pretty confusing.

I'll try to explain what I've understood. You can add your explanation to this.


Code:
 .
    ├── file1.txt (Permission: 644)
    ├── file2.txt (Permission: 600)
    └── subdir
        ├── file3.txt (Permission: 755)
        └── file4.txt (Permission: 700)

Say we have a scenario like this.
Code:
    $ find . -perm 644
    ./file1.txt

Here the -perm 644 will exactly match for files that have permission 644.

Code:
    $ find . -perm -600
    ./file1.txt
    ./file2.txt

Here the -perm -600 will find any find that have at least 600 as permission.

Code:
    $ find . -perm /700
    ./file2.txt
    ./subdir/file3.txt
    ./subdir/file4.txt

Here -perm /700 finds files that have any of 7,0,0 as their permission bit set.

Is my understanding correct and what are the potential use cases of these respective commands?
 
Technology news on Phys.org
  • #2
You could be looking for supposedly private files that are publicly readable or executable.

One use case might be others are doing maintenance on your machines and you want scripts that can check for vulnerabilities such as allowing some file to be executed or changed that shouldn't be.
 

What is the purpose of the "-perm" mode in the Find command?

The "-perm" mode in the Find command is used to specify the permissions of files or directories that you want to search for. This allows you to narrow down your search results and only find files or directories with specific permissions.

What is the difference between "-perm -mode" and "-perm /mode" in the Find command?

The "-perm -mode" option in the Find command will search for files or directories with exact permission matches, while the "-perm /mode" option will search for files or directories with at least the specified permissions. For example, "-perm -644" will only find files with permissions set to 644, while "-perm /644" will find files with permissions set to 644 or any higher permissions.

Can the "-perm" mode be used with other options in the Find command?

Yes, the "-perm" mode can be combined with other options in the Find command to further refine your search results. For example, you can use it with the "-user" option to find files with specific permissions and owned by a specific user.

What happens if I use multiple "-perm" modes in the Find command?

If you use multiple "-perm" modes in the Find command, the search will only return files or directories that match all of the specified modes. For example, using "-perm -644 -perm /755" will only find files with permissions set to 644 and 755.

Are there any other important considerations when using the "-perm" mode in the Find command?

Yes, it is important to note that the "-perm" mode only works with exact numerical permissions. This means that it will not work with symbolic permissions like "rwx" or "u+rw". Additionally, the "-perm" mode only searches for permissions of the user running the command, not the permissions of other users on the system.

Similar threads

Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
4K
  • Computing and Technology
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • Special and General Relativity
Replies
13
Views
2K
  • Special and General Relativity
Replies
1
Views
2K
Back
Top