{"id":18476,"date":"2020-06-25T06:43:01","date_gmt":"2020-06-25T13:43:01","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=18476"},"modified":"2023-12-01T03:26:59","modified_gmt":"2023-12-01T11:26:59","slug":"linux-find-command","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/linux-find-command\/","title":{"rendered":"Linux find Command: A Guide"},"content":{"rendered":"\n<p>When you\u2019re starting to use the Linux command line, you\u2019ll encounter the question: How do I find files using Linux? It\u2019s not as if there is a search bar you can use in your command line to find a file on your operating system. That\u2019s where the Linux find command comes in handy.<br><\/p>\n\n\n\n<p>In this article, we\u2019re going to discuss how to find files in Linux using the find command. We will walk through a couple of examples of the find command in action to help you search for files based on different attributes. Let\u2019s get started.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Linux find Command Syntax<\/h2>\n\n\n\n<p>Here is the syntax for the find command in Linux:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>find [options] [file path] [expressions]<\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The options attribute controls what type of files you will search for and the debugging options you specify.<\/li>\n\n\n\n<li>file path is the directory at which your search for files will begin.<\/li>\n\n\n\n<li>expressions refer to all the options and search patterns that will be used to find a file or set of files.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How to Find Files by Name<\/h2>\n\n\n\n<p>Perhaps the most popular usage of the find command is to find a file by name. This allows you to search through a folder for a file based on its filename.<br><\/p>\n\n\n\n<p>You can use the -name option with the find command to search for a file, followed by the name of the file for which you are searching.<br><\/p>\n\n\n\n<p>Suppose we want to search for a file called find_tutorial.pdf in the directory \/home\/careerkarma\/tutorials. We could do so using this command:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>find \/home\/careerkarma\/tutorials -name find_tutorial.pdf<\/pre><\/div>\n\n\n\n<p>Let\u2019s break down this command:<br><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\/home\/careerkarma\/tutorials is the name of the folder in which we are searching for our files (the file path).<\/li>\n\n\n\n<li>-name find_tutorial.pdf specifies the name of the file for which we want to search (the expression).<\/li>\n<\/ul>\n\n\n\n<p>The find command is not case sensitive. As a result, the above command would return any file which has the name \u201cfind_tutorial.pdf\u201d, even if the matching filename contained capital letters.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Find Files by Extension<\/h2>\n\n\n\n<p>You can also search for files based on their extensions. To do so, you can use the same syntax you would use for finding a file by name.&nbsp;<br><\/p>\n\n\n\n<p>Suppose we want to find all files in the \/var\/log folder that ended in \u201c.log\u201d. We could do so using the following command:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>find \/var\/log -name '*.log'<\/pre><\/div>\n\n\n\n<p>The  \u201c*.log\u201d name tells the command line to search for any file whose name ends in .log; <code>*<\/code> is known as the wildcard character which can be used as a substitution for any text.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Find Files by Modified Date<\/h2>\n\n\n\n<p>When you\u2019re searching for a file, you may want to refine your search to only files that were modified between a specific date.<br><\/p>\n\n\n\n<p>Suppose you modified a file in \/etc\/nginx last week but you\u2019re not sure which one. You could find which file you modified using this command:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>find \/etc\/nginx -name * -mtime 7<\/pre><\/div>\n\n\n\n<p>This command uses <code>*<\/code> to denote any file name, and the <code>-mtime<\/code> flag to instruct find to only return files that have been modified in the past seven days.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Find and Delete Files<\/h2>\n\n\n\n<p>You may want to delete the files returned by a find search. You can do so using the -delete option at the end of your command.<br><\/p>\n\n\n\n<p>Before you use the find command to delete files, you should ensure the files returned by the find command are the ones you want to delete. It\u2019s best to run the find command without the -delete option first, so you can see what files will be deleted.<br><\/p>\n\n\n\n<p>Remember, there is no trash can on the Linux command line; when a file is gone, it\u2019s gone.<br><\/p>\n\n\n\n<p>Suppose we want to delete all \u201c.log\u201d files in the folder \/home\/careerkarma\/logs. We could do so using this command:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>find \/home\/careerkarma\/logs -name \"*.log\" -delete<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Find Files by Different Types<\/h2>\n\n\n\n<p>So far, we\u2019ve used the find command to search for any file or directory that matches a certain criteria on your file system. But what if you only want to search for files, folders or symbolic links?<br><\/p>\n\n\n\n<p>The <code>-type<\/code> option allows you to specify the file type for which you want to search. The most common values used with this option are:<br><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>f: Search for files<\/li>\n\n\n\n<li>d: Search for folder<\/li>\n\n\n\n<li>l: Search for symbolic link<\/li>\n<\/ul>\n\n\n\n<p>Suppose you want to find a list of all folders in the \/home\/careerkarma folder. You could accomplish this task using the following command:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>find \/home\/careerkarma -type d<\/pre><\/div>\n\n\n\n<p>In this command, the <code>-type d<\/code> flag tells the find command to only search for folders.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The Linux find command gives you a number of options to find files and directories on your system. While the command may be less intuitive than a search bar, it gives you a lot of control over file types for your search.<br><\/p>\n\n\n\n<p>Interested in learning more about the find command? Type <code>man find<\/code> into your terminal to read more about the options offered by this command from the Linux manual.<\/p>\n","protected":false},"excerpt":{"rendered":"When you\u2019re starting to use the Linux command line, you\u2019ll encounter the question: How do I find files using Linux? It\u2019s not as if there is a search bar you can use in your command line to find a file on your operating system. That\u2019s where the Linux find command comes in handy. In this&hellip;","protected":false},"author":240,"featured_media":18477,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[18070],"tags":[],"class_list":{"0":"post-18476","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-software-engineering-skills"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Software Engineering","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":"","is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Linux find Command: A Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"The find command allows you to find files and folders that meet a set of criteria on Linux. On Career Karma, learn how to use the find command.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/linux-find-command\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linux find Command: A Guide\" \/>\n<meta property=\"og:description\" content=\"The find command allows you to find files and folders that meet a set of criteria on Linux. On Career Karma, learn how to use the find command.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/linux-find-command\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-25T13:43:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:26:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/goran-ivos-idmvPhF8t4E-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"766\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/linux-find-command\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/linux-find-command\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Linux find Command: A Guide\",\"datePublished\":\"2020-06-25T13:43:01+00:00\",\"dateModified\":\"2023-12-01T11:26:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/linux-find-command\/\"},\"wordCount\":822,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/linux-find-command\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/goran-ivos-idmvPhF8t4E-unsplash.jpg\",\"articleSection\":[\"Software Engineering\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/linux-find-command\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/linux-find-command\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/linux-find-command\/\",\"name\":\"Linux find Command: A Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/linux-find-command\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/linux-find-command\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/goran-ivos-idmvPhF8t4E-unsplash.jpg\",\"datePublished\":\"2020-06-25T13:43:01+00:00\",\"dateModified\":\"2023-12-01T11:26:59+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"The find command allows you to find files and folders that meet a set of criteria on Linux. On Career Karma, learn how to use the find command.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/linux-find-command\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/linux-find-command\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/linux-find-command\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/goran-ivos-idmvPhF8t4E-unsplash.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/goran-ivos-idmvPhF8t4E-unsplash.jpg\",\"width\":1020,\"height\":766},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/linux-find-command\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Software Engineering\",\"item\":\"https:\/\/careerkarma.com\/blog\/software-engineering-skills\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Linux find Command: A Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Linux find Command: A Guide | Career Karma","description":"The find command allows you to find files and folders that meet a set of criteria on Linux. On Career Karma, learn how to use the find command.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/linux-find-command\/","og_locale":"en_US","og_type":"article","og_title":"Linux find Command: A Guide","og_description":"The find command allows you to find files and folders that meet a set of criteria on Linux. On Career Karma, learn how to use the find command.","og_url":"https:\/\/careerkarma.com\/blog\/linux-find-command\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-06-25T13:43:01+00:00","article_modified_time":"2023-12-01T11:26:59+00:00","og_image":[{"width":1020,"height":766,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/goran-ivos-idmvPhF8t4E-unsplash.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/linux-find-command\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/linux-find-command\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Linux find Command: A Guide","datePublished":"2020-06-25T13:43:01+00:00","dateModified":"2023-12-01T11:26:59+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/linux-find-command\/"},"wordCount":822,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/linux-find-command\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/goran-ivos-idmvPhF8t4E-unsplash.jpg","articleSection":["Software Engineering"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/linux-find-command\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/linux-find-command\/","url":"https:\/\/careerkarma.com\/blog\/linux-find-command\/","name":"Linux find Command: A Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/linux-find-command\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/linux-find-command\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/goran-ivos-idmvPhF8t4E-unsplash.jpg","datePublished":"2020-06-25T13:43:01+00:00","dateModified":"2023-12-01T11:26:59+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"The find command allows you to find files and folders that meet a set of criteria on Linux. On Career Karma, learn how to use the find command.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/linux-find-command\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/linux-find-command\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/linux-find-command\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/goran-ivos-idmvPhF8t4E-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/goran-ivos-idmvPhF8t4E-unsplash.jpg","width":1020,"height":766},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/linux-find-command\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Software Engineering","item":"https:\/\/careerkarma.com\/blog\/software-engineering-skills\/"},{"@type":"ListItem","position":3,"name":"Linux find Command: A Guide"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/18476","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=18476"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/18476\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/18477"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=18476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=18476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=18476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}