{"id":8074,"date":"2014-06-13T05:02:45","date_gmt":"2014-06-12T19:02:45","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=8074"},"modified":"2014-06-13T05:02:45","modified_gmt":"2014-06-12T19:02:45","slug":"files-since-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/files-since-primer-tutorial\/","title":{"rendered":"Files Since Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Windows\/FilesSince\/Files_Since.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Files Since Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Windows\/FilesSince\/Files_Since.jpg\" title=\"Files Since Primer Tutorial\" \/><\/a><p class=\"wp-caption-text\">Files Since Primer Tutorial<\/p><\/div>\n<p>A while ago we spoke of the Linux commands find and locate in <a href=\"#lfalfpt\">Linux Find and\/or Locate Files\/Directories Primer Tutorial<\/a> as shown below.  After that you may have been thinking &#8220;That&#8217;s it!  No more carrying on about directory listings and stuff!&#8221; &#8230; and we say &#8230; but on a practical level how can this knowledge be set to good use?<\/p>\n<p>With that in mind, today, we do a tutorial called &#8220;Files Since&#8221; (and just concentrate on command line work &#8230; there may well be Mac Finder and\/or Windows Explorer solutions to this problem, but want to stick to command line, for today), because it is easy to get <strike>sidetracted<\/strike> sidetracked these days and forget what you&#8217;ve been doing, so today for both Mac and Windows we show a scenario of (finding files that):<\/p>\n<ul>\n<li>are HTML<\/li>\n<li>have been worked on over the last seven days<\/li>\n<li>from all directories and subdirectories off where we are now (in relevant command line environment)<\/li>\n<\/ul>\n<p>Obviously, if you are asleep now, you&#8217;ll continue to be asleep, and you can sleep through the next bit just as well.<\/p>\n<p>But if you are still here, this scenario is a doddle for Mac (via Bash environment find command via Terminal application).  However, believe it or not, it is not straightforward in a Windows (DOS command line) environment, depending on how user-friendly you want the information to be &#8230; let me explain &#8230; DOS command line (out of the box) can do a listing sorted by date (descending) of the last file write date for all the subdirectories, but, without some tailoring it can&#8217;t cut off the report and not mention superfluous files to your designated date range of interest &#8230; for us, 7 days.<\/p>\n<p>You might ask, &#8220;How come?&#8221; &#8230; and that is a good question &#8230; but wasting time &#8230; so why don&#8217;t we create a hybrid DOS\/Linux-find-equivalent-of-mtime-switch scenario.  What is meant by this is that Windows\/DOS does 99% of what anybody wants, and that is good (thanks), but why not try to add on the bit of Linux find (its -mtime -7d (for our case) &#8230; (just the d suboption will be assumed)) cute functionality into our Windows\/DOS world &#8230; with help from <a target=_blank href='http:\/\/www.experts-exchange.com\/OS\/Microsoft_Operating_Systems\/MS_DOS\/A_10774-Advanced-Batch-File-Programming-YESTERDAY-BAT.html' title='Get date of yesterday in DOS Batch'>here<\/a> (get yesterday&#8217;s date in DOS batch &#8230; thanks) and <a target=_blank title='Brilliant DOS batch string functionality web page ... thanks' href='http:\/\/www.dostips.com\/DtTipsStringOperations.php'>here<\/a> (brilliant DOS batch string functionality web page &#8230; thanks) this became possible and we would like you to try <a target=_blank title='mydir.bat' href='http:\/\/www.rjmprogramming.com.au\/Windows\/FilesSince\/mydir.bat_GETME'>mydir.bat<\/a> should you wish to try it out.  Where should you place mydir.bat in order to try it out on Windows?  Well, if &#8220;mydir&#8221; as a command line command, means nothing, at present on your system, it would be best of all to place mydir.bat somewhere in the path (the directories of which can be gleaned from <i>echo %PATH%<\/i>), but you may not want it that public, and so, just place mydir.bat in the root directory of interest you want information about, if this is your case &#8230; in either scenario mydir.bat works after you have used <i>cd [blah blah]<\/i> to get to the root directory of your interest.  For our example scenarios today the [blah blah] equated to the root directories for the local Apache web server of interest &#8230; for Windows the root directory of <a target=_blank href='http:\/\/www.easyphp.org\/' title='EasyPHP home page'>EasyPHP<\/a> ( &#8220;c:Program FilesEasyPHP-12.1www&#8221; ) and for Mac the root directory of <a target=_blank href='http:\/\/www.mamp.info\/' title='MAMP home page'>MAMP<\/a> ( \/Applications\/MAMP\/htdocs ).   More on this happens on this blog at <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=4112' title='Generic web server tutorial'>Cassini++ WebServer Primer Tutorial<\/a>.<\/p>\n<p>So, in summary, try this tutorial for ideas about command line environment solutions to the &#8220;Files since &#8230;&#8221; scenario that many of us often face when using computers &#8230; our commands ended up:<\/p>\n<ul>\n<li>find . -name &#8220;*.htm*&#8221; -mtime -7 2&gt; \/dev\/null        # Mac (via Linux Bash via Terminal)  NB. Some environments would ask for switch -mtime -7d<\/li>\n<li>mydir *.htm* \/s \/t:w \/o:-d \/m:-7       rem  Windows (via DOS command line)<\/li>\n<\/li>\n<hr \/>\n<p id='lfalfpt'>Previous relevant <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=7067\">Linux Find and\/or Locate Files\/Directories Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Linux\/locate\/LocateFind_Linux.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Linux Find and\/or Locate Files\/Directories Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Linux\/locate\/LocateFind_Linux.jpg\" title=\"Linux Find and\/or Locate Files\/Directories Primer Tutorial\" \/><\/a><p class=\"wp-caption-text\">Linux Find and\/or Locate Files\/Directories Primer Tutorial<\/p><\/div>\n<p>Linux (or Unix) servers have two really useful commands which help the user find files and\/or directories &#8230; <a target=_blank title='Linux\/unix locate command help from Computerhope ... thanks' href='http:\/\/www.computerhope.com\/unix\/ulocate.htm'>locate<\/a> and <a target=_blank title='Linux\/unix find command help from Computerhope ... thanks' href='http:\/\/www.computerhope.com\/unix\/ufind.htm'>find<\/a>.  Doubt there are many people out there who have not mislaid a computer file at some time or other.   The GUI options are there, such as Windows Explorer and Mac Finder, but you tend to think, with these, of the one area or folder to search (mind you both are capable of better), whereas you often face the dilemma of having no idea where the file is.   The GUIs can help here, but find, for myself, that I always jump to the command line for this, with Windows command line DIR C: [filespec] \/s or the Linux\/Unix commands for today&#8217;s tutorial &#8230; locate and find.<\/p>\n<p>So why confuse things with two choices?   Well, locate is fast, once set up, because it sets up its own &#8220;database&#8221; of previous knowledge, and so can pluck out whatever you want really fast from then on, once you use a &#8220;<a target=_blank title='Linux\/unix sudo command help from Computerhope ... thanks.' href='http:\/\/www.computerhope.com\/unix\/sudo.htm'>sudo<\/a>&#8221; command to set up locate for future use.<\/p>\n<p>The strength of the Linux\/Unix find command are its switches like &#8220;-type ?&#8221; to define what type of file to find, and the way you can use &#8220;exec&#8221; in a piped scenario, to add more functionality.<\/p>\n<p>So some words about the syntax (and for this, found <i>Linux<\/i> by Steve Oualline and Eric Foster-Johnson (pp 72-73) an excellent source) where you can hover or click for further information:<\/p>\n<ul>\n<script>function showt(ospan) {\n  ospan.style.backgroundColor = 'yellow';\n  alert(ospan.title);\n  ospan.style.backgroundColor = '';\n}<\/script><\/p>\n<li><span id=\"a1\" title=\"The locate command in Linux or unix.\" onclick=\"showt(this);\">locate<\/span> <span id=\"a2\" title=\"File name or file name fragment to look for.\" onclick=\"showt(this);\">gimp<\/span> <span id=\"a3\" title=\"Pipe operator in Linux or unix.\" onclick=\"showt(this);\">|<\/span> <span id=\"a4\" title=\"Pipe to more command for 13 lines at a time.\" onclick=\"showt(this);\">more -y 13<\/span><\/li>\n<li><span id=\"b1\" title=\"The find command in Linux or unix.\" onclick=\"showt(this);\">find<\/span> <span id=\"b2\" title=\"This is start directory of search.\" onclick=\"showt(this);\">\/<\/span> <span id=\"b3\" title=\"Find command searches for all files satisfying *gimp* filespec.\" onclick=\"showt(this);\">-name &#8220;*gimp*&#8221;<\/span> <span id=\"b4\" title=\"Filter search to files of type f (file) so that directores and special files are excluded.\" onclick=\"showt(this);\">-type f<\/span> <span id=\"b5\" title=\"What to do when file is found - print it to standard output..\" onclick=\"showt(this);\">-print<\/span> <span id=\"b6\" title=\"Ignore outputting any errors found performing this command.\" onclick=\"showt(this);\">2> \/dev\/null<\/span> <span id=\"by\" title=\"Pipe operator in Linux or unix.\" onclick=\"showt(this);\">| <\/span> <span id=\"b8\" title=\"Pipe to more command for 13 lines at a time.\" onclick=\"showt(this);\">more -y 13<\/span><\/li>\n<li><span id=\"c1\" title=\"The find command in Linux or unix.\" onclick=\"showt(this);\">find<\/span> <span id=\"c2\" title=\"This is start directory of search.\" onclick=\"showt(this);\">$HOME\/Documents<\/span> <span id=\"c3\" title=\"Find command searches for all files satisfying *.htm* filespec.\" onclick=\"showt(this);\">-name &#8220;*.htm*&#8221;<\/span> <span id=\"c4\" title=\"Filter search to files of type f (file) so that directores and special files are excluded.\" onclick=\"showt(this);\">-type f<\/span> <span id=\"c5\" title=\"Use to execute command on the file.\" onclick=\"showt(this);\">-exec<\/span> <span id=\"c6\" title=\"This is the command executed on each file where {} is replaced by the actual filename ( eg. fgrep body $HOME\/Documents\/index.html \/dev\/null ).\" onclick=\"showt(this);\">fgrep body {} \/dev\/null<\/span> <span id=\"c7\" title=\"End of command.\" onclick=\"showt(this);\"> ;<\/span><\/li>\n<\/ul>\n<p>So today we see some actions to find and\/or locate files\/directories with this <a target=_blank href=\"\/Linux\/locate\/LocateFind_Linux.jpg\" title=\"Click picture\">tutorial<\/a>.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d7067' onclick='var dv=document.getElementById(\"d7067\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=Linux\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d7067' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d8074' onclick='var dv=document.getElementById(\"d8074\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=command-line\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d8074' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>A while ago we spoke of the Linux commands find and locate in Linux Find and\/or Locate Files\/Directories Primer Tutorial as shown below. After that you may have been thinking &#8220;That&#8217;s it! No more carrying on about directory listings and &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/files-since-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,29,37],"tags":[234,358,707,723,885,997,1319,1435],"class_list":["post-8074","post","type-post","status-publish","format-standard","hentry","category-elearning","category-operating-system","category-tutorials","tag-command-line","tag-dos","tag-linux","tag-mac","tag-operating-system-2","tag-programming","tag-tutorial","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/8074"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=8074"}],"version-history":[{"count":0,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/8074\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=8074"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=8074"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=8074"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}