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

  • Thread starter Thread starter shivajikobardan
  • Start date Start date
  • Tags Tags
    Linux
Click For Summary
SUMMARY

The discussion clarifies the usage of the Linux find command with the -perm option, specifically focusing on three modes: "-perm mode", "-perm -mode", and "-perm /mode". The command "$ find . -perm 644" retrieves files with exact permission 644, while "$ find . -perm -600" identifies files with at least permission 600. Additionally, "$ find . -perm /700" locates files with any permission bits set to 7, 0, or 0. These commands are essential for identifying file permissions, particularly for security audits and vulnerability assessments.

PREREQUISITES
  • Understanding of Linux file permissions
  • Familiarity with the Linux command line interface
  • Basic knowledge of the find command syntax
  • Awareness of file security implications
NEXT STEPS
  • Research the find command's other options and flags
  • Learn about Linux file permission management
  • Explore security auditing tools for Linux environments
  • Study best practices for file permission settings in Linux
USEFUL FOR

System administrators, security professionals, and developers managing Linux environments who need to ensure proper file permissions and enhance system security.

shivajikobardan
Messages
637
Reaction score
54
TL;DR
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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 13 ·
Replies
13
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K