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.
 

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

What is the difference between "-perm mode", "-perm -mode", and "-perm /mode" in the find command in Linux?

The "-perm mode" option in the find command is used to search for files with exact permissions specified by mode. The "-perm -mode" option is used to search for files with at least the permissions specified by mode. The "-perm /mode" option is used to search for files with any of the permissions specified by mode.

How do I use the "-perm mode" option in the find command?

To use the "-perm mode" option in the find command, you need to specify the exact permissions you are looking for. For example, to find files with read, write, and execute permissions for the owner, you would use the command "find . -perm 700".

Can I combine the "-perm" option with other options in the find command?

Yes, you can combine the "-perm" option with other options in the find command to narrow down your search results. For example, you can combine it with the "-type f" option to only search for files with the specified permissions.

What do the numbers in the "-perm" option represent?

The numbers in the "-perm" option represent the file permissions in octal form. Each digit represents the permissions for the owner, group, and others, respectively. The numbers are calculated by adding the values for read, write, and execute permissions (4, 2, and 1) for each group.

Are there any shortcuts for common permission settings in the "-perm" option?

Yes, there are shortcuts for common permission settings in the "-perm" option. For example, you can use "u+x" to search for files with execute permission for the owner, "g=r" to search for files with read permission for the group, and "o=w" to search for files with write permission for others.

Similar threads

Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
5K
  • 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