{"id":37488,"date":"2021-10-06T21:47:00","date_gmt":"2021-10-06T21:47:00","guid":{"rendered":"https:\/\/linuxiac.com\/?p=37488"},"modified":"2022-04-27T18:33:47","modified_gmt":"2022-04-27T18:33:47","slug":"find-files-in-linux","status":"publish","type":"post","link":"https:\/\/linuxiac.com\/find-files-in-linux\/","title":{"rendered":"Find Files and Directories in Linux Like a Pro"},"content":{"rendered":"\n<div class=\"wp-block-ultimate-post-table-of-content ultp-block-5cfd2d\"><div class=\"ultp-block-wrapper\"><div class=\"ultp-block-toc\"><div class=\"ultp-toc-header\"><div class=\"ultp-toc-heading\">Table of Contents<\/div><div class=\"ultp-collapsible-toggle  ultp-collapsible-right\"><a class=\"ultp-collapsible-text ultp-collapsible-open\" href=\"javascript:;\">[Open]<\/a><a class=\"ultp-collapsible-text ultp-collapsible-hide\" href=\"javascript:;\">[Close]<\/a><\/div><\/div><div class=\"ultp-block-toc-style1 ultp-block-toc-body\" style=\"display:block;\"><ul class=\"ultp-toc-lists\"><li><a href=\"#Find_Files_and_Directories_in_Linux_Using_find_Command\">Find Files and Directories in Linux Using find Command<\/a><ul class=\"ultp-toc-lists\"><li><a href=\"#Find_Files_by_Name\">Find Files by Name<\/a><\/li><li><a href=\"#Find_Files_by_Partial_Name\">Find Files by Partial Name<\/a><\/li><li><a href=\"#Find_Files_by_Size\">Find Files by Size<\/a><\/li><li><a href=\"#Find_Files_Using_Timestamps\">Find Files Using Timestamps<\/a><\/li><li><a href=\"#Find_Files_by_Owner\">Find Files by Owner<\/a><\/li><li><a href=\"#Find_Files_by_Permissions\">Find Files by Permissions<\/a><\/li><li><a href=\"#Find_Directories_by_Name\">Find Directories by Name<\/a><\/li><\/ul><\/li><li><a href=\"#Find_Files_and_Directories_in_Linux_Using_locate_Command\">Find Files and Directories in Linux Using locate Command<\/a><ul class=\"ultp-toc-lists\"><li><a href=\"#Find_Files_by_Name\">Find Files by Name<\/a><\/li><li><a href=\"#Find_Files_by_Partial_Name\">Find Files by Partial Name<\/a><\/li><li><a href=\"#Limit_Search_Results\">Limit Search Results<\/a><\/li><li><a href=\"#Display_the_Number_of_Matching_Entries\">Display the Number of Matching Entries<\/a><\/li><li><a href=\"#Get_Information_About_locate_Database\">Get Information About locate Database<\/a><\/li><\/ul><\/li><li><a href=\"#Conclusion\">Conclusion<\/a><\/li><\/ul><\/div><\/div><\/div><\/div>\n\n\n\n<p>You want to access a specific file but can&#8217;t find it on your Linux system. While there are many ways with which we can search and locate files and directories on Linux, the easiest and quickest is probably through the terminal.<\/p>\n\n\n\n<p><strong>Related: <a href=\"https:\/\/linuxiac.com\/basic-linux-commands\/\">20 Basic Linux Commands for Beginners Explained with Examples<\/a><\/strong><\/p>\n\n\n\n<p>The <code>find<\/code> command is one of the most important and frequently used command-line utilities in Linux.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Find_Files_and_Directories_in_Linux_Using_find_Command\">Find Files and Directories in Linux Using find Command<\/h2>\n\n\n\n<p>The Linux&nbsp;<code>find<\/code>&nbsp;command is a powerful tool that enables system administrators to locate and manage files and directories based on a search criteria. It supports searching by file, folder, name, creation date, modification date, owner, and permissions.<\/p>\n\n\n\n<p><strong>The&nbsp;<code>find<\/code>&nbsp;command is used to find files and directories and perform subsequent operations.<\/strong> It searches for files and directories in each path recursively.&nbsp;Thus, when the <code>find<\/code> command encounters a directory inside the given path, it looks for other files and directories inside it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"Find_Files_by_Name\">Find Files by Name<\/h3>\n\n\n\n<p>The general syntax of the <code>find<\/code> command is:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code lang=\"bash\" class=\"hljs language-css language-bash\"><span class=\"hljs-selector-tag\">find<\/span> <span class=\"hljs-selector-attr\">&#91;path]<\/span> <span class=\"hljs-selector-attr\">&#91;options]<\/span> <span class=\"hljs-selector-attr\">&#91;expression]<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Let\u2019s break down this syntax:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>path<\/code>:&nbsp;Defines the starting directory where find will search the files.<\/li>\n\n\n\n<li><code>options<\/code>:&nbsp;Controls the <code>find<\/code>&nbsp;process\u2019s behavior and optimization method.<\/li>\n\n\n\n<li><code>expression<\/code>:&nbsp;This attribute is made up of options, search patterns, and actions separated by operators.<\/li>\n<\/ul>\n\n\n\n<p>The most common use of the find command is searching for a file by its name. The&nbsp;<code>-type f<\/code>&nbsp;option tells the system that we&#8217;re looking for a&nbsp;File. To find a file using the filename, use the&nbsp;<code>-name<\/code>&nbsp;flag with the default command. <\/p>\n\n\n\n<p>For example, to search for a file named&nbsp;<code>report.pdf<\/code>&nbsp;in the&nbsp;<code>\/home<\/code>&nbsp;directory, you would use the following command:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">find \/home -type f -name report.pdf<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>As you know, Linux is case sensitive about file names, so if you\u2019re looking for a file named <code>Report.pdf<\/code>, the command shown above will return no results. So, you will need to use the <code>-iname<\/code> option instead of <code>-name<\/code>.<\/p>\n\n\n\n<p>The <code>-iname<\/code> option runs a <strong>case insensitive search<\/strong> so that we can do this:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">find \/home -type f -iname report.pdf<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>This command will locate a file with either of the following names: <code>report.pdf<\/code>, <code>Report.pdf<\/code>, <code>REPORT.pdf<\/code>, etc.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"Find_Files_by_Partial_Name\">Find Files by Partial Name<\/h3>\n\n\n\n<p>You can use filename meta-characters such as an asterisk (<code>*<\/code>), but you should either put an escape character (<code>\\<\/code>) in front of each or enclose them in quotes.<\/p>\n\n\n\n<p>For example, to find all files ending with a&nbsp;<code>.pdf<\/code>, you could run:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code lang=\"bash\" class=\"hljs language-javascript language-bash\">find \/home -type f -name <span class=\"hljs-string\">'*.pdf'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>which is the same as:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">find \/home -type f -name \\*.pdf<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Similarly, to find all the files on your Linux system whose names begin with <code>report<\/code>, you could run:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code lang=\"bash\" class=\"hljs language-javascript language-bash\">find \/home -type f -name <span class=\"hljs-string\">'report*'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id=\"Find_Files_by_Size\">Find Files by Size<\/h3>\n\n\n\n<p>Using the&nbsp;<code>find<\/code>&nbsp;command, we can quickly achieve something that might look complicated: <strong>find files bigger or smaller than a given size<\/strong>.<\/p>\n\n\n\n<p>The <code>-size<\/code> option on <code>find<\/code> allows us to search for files of a specific size. The <code>+<\/code> and <code>-<\/code> prefixes signify &#8220;greater than&#8221; and &#8220;less than.&#8221;<\/p>\n\n\n\n<p>The below example will search for all files greater than 1 Gigabyte. Note the use of the <code>+<\/code>&nbsp;sign:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">find \/home -type f -size +1G<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>In the example above, the suffix&nbsp;<code>G<\/code>&nbsp;denotes Gigabytes. The other popular available suffixes are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>c<\/code>: bytes.<\/li>\n\n\n\n<li><code>k<\/code>: Kilobytes.<\/li>\n\n\n\n<li><code>M<\/code>: Megabytes.<\/li>\n<\/ul>\n\n\n\n<p>The above&nbsp;<code>find<\/code>&nbsp;command was used to search for all files greater than the specified size. Next,&nbsp;<code>find<\/code>&nbsp;command example will search for all files with less than 200 Kilobytes in size. Note the use of the <code>-<\/code>&nbsp;sign:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">find \/home -type f -size -200k<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Now you probably wonder <strong>how to find files in Linux between a certain size<\/strong>. For example, you can find files&nbsp;between 100 Megabytes and 120 Megabytes&nbsp;in size using the following command:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">find \/home -type f -size +100M -size -120M<\/code><\/span><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id=\"Find_Files_Using_Timestamps\">Find Files Using Timestamps<\/h3>\n\n\n\n<p>Linux assigns specific timestamps to every file in the <a href=\"https:\/\/linuxiac.com\/linux-file-system-types-explained-which-one-should-you-use\/\">file system<\/a>. The <code>find<\/code> command can also <strong>search for files based on their last modification<\/strong>, access, or change time.<\/p>\n\n\n\n<p>The <code>-mtime<\/code> option is used to specify the number of days old that the file is. The expression can be used in two ways:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>-mtime +N<\/code>&nbsp;finds the files modified more than&nbsp;<code>N<\/code>&nbsp;days ago (for greater than).<\/li>\n\n\n\n<li><code>-mtime -N<\/code>&nbsp;finds the files modified less than&nbsp;<code>N<\/code>&nbsp;days ago (for less than).<\/li>\n<\/ul>\n\n\n\n<p>For example, entering <code>+3<\/code> will find all the files inside the <code>\/home<\/code> directory older than three days.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">find \/home -type f -mtime +3<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Similarly, if we want to find all the files that have changed in the last 24 hours:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">find \/home -type f -mtime -1<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>In the same way,&nbsp;you can use the&nbsp;<code>-mmin N<\/code>&nbsp;expression to rely on minutes instead of days.<\/p>\n\n\n\n<p>For example, this command finds all the files from the&nbsp;<code>\/home<\/code>&nbsp;directory modified at the last minute.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">find \/home -type f -mmin -1<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Furthermore, we can even compose expressions. Here&#8217;s how to find files in Linux that have been changed less than 60 minutes ago and more than 30 minutes ago:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">find \/home -type f -mmin -60 -mmin +30<\/code><\/span><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id=\"Find_Files_by_Owner\">Find Files by Owner<\/h3>\n\n\n\n<p>To find files&nbsp;owned&nbsp;by a particular <a href=\"https:\/\/linuxiac.com\/add-user-to-group-linux\/\">user or group<\/a>, use the&nbsp;<code>-user<\/code>&nbsp;and&nbsp;<code>-group<\/code>&nbsp;options.<\/p>\n\n\n\n<p>For example, to find files owned by the user <code>john<\/code> in the <code>\/home<\/code> folder of the server:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">find \/home -type f -user john<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Find all files belonging to a group called <code>www-data<\/code> in the <code>\/home<\/code> directory:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">find \/home -type f -group www-data<\/code><\/span><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id=\"Find_Files_by_Permissions\">Find Files by Permissions<\/h3>\n\n\n\n<p>The&nbsp;<code>-perm<\/code>&nbsp;option allows users to <strong>search for files with <strong>a particular permission set<\/strong><\/strong>.<\/p>\n\n\n\n<p>The below command will find the files with permission of&nbsp;exactly 644&nbsp;in the current directory.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">find \/home -type f -perm 644<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The use of the&nbsp;<code>-<\/code>&nbsp;option means &#8220;at least this permission level is set, and any higher permissions.&#8221;<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">find \/home -type f -perm -644<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>This example displays all resources in the <code>\/home<\/code> directory with at least&nbsp;<code>644<\/code>&nbsp;permissions. This means that files with the permissions such as <code>777<\/code>, <code>745<\/code>, <code>666<\/code>, <code>655<\/code>, <code>654<\/code>, etc., would match, while files with permissions <code>642<\/code>, <code>611<\/code>, <code>600<\/code>, <code>544<\/code>, etc., would not match.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"Find_Directories_by_Name\">Find Directories by Name<\/h3>\n\n\n\n<p>All the examples we\u2019ve seen so far return files. However, you can use the <code>-type d<\/code> switch if you need to search for directories only.<\/p>\n\n\n\n<p>In other words, you can prevent the <code>find<\/code> command in Linux from searching for other file types except for directories by using the <code>-type d<\/code> flag (<code>d<\/code> means directory).<\/p>\n\n\n\n<p>To find a folder named <code>scripts<\/code> in the <code>\/home<\/code> directory, run:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">find \/home -type d -name scripts<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Similarly, all other options shown so far are also applicable when searching for directories.<\/p>\n\n\n\n<p>For more about the&nbsp;<code>find<\/code>&nbsp;command in Linux, consult its&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man1\/find.1.html\" target=\"_blank\" rel=\"noreferrer noopener\">manual page<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Find_Files_and_Directories_in_Linux_Using_locate_Command\">Find Files and Directories in Linux Using locate Command<\/h2>\n\n\n\n<p>While <code>find<\/code> is undoubtedly one of the most popular and powerful command-line\u00a0utilities\u00a0for file searching in Linux, it is not fast enough for situations where you need instantaneous results.<\/p>\n\n\n\n<p>The <code>locate<\/code> command is faster than the <code>find<\/code> command because it uses a previously built database, whereas the <code>find<\/code> command searches in real-time through all the actual directories and files.<\/p>\n\n\n\n<p><strong>Related: <a href=\"https:\/\/linuxiac.com\/plocate-command\/\">The plocate Command as a Faster Alternative to locate in Linux<\/a><\/strong><\/p>\n\n\n\n<p>If&nbsp;<code>locate<\/code>&nbsp;is not installed, you can easily install it using the package manager of your Linux distro.<\/p>\n\n\n\n<p>On&nbsp;<a href=\"https:\/\/linuxiac.com\/ubuntu\/\">Ubuntu<\/a>&nbsp;or any other&nbsp;<a href=\"https:\/\/linuxiac.com\/debian\/\">Debian<\/a>-based system, type the following command:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">sudo apt install mlocate<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>If you are using&nbsp;<a href=\"https:\/\/linuxiac.com\/fedora\/\">Fedora<\/a>&nbsp;or&nbsp;<a href=\"https:\/\/linuxiac.com\/centos-stream\/\">CentOS<\/a>, use this command instead:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">sudo dnf install mlocate<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><a href=\"https:\/\/linuxiac.com\/archlinux\/\">Arch Linux<\/a>&nbsp;users need to execute:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">sudo pacman -S mlocate<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>But before the&nbsp;<code>locate<\/code>&nbsp;command can be used, the database will need to be created. This is done with the&nbsp;<code>updatedb<\/code>&nbsp;command, which (as the name suggests) updates the database.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">sudo updatedb<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The database will be <a href=\"https:\/\/linuxiac.com\/how-to-use-cron-and-crontab-on-linux\/\">updated automatically<\/a> daily, but you can also update it yourself at any time to obtain up-to-the-minute results.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"Find_Files_by_Name\">Find Files by Name<\/h3>\n\n\n\n<p>The <code>locate<\/code> command is straightforward to use. All you have to do is pass it the filename you want to search.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code lang=\"bash\" class=\"hljs language-css language-bash\"><span class=\"hljs-selector-tag\">locate<\/span> <span class=\"hljs-selector-tag\">report<\/span><span class=\"hljs-selector-class\">.pdf<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Like the <code>find<\/code> command, <code>locate<\/code> is configured to process queries in a case-sensitive manner. To have the <code>locate<\/code> command <strong>ignore case sensitivity<\/strong> and show results for both uppercase and lowercase queries, you need to use the <code>-i<\/code> option.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code lang=\"bash\" class=\"hljs language-css language-bash\"><span class=\"hljs-selector-tag\">locate<\/span> <span class=\"hljs-selector-tag\">-i<\/span> <span class=\"hljs-selector-tag\">rEpoRT<\/span><span class=\"hljs-selector-class\">.pdf<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id=\"Find_Files_by_Partial_Name\">Find Files by Partial Name<\/h3>\n\n\n\n<p>If you want to search for all filenames that have the string <code>.pdf<\/code> in them, then you can do that using <code>locate<\/code> in the following way:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code lang=\"bash\" class=\"hljs language-javascript language-bash\">locate <span class=\"hljs-string\">'*.pdf'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id=\"Limit_Search_Results\">Limit Search Results<\/h3>\n\n\n\n<p>You can <strong>limit your search returns<\/strong> to a required number to avoid redundancy with your search results using the&nbsp;<code>-n<\/code>&nbsp;option.<\/p>\n\n\n\n<p>For example, if you want just&nbsp;ten&nbsp;results from your queries, you can type the following command:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code lang=\"bash\" class=\"hljs language-javascript language-bash\">locate -n <span class=\"hljs-number\">10<\/span> <span class=\"hljs-string\">'*.pdf'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id=\"Display_the_Number_of_Matching_Entries\">Display the Number of Matching Entries<\/h3>\n\n\n\n<p>To count the number of occurrences of a file name or search pattern using the locate command, invoke the&nbsp;<code>-c<\/code>&nbsp;option as shown.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code lang=\"bash\" class=\"hljs language-javascript language-bash\">locate -c <span class=\"hljs-string\">'*.pdf'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id=\"Get_Information_About_locate_Database\">Get Information About locate Database<\/h3>\n\n\n\n<p>To gather more insights on the locate database <code>mlocate.db<\/code> that <code>locate<\/code> has cataloged, use the&nbsp;<code>-S<\/code>&nbsp;option:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">locate -S<\/code><\/span><\/pre>\n\n<pre title=\"Output\" class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code lang=\"xml\" class=\"hljs language-javascript language-xml\">Database \/<span class=\"hljs-keyword\">var<\/span>\/lib\/mlocate\/mlocate.db:\n\t<span class=\"hljs-number\">72376<\/span> directories\n\t<span class=\"hljs-number\">1142596<\/span> files\n\t<span class=\"hljs-number\">98622214<\/span> bytes <span class=\"hljs-keyword\">in<\/span> file names\n\t<span class=\"hljs-number\">33950606<\/span> bytes used to store database<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>If you need it,&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man1\/locate.1.html\" target=\"_blank\" rel=\"noreferrer noopener\">here\u2019s the man page<\/a>&nbsp;for the&nbsp;<code>locate<\/code>&nbsp;command.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Conclusion\">Conclusion<\/h2>\n\n\n\n<p>The two most widely used file searching utilities accessible to Linux users are called <code>find<\/code> and&nbsp;<code>locate<\/code>. Both are good ways to find files on your system. It is up to you to decide which of these tools is appropriate in each situation.<\/p>\n\n\n\n<p>This article should give you a fundamental understanding of finding files on your Linux systems.<\/p>\n\n\n\n<p>However, even if the option were presented individually, you should remember that they can be combined in order to be able to specify even more the files you are looking for.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide will show you how to use \u201cfind\u201d and \u201clocate\u201d commands to find files and directories on your Linux file systems.<\/p>\n","protected":false},"author":10,"featured_media":37491,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,4417],"tags":[1484,4371,4374],"class_list":["post-37488","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tips","category-linux-knowledge","tag-commands","tag-find","tag-locate"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6},"post_title_panel":"","has_hero_section":"default","e64e38761940bf4b5699c63a1eb2ecea":"","hero_section":"type-2","hero_elements":[{"id":"custom_title","enabled":true,"heading_tag":"h1","title":"Home","__id":"yGTOECy3-pMJtn9RTBnKo"},{"id":"custom_description","enabled":false,"description_visibility":{"desktop":true,"tablet":true,"mobile":false},"__id":"nWZ1ne46npSHKE_kFRDrA"},{"id":"custom_meta","enabled":true,"meta_elements":[{"id":"author","enabled":true,"label":"By","has_author_avatar":"yes","avatar_size":50,"__id":"DIGeI7-mDRw_IQM63ShdS"},{"id":"post_date","enabled":false,"label":"On","date_format_source":"default","date_format":"M j, Y","__id":"5aJxvgXJ4-JWjr41gRf0f"},{"id":"updated_date","enabled":true,"label":"Updated","date_format_source":"default","date_format":"M j, Y","__id":"mBFyBEXvopffEPE2X3lsW"},{"id":"categories","enabled":false,"label":"In","style":"simple","__id":"29VGapxBQIFaBz6bCtcpw"},{"id":"comments","enabled":true,"__id":"tU-0hNAXKdSwldogW2TPc"}],"page_meta_elements":{"joined":true,"articles_count":true,"comments":true},"__id":"rjh7XF7JWUCYGZyL88qNM","meta_type":"label","meta_divider":"circle"},{"id":"breadcrumbs","enabled":false,"__id":"nrpJuS6r92uDsEHamCJMb"}],"9df97e6e0f63c07e366aee25d0339d90":"","hero_alignment1":"CT_CSS_SKIP_RULE","hero_margin":40,"hero_alignment2":"center","hero_vertical_alignment":"center","2e21b6657c84f24d0c97d6766b0b2c5e":"","hero_structure":"normal","49d7b9db071b7bb51922398172914100":"","page_title_bg_type":"custom_image","custom_hero_background":{"attachment_id":45408,"url":"https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/10\/find-files-header-1024x237.jpg"},"page_title_image_size":"full","parallax":{"desktop":false,"tablet":false,"mobile":false},"026ff3d3c7b43add7132d5ea33f8d7c5":"","hero_height":"250px","pageTitleFont":{"family":"Default","variation":"Default","size":{"desktop":"2.8em","tablet":"2.8em","mobile":"2.8em","__changed":[]},"line-height":"CT_CSS_SKIP_RULE","letter-spacing":"CT_CSS_SKIP_RULE","text-transform":"CT_CSS_SKIP_RULE","text-decoration":"CT_CSS_SKIP_RULE"},"pageTitleFontColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"pageMetaFont":{"family":"Default","variation":"n6","size":"12px","line-height":"1.3","letter-spacing":"CT_CSS_SKIP_RULE","text-transform":"uppercase","text-decoration":"CT_CSS_SKIP_RULE"},"pageMetaFontColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"page_meta_button_type_font_colors":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"page_meta_button_type_background_colors":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"pageExcerptFont":{"family":"Default","variation":"Default","size":"CT_CSS_SKIP_RULE","line-height":"CT_CSS_SKIP_RULE","letter-spacing":"CT_CSS_SKIP_RULE","text-transform":"CT_CSS_SKIP_RULE","text-decoration":"CT_CSS_SKIP_RULE"},"pageExcerptColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"breadcrumbsFont":{"family":"Default","variation":"Default","size":"CT_CSS_SKIP_RULE","line-height":"CT_CSS_SKIP_RULE","letter-spacing":"CT_CSS_SKIP_RULE","text-transform":"CT_CSS_SKIP_RULE","text-decoration":"CT_CSS_SKIP_RULE"},"breadcrumbsFontColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"initial":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"pageTitleOverlay":{"background_type":"color","background_pattern":"type-1","background_image":{"attachment_id":null,"x":0,"y":0},"gradient":"linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)","background_repeat":"repeat","background_size":"auto","background_attachment":"scroll","patternColor":{"default":{"color":"#e5e7ea"}},"overlayColor":{"default":{"color":"CT_CSS_SKIP_RULE"}},"backgroundColor":{"default":{"color":"CT_CSS_SKIP_RULE"}}},"pageTitleBackground":{"background_type":"color","background_pattern":"type-1","background_image":{"attachment_id":null,"x":0,"y":0},"gradient":"linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)","background_repeat":"repeat","background_size":"auto","background_attachment":"scroll","patternColor":{"default":{"color":"#e5e7ea"}},"overlayColor":{"default":{"color":"CT_CSS_SKIP_RULE"}},"backgroundColor":{"default":{"color":"var(--theme-palette-color-6)"}}},"pageTitlePadding":{"top":"50px","bottom":"50px","left":"auto","right":"auto","linked":true},"8649a5719d319714927abd6482d9d830":"","page_structure_type":"default","3b351c6b61ccfff1c1b134ddc2a442f2":"","content_style_source":"inherit","content_style":"wide","9a4fcd834e23a30532d962e249fa4514":"","vertical_spacing_source":"inherit","content_area_spacing":"both","background":{"background_type":"color","background_pattern":"type-1","background_image":{"attachment_id":null,"x":0,"y":0},"gradient":"linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)","background_repeat":"repeat","background_size":"auto","background_attachment":"scroll","patternColor":{"default":{"color":"#e5e7ea"}},"overlayColor":{"default":{"color":"CT_CSS_SKIP_RULE"}},"backgroundColor":{"default":{"color":"CT_CSS_SKIP_RULE"}}},"content_background":{"background_type":"color","background_pattern":"type-1","background_image":{"attachment_id":null,"x":0,"y":0},"gradient":"linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)","background_repeat":"repeat","background_size":"auto","background_attachment":"scroll","patternColor":{"default":{"color":"#e5e7ea"}},"overlayColor":{"default":{"color":"CT_CSS_SKIP_RULE"}},"backgroundColor":{"default":{"color":"var(--theme-palette-color-8)"}}},"content_boxed_shadow":{"inherit":false,"blur":18,"spread":-6,"v_offset":12,"h_offset":0,"inset":false,"enable":true,"color":{"color":"rgba(34, 56, 101, 0.04)"}},"boxed_content_spacing":{"desktop":{"top":"40px","bottom":"40px","left":"40px","right":"40px","linked":true},"tablet":{"top":"35px","bottom":"35px","left":"35px","right":"35px","linked":true},"mobile":{"top":"20px","bottom":"20px","left":"20px","right":"20px","linked":true}},"content_boxed_radius":{"top":"3px","bottom":"3px","left":"3px","right":"3px","linked":true},"ea4957e7615ff3391fb2736c8c2af827":"","disable_featured_image":"no","disable_post_tags":"no","disable_share_box":"no","disable_author_box":"no","disable_posts_navigation":"no","disable_subscribe_form":"no","0f494c060bd831e823ad728ce3b3779e":"","disable_related_posts":"no","disable_header":"no","disable_footer":"no","18009369cb39d5d49ab18cb5a9e9ae97":"","header_footer_scripts_panel":"","header_scripts":"","b3f5f2569fcc68cfc89b506a7011be4d":"","header_after_body_scripts":"","33f18bf5de8f0c08ffde8213db6938b6":"","footer_scripts":""},"_links":{"self":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/posts\/37488","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/comments?post=37488"}],"version-history":[{"count":0,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/posts\/37488\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/media\/37491"}],"wp:attachment":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/media?parent=37488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/categories?post=37488"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/tags?post=37488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}