{"id":789,"date":"2011-11-28T11:09:57","date_gmt":"2011-11-28T11:09:57","guid":{"rendered":"http:\/\/blog.designed79.co.uk\/?p=789"},"modified":"2011-11-28T11:39:27","modified_gmt":"2011-11-28T11:39:27","slug":"find-files-with-time","status":"publish","type":"post","link":"https:\/\/blog.designed79.co.uk\/?p=789","title":{"rendered":"Find files with time"},"content":{"rendered":"<p>You can use the\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">find<\/div><\/div>\n<p>\u00a0command to find all files that have been modified after a certain number of days.<\/p>\n<p>For example, to find all files in the current directory that have been modified since yesterday (24 hours ago) use:<\/p>\n<pre>\n\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">find . -maxdepth 1 -mtime -1 -ls<\/div><\/div>\n\n<\/pre>\n<pre><strong>examples<\/strong>\r\n---------------------------------------------------------------------------------\r\n---------------------------------------------------------------------------------\r\nSearch for file with a specific name in a set of files (-name)\r\n\r\n<strong>find . -name test.file<\/strong>\r\n\r\n<em>searches in the current working directory for a file named \"test.file\"<\/em>\r\n\r\n<strong>find \/etc -name test.conf<\/strong>\r\n\r\n<em>searches in \/etc for a file named \"test.conf\"<\/em>\r\n\r\n---------------------------------------------------------------------------------\r\nSearch for a file and if found, execute a command\r\n\r\n<strong>find \/etc -name test.conf -exec chmod 775 {} \\;<\/strong>\r\n\r\n<em>searches in \/etc for a file named \"test.conf\" and if found, executes 'chmod 755' on that file<\/em> \r\n\r\n---------------------------------------------------------------------------------\r\nSearch for a string in files that match criteria\r\n\r\n<strong>find . -name \\*.log -exec grep \"error\" {} \\;<\/strong>\r\n\r\n<em>searches in the current working directory for all files ending in \".log\" and then executes grep on those files to find the string \"error\"<\/em>\r\n\r\n---------------------------------------------------------------------------------\r\nsearch multiple directories \r\n\r\n<strong>find \/etc \/usr -name \\*.log<\/strong> \r\n\r\n<em>searches \/etc\/ and \/usr for any files ending in \".log\"<\/em>\r\n\r\n---------------------------------------------------------------------------------\r\nsearch for files older than a certain time and remove\r\n\r\n<strong>find . -name \\*.log -mtime +10 -exec rm {} \\;<\/strong>\r\n\r\n<em>searches in the current working directory for all files ending in \".log\" and last modified over 10 days ago and removes those files<\/em>\r\n\r\n---------------------------------------------------------------------------------\r\nSearch for files that have not been accessed in a certain time and remove\r\n(with prompting)\r\n\r\n<strong>find \/apps -atime +30 -ok rm {} \\;<\/strong>\r\n\r\n<em>searches in the \/apps directory for all files that have not been accessed in over 10 days and prompts the user before removing those files<\/em>\r\n\r\n---------------------------------------------------------------------------------\r\nsearch for files by access and modify time, and long list them\r\n\r\n<strong>find \/apps \\(-mtime +10 -o -atime +20\\) -exec ls -l {} \\;<\/strong>\r\n\r\n<em>searches in the \/apps directory for all files that have not been accessed in over 20 days or not modified in over 10 days and long lists those files<\/em>\r\n\r\n---------------------------------------------------------------------------------\r\nremove core files larger than a certain size\r\n\r\n<strong>find \/apps -type f -size +104857600c -name core -exec rm {} \\;<\/strong>\r\n\r\n<em>searches in the \/apps directory for files (-type f) named \"core\" that are larger than 100mb (104857600 bytes = 100mb) and removes them<\/em>\r\n\r\n---------------------------------------------------------------------------------<\/pre>\n<pre>\n\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">&nbsp;<\/div><\/div>\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You can use the\u00a0 find \u00a0command to find all files that have been modified after a certain number of days. For example, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-789","post","type-post","status-publish","format-standard","hentry","category-info-on-tech"],"_links":{"self":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/789","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=789"}],"version-history":[{"count":0,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/789\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}