{"id":16943,"date":"2023-11-01T10:14:56","date_gmt":"2023-11-01T10:14:56","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=16943"},"modified":"2023-11-01T10:18:16","modified_gmt":"2023-11-01T10:18:16","slug":"how-to-find-files-based-on-permissions-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2023\/11\/01\/how-to-find-files-based-on-permissions-in-linux\/","title":{"rendered":"How to Find Files Based on Permissions in Linux."},"content":{"rendered":"\n<p><strong>Are you trying to locate files with specific file permissions for different purposes, such as security auditing?<\/strong> Fortunately, the&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.ubuntumint.com\/find-recently-modified-files\/\" target=\"_blank\">find command<\/a>&nbsp;provides a handy&nbsp;<code>\u201c-perm\u201d<\/code>&nbsp;flag which enables users to list all the files that match the provided file permissions.<\/p>\n\n\n\n<p>However, this blog post assumes you are already familiar with file permissions and how to check or grant them. If that\u2019s not the case, refer to our beginner\u2019s guide on&nbsp;<a href=\"https:\/\/www.ubuntumint.com\/linux-file-permissions\/\" target=\"_blank\" rel=\"noreferrer noopener\">changing file permissions<\/a>.<\/p>\n\n\n\n<p>Now that you\u2019re prepared and have an understanding of file permissions, this guide will help you search for your desired files based on their permissions, using the well-known \u201c<strong>find<\/strong>\u201d and \u201c<strong>ls<\/strong>\u201d commands.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Find Files Based on Permissions in Linux<\/strong><\/h2>\n\n\n\n<p>The syntax of the&nbsp;<strong>find command<\/strong>&nbsp;for locating files based on their permission is stated below:$ find [path] -type f -perm [permissions]<\/p>\n\n\n\n<p>Here\u2019s what each part of the syntax means:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>[path]<\/code>&nbsp;\u2013 It states the directory or path from where you want to begin your search. For instance, to look for the file in the root directory use&nbsp;<code>\u201c\/\u201d<\/code>.<\/li>\n\n\n\n<li><code>-type f<\/code>&nbsp;\u2013 This option filters the search results to only include regular files, excluding other types of files.<\/li>\n\n\n\n<li><code>-perm [permissions]<\/code>&nbsp;\u2013 This option specifies the permission mode you intend to find. You can add Minus&nbsp;<code>(-)<\/code>&nbsp;or Slash&nbsp;<code>(\/)<\/code>&nbsp;prefixes before the permission mode, or no prefix at all.<\/li>\n<\/ul>\n\n\n\n<p>Let\u2019s quickly review permission prefixes before delving into examples for further clarity.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>No prefix \u2013 exact permissions.<\/li>\n\n\n\n<li>Minus&nbsp;<code>(-)<\/code>&nbsp;prefix \u2013 At least specified permissions, with extras allowed.<\/li>\n\n\n\n<li>Slash&nbsp;<code>(\/)<\/code>&nbsp;prefix \u2013 At least any category (owner\/group\/others) must have specified permission bit(s).<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Find Files That Have Specific Permissions<\/strong><\/h3>\n\n\n\n<p>In this example, we will look for files in the \u201c<strong>UbuntuMint<\/strong>\u201d directory that have exactly&nbsp;<strong>read<\/strong>&nbsp;and&nbsp;<strong>write<\/strong>&nbsp;permissions for the owner only \u201c<strong>600<\/strong>\u201d by executing the command stated below.<\/p>\n\n\n\n<p>Before executing the following command, you can run \u201c<strong>ls -l ~\/UbuntuMint<\/strong>\u201d to review the permissions of files within this directory:<\/p>\n\n\n\n<p>$ ls -l ~\/UbuntuMint $ find ~\/UbuntuMint -type f -perm 600<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9126\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Find-Files-by-Specific-Permissions.png\" alt=\"Find Files by Specific Permissions\" class=\"wp-image-9126\"\/><figcaption class=\"wp-element-caption\">Find Files by Specific Permissions<\/figcaption><\/figure>\n\n\n\n<p>You can notice that the above command has returned the \u201c<strong>file4.txt<\/strong>\u201d which exactly meets the specified criteria.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Find Files That Have Executable Permissions<\/strong><\/h3>\n\n\n\n<p>If you want to search files with executable permissions for their&nbsp;<strong>owner<\/strong>,&nbsp;<strong>group<\/strong>, and&nbsp;<strong>other<\/strong>&nbsp;users, simply execute.$ find ~\/UbuntuMint -type f -perm 111<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9127\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Find-Files-by-Execute-Permissions.png\" alt=\"Find Files with Execute Permissions\" class=\"wp-image-9127\"\/><figcaption class=\"wp-element-caption\">Find Files with Execute Permissions<\/figcaption><\/figure>\n\n\n\n<p>Upon executing this command, you\u2019ll notice files that precisely match the specified executable permissions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Find Files That Have Read\/Write Permissions<\/strong><\/h3>\n\n\n\n<p>Before delving into this example, let\u2019s use the \u201c<strong>ls<\/strong>\u201d command within the directory to inspect current file permissions. Here, you\u2019ll observe two files with&nbsp;<strong>read<\/strong>&nbsp;and&nbsp;<strong>write<\/strong>&nbsp;(6) permissions for the file owner, and read permissions (4) for the group and other users.<\/p>\n\n\n\n<p>In this scenario, the&nbsp;<strong>find<\/strong>&nbsp;command will enumerate multiple files with \u201c<strong>644<\/strong>\u201d permission:<\/p>\n\n\n\n<p>$ ls -l ~\/UbuntuMint <\/p>\n\n\n\n<p>$ find ~\/UbuntuMint -type f -perm 644<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9128\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Find-Files-with-Read-Write-Permissions.png\" alt=\"Find Files with Read Write Permissions\" class=\"wp-image-9128\"\/><figcaption class=\"wp-element-caption\">Find Files with Read Write Permissions<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Find Files That Have Owner\u2019s Read\/Write Permissions<\/strong><\/h3>\n\n\n\n<p>Let\u2019s use the&nbsp;<code>\u201c-\u201d<\/code>&nbsp;minus prefix before the file permissions to list all the files that possess at least&nbsp;<strong>read<\/strong>&nbsp;and&nbsp;<strong>write<\/strong>&nbsp;permissions for the file owner.<\/p>\n\n\n\n<p>So basically the command mentioned below will return files with permissions like \u201c<strong>600<\/strong>\u201d,&nbsp;<strong>601<\/strong>,&nbsp;<strong>602<\/strong>,&nbsp;<strong>610<\/strong>,&nbsp;<strong>620<\/strong>,&nbsp;<strong>630<\/strong>, and so on:<\/p>\n\n\n\n<p>$ find ~\/UbuntuMint -type f -perm -600<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9129\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Find-Files-with-Owner-Read-Write-Permissions.png\" alt=\"Find Files with Owner's Read and Write Permissions\" class=\"wp-image-9129\"\/><figcaption class=\"wp-element-caption\">Find Files with Owner\u2019s Read and Write Permissions<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Find Files with Any Category Meeting Specified Permissions<\/strong><\/h3>\n\n\n\n<p>Next, let\u2019s explore the working of the slash&nbsp;<code>(\/)<\/code>&nbsp;prefix before file permissions by executing the provided command. This will retrieve files within the \u201c<strong>UbuntuMint<\/strong>\u201d directory where at least one of the categories (<strong>owner<\/strong>,&nbsp;<strong>group<\/strong>, or&nbsp;<strong>others<\/strong>) meets the specified permission bits.<\/p>\n\n\n\n<p>$ find ~\/UbuntuMint -type f -perm \/600<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9131\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Find-Files-with-Exact-Permissions.png\" alt=\"Find Files with Exact Permissions\" class=\"wp-image-9131\"\/><figcaption class=\"wp-element-caption\">Find Files with Exact Permissions<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. Find Files That Have Symbolic Permissions<\/strong><\/h3>\n\n\n\n<p>Users can opt for symbolic permissions instead of the numerical mode to specify file permissions. Execute the command below to find files with read and write permissions for the owner and read permissions for the group and others within the \u201c<strong>UbuntuMint<\/strong>\u201d directory:<\/p>\n\n\n\n<p>$ find ~\/UbuntuMint -type f -perm u=rw,g=r,o=r<\/p>\n\n\n\n<p>This command is equivalent to the above command:<\/p>\n\n\n\n<p>$ find ~\/UbuntuMint -type f -perm u+rw,g+r,o+r<\/p>\n\n\n\n<p><strong>Note<\/strong>: Prefixes can be utilized with symbolic permissions as well.<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9132\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Find-Files-with-Symbolic-Permissions.png\" alt=\"Find Files with Symbolic Permissions\" class=\"wp-image-9132\"\/><figcaption class=\"wp-element-caption\">Find Files with Symbolic Permissions<\/figcaption><\/figure>\n\n\n\n<p>Now that you have learned the usage of the find command with the&nbsp;<code>\u201c-perm\u201d<\/code>&nbsp;flag, let\u2019s explore another command that combines both the&nbsp;<strong>\u201cls\u201d<\/strong>&nbsp;and&nbsp;<strong>\u201cgrep\u201d<\/strong>&nbsp;commands.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Find Files Based on Permissions Using the \u2018ls\u2019 and \u2018grep\u2019 Commands<\/strong><\/h2>\n\n\n\n<p>You can even utilize the powerful combination of the&nbsp;<a href=\"https:\/\/www.ubuntumint.com\/sort-files-by-size-in-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\">ls command<\/a>&nbsp;piped with the&nbsp;<strong>grep command<\/strong>&nbsp;to display all files in the current directory and subsequently filter out files that match the specified permission.<\/p>\n\n\n\n<p><strong>Note<\/strong>: The&nbsp;<code>\u201c-l\u201d<\/code>&nbsp;flag in the \u201c<strong>ls<\/strong>\u201d command helps in displaying detailed information about files including file permissions, ownership, size, modification time, and more.<\/p>\n\n\n\n<p>Let\u2019s run the command mentioned below to look for files that have&nbsp;<strong>read<\/strong>&nbsp;and&nbsp;<strong>write<\/strong>&nbsp;permissions for the file owner. Here in this command, the&nbsp;<code>\u201c^\u201d<\/code>&nbsp;symbol specifies that the&nbsp;<strong>grep<\/strong>&nbsp;command will only filter files not directories:<\/p>\n\n\n\n<p>$ ls -l | grep &#8220;^-rw&#8212;&#8212;-&#8220;<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9134\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Find-Files-Based-on-Permissions.png\" alt=\"Find Files Based on Permissions\" class=\"wp-image-9134\"\/><figcaption class=\"wp-element-caption\">Find Files Based on Permissions<\/figcaption><\/figure>\n\n\n\n<p>However, if you want to focus on only permissions for a specific user like file owner and don\u2019t care about permission of other user classes, you can define the permissions for that particular user bits and employ a wildcard character for the rest, as shown below:<\/p>\n\n\n\n<p>$ ls -l ~\/UbuntuMint\/ | grep &#8220;^-rw-*&#8221;<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9135\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Find-Files-by-Specifying-Particular-User-Bits.png\" alt=\"Find Files by Specifying Particular User Bits\" class=\"wp-image-9135\"\/><figcaption class=\"wp-element-caption\">Find Files by Specifying Particular User Bits<\/figcaption><\/figure>\n\n\n\n<p>This command effectively identifies all files within the \u201c<strong>~\/UbuntuMint\/\u201d<\/strong>&nbsp;directory that possess&nbsp;<strong>read<\/strong>&nbsp;and&nbsp;<strong>write<\/strong>&nbsp;permissions for the file owner.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Conclusion<\/h5>\n\n\n\n<p>If you\u2019re seeking to identify files within a directory based on specific file permissions for security audits or other purposes, this guide is your essential resource. It offered two distinct commands, accompanied by numerous examples, to assist you in pinpointing files according to their permissions.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.ubuntumint.com\/find-files-specific-permissions-linux\/\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Are you trying to locate files with specific file permissions for different purposes, such as security auditing? Fortunately, the&nbsp;find command&nbsp;provides a handy&nbsp;\u201c-perm\u201d&nbsp;flag which enables users to list all the files that match the provided file permissions. However, this blog post assumes you are already familiar with file permissions and how to check or grant them. &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2023\/11\/01\/how-to-find-files-based-on-permissions-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Find Files Based on Permissions in Linux.&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-16943","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/16943","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=16943"}],"version-history":[{"count":2,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/16943\/revisions"}],"predecessor-version":[{"id":16945,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/16943\/revisions\/16945"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=16943"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=16943"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=16943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}