{"id":1287,"date":"2017-04-14T17:24:01","date_gmt":"2017-04-14T11:54:01","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=1287"},"modified":"2017-04-15T14:49:40","modified_gmt":"2017-04-15T09:19:40","slug":"learn-find-command-usages","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/learn-find-command-usages\/","title":{"rendered":"Learn Find Command and usages"},"content":{"rendered":"<h3>Learn Find Command and usages<\/h3>\n<p><strong>Date Posted: 28-03-2017<\/strong><\/p>\n<p>Find is a command which is used to find files and directories based on various scenario. In this post, we will explain find command and usage with some examples.<\/p>\n<p>Find a filename called<span style=\"color: #ff6600;\"> test.txt<\/span> on the directory \/home\/pheonixsolutions. The below command\u00a0search all the directories and report\u00a0test.txt.<\/p>\n<p><code>find \/home\/pheonixsolutions\/ -type f -name test.txt<\/code><\/p>\n<p>Find filename starts test and extension is txt(say test1.txt, test2.txt, test3.txt).<\/p>\n<p><code>find \/home\/pheonixsolutions\/ -type f -name test*.txt<\/code><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">\/home\/pheonixsolutions\/test1.txt\r\n\/home\/pheonixsolutions\/test2.txt\r\n\/home\/pheonixsolutions\/test3.txt\r\n<\/pre>\n<p>Find directory named called <em>dir\u00a0<\/em>on the current working directory(for current working directory, we will be using .)<\/p>\n<p><code>find . -type d -name dir<\/code><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">.\/dir1\/dir\r\n.\/dir<\/pre>\n<p>Find directory named called <em>dir<\/em> with maximum of 2 sub directories<\/p>\n<p><code>find . -type d -name dir -maxdepth 2<\/code><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">.\/dir1\/dir\r\n.\/dir<\/pre>\n<p>Find directory named called <em>dir<\/em> with minimum of 2 directories.<\/p>\n<p><code>find . -type d -name dir -mindepth 2<\/code><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">.\/dir1\/dir\r\n.\/dir1\/dir2\/dir<\/pre>\n<p>Find the file which has permission of 644.<\/p>\n<p><code>find . -type f -perm 644<\/code><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">.\/dir1\/file1.txt\r\n\/dir\/dir1\/file2.txt\r\nfile.txt<\/pre>\n<p>Execute commands to the find command result. This will list\u00a0files with full information.<\/p>\n<p><code>find . -type f -exec ls -la\u00a0<\/code><\/p>\n<p>The below example will change the permission of the find file.<\/p>\n<p><code>find . type f -exec chmod 644 {} \\;<\/code><\/p>\n<p>Assign find command result using <em>xargs.\u00a0<\/em><\/p>\n<p><code>find . type f |xargs ls -la\u00a0<\/code><\/p>\n<p>Use find command result on multiple places.<\/p>\n<p><code>find . -type f |xargs -I {} mv {} {}_bak<\/code><\/p>\n<p>Find the files which are older than 3 days<\/p>\n<p><code>find . -type f -mtime +3<\/code><\/p>\n<p>To delete files which are older than 3 days.<\/p>\n<p><code>find . -type f -mtime +5 -exec rm {} \\;<\/code><\/p>\n<p>To find the files which are <em>accessed<\/em> before 5 days<\/p>\n<p><code>find . -type f -atime +5<\/code><\/p>\n<p>Find files which ownership is\u00a0\u00a0<em>pheonixsolutions<\/em><\/p>\n<p><code>find . -type f -user pheonixsolutions<\/code><\/p>\n<p>To find files which group is\u00a0<em>pheonixsolutions<\/em><\/p>\n<p><code>find . -type f -group pheonixsolutions<\/code><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn Find Command and usages Date Posted: 28-03-2017 Find is a command which is used to find files and directories [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[312,320,261],"class_list":["post-1287","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-command","tag-find","tag-linux","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phns3A-kL","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=1287"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1287\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}