{"id":260,"date":"2020-06-11T21:50:28","date_gmt":"2020-06-11T21:50:28","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=260"},"modified":"2020-12-11T21:53:37","modified_gmt":"2020-12-11T21:53:37","slug":"finding-files-on-linux","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/finding-files-on-linux\/","title":{"rendered":"Finding files on Linux"},"content":{"rendered":"\n<p>Finding files on unix and linux Find is an extremely useful command for finding files. It searches based a specified condition at a specified directory and descends into all subdirectories of the specified directory. You must always specify a directory and a condition. Files offers lots of very powerful options which allow you to precisely define your search criteria. Following are the most useful ones:-exec command \\;Run unix command on each file matched by find, provided that it can execute successfully on that file.-followFollow symbolic links and track visited directories.-group gnameFind files belonging to group gname.-mtimeFind files which were modifed +n or -n days ago.-name patternFind files whose names match some pattern.-printPrint results using absolute pathnames.-type handleFind files whose type is handle. Handle can be f for plain file, d for directory, l for symbolic link, etc.-user userFind files belonging to certain user.<\/p>\n\n\n\n<p><strong>Some Examples<\/strong>&nbsp;List all files named myfile in you home directory<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find $HOME -name myfile -print<\/code><\/pre>\n\n\n\n<p>List all files beginning with ca in the project directory<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find \/project -type f -name \u00b4ca*\u00b4 -print<\/code><\/pre>\n\n\n\n<p>Seach the filesystem for manpage directories<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find \/ -type d -name \u00b4man\u00b4 -print<\/code><\/pre>\n\n\n\n<p>Remove all empty files<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find \/ -size 0 -ok rm  \\;<\/code><\/pre>\n\n\n\n<p>Find all files modified within the last 90 days<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find \/ -mtime -90 -print<\/code><\/pre>\n\n\n\n<p>To find executable files, you should use which or whereis commands. Some Linux versions offer GNU locate to find files. All versions of Unix and Linux fully support the find command.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Finding files on unix and linux Find is an extremely useful command for finding files. It searches based a specified condition at a specified directory and descends into all subdirectories of the specified directory. You must always specify a directory and a condition. Files offers lots of very powerful options which allow you to precisely [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101,34],"tags":[94,102,35,103],"class_list":["post-260","post","type-post","status-publish","format-standard","hentry","category-bash","category-linux","tag-bash","tag-find","tag-linux","tag-locate"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/260","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=260"}],"version-history":[{"count":1,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/260\/revisions"}],"predecessor-version":[{"id":261,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/260\/revisions\/261"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=260"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}