{"id":3407,"date":"2014-08-03T16:20:07","date_gmt":"2014-08-03T08:20:07","guid":{"rendered":"http:\/\/rmohan.com\/?p=3407"},"modified":"2014-08-03T16:26:27","modified_gmt":"2014-08-03T08:26:27","slug":"find-shell","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=3407","title":{"rendered":"find shell"},"content":{"rendered":"<p>Find files larger than 100MB\u2026<\/p>\n<p>find . -size +100000000c -ls<br \/>\nOld Files<br \/>\nFind files last modified over 30days ago\u2026<\/p>\n<p>find . -type f -mtime 30 -ls<br \/>\nFind files last modified over 365days ago\u2026<\/p>\n<p>find . -type f -mtime 365 -ls<br \/>\nFind files last accessed over 30days ago\u2026<\/p>\n<p>find . -type f -atime 30 -ls<br \/>\nFind files last accessed over 365days ago\u2026<\/p>\n<p>find . -type f -atime 365 -ls<br \/>\nFind Recently Updated Files<br \/>\nThere have been instances where a runaway process is seemingly using up any and all space left on a partition. Finding the culprit file is always useful.<\/p>\n<p>If the file is being updated at the current time then we can use find to find files modified in the last day\u2026<\/p>\n<p>find  . -type f -mtime -1 -ls<br \/>\nBetter still, if we know a file is being written to now, we can touch a file and ask the find command to list any files updated after the timestamp of that file, which will logically then list the rogue file in question.<\/p>\n<p>touch testfile<br \/>\nfind .  -type f -newer testfile -ls<br \/>\nFinding tar Files<br \/>\nA clean up of redundant tar (backup) files, after completing a piece of work say, is sometimes forgotten. Conversely, if tar files are needed, they can be identified and duly compressed (using compress or gzip) if not already done so, to help save space. Either way, the following lists all tar files for review.<\/p>\n<p>find . -type f -name &#8220;*.tar&#8221; -ls<br \/>\nfind . -type f -name &#8220;*.tar.Z&#8221; -ls<br \/>\nLarge Directories<br \/>\nList, in order, the largest sub-directories (units are in Kb)\u2026<\/p>\n<p>du -sk * | sort -n<br \/>\nSometimes it is useful to then cd into that suspect directory and re-run the du command until the large files are found.<\/p>\n<p>Removing Files using Find<br \/>\nThe above find commands can be edited to remove the files found rather than list them. The \u201c-ls\u201d switch can be changed for \u201c-exec rm {}\\;\u201d=.<\/p>\n<p>e.g.<\/p>\n<p>find . -type f -mtime 365 -exec rm {} \\;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Find files larger than 100MB\u2026<\/p>\n<p>find . -size +100000000c -ls Old Files Find files last modified over 30days ago\u2026<\/p>\n<p>find . -type f -mtime 30 -ls Find files last modified over 365days ago\u2026<\/p>\n<p>find . -type f -mtime 365 -ls Find files last accessed over 30days ago\u2026<\/p>\n<p>find . -type f -atime 30 -ls Find [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3407"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3407"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3407\/revisions"}],"predecessor-version":[{"id":3408,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3407\/revisions\/3408"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}