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

  • Thread starter Thread starter shivajikobardan
  • Start date Start date
  • Tags Tags
    Linux
AI Thread Summary
The discussion focuses on the use of the `find` command in Unix-like systems to search for files based on their permission settings. The user explains three different scenarios using the `-perm` option with specific permission values. The command `find . -perm 644` accurately identifies files with exact permission 644, while `find . -perm -600` locates files with at least 600 permission, including those with higher permissions. The command `find . -perm /700` identifies files that have any of the permission bits set to 7, 0, or 0, thus finding files with permissions that may allow read, write, or execute access. The potential use cases for these commands include auditing file permissions to identify vulnerabilities, such as ensuring that sensitive files are not publicly accessible or executable, which is crucial for maintaining system security during maintenance or updates.
shivajikobardan
Messages
637
Reaction score
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
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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
What percentage of programmers have learned to touch type? Have you? Do you think it's important, not just for programming, but for more-than-casual computer users generally? ChatGPT didn't have much on it ("Research indicates that less than 20% of people can touch type fluently, with many relying on the hunt-and-peck method for typing ."). 'Hunt-and-peck method' made me smile. It added, "For programmers, touch typing is a valuable skill that can enhance speed, accuracy, and focus. While...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top