{"id":64216,"date":"2024-07-16T03:01:00","date_gmt":"2024-07-15T17:01:00","guid":{"rendered":"https:\/\/65.254.95.247\/ITblog\/?p=64216"},"modified":"2024-07-25T13:00:23","modified_gmt":"2024-07-25T03:00:23","slug":"linux-find-and-or-locate-files-directories-application-extensions-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-find-and-or-locate-files-directories-application-extensions-tutorial\/","title":{"rendered":"Linux Find and\/or Locate Files\/Directories Application Extensions Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/todays_plist.gif\" rel=\"noopener\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Linux Find and\/or Locate Files\/Directories Application Extensions Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/todays_plist.gif\" title=\"Linux Find and\/or Locate Files\/Directories Application Extensions Tutorial\" \/><\/a><p class=\"wp-caption-text\">Linux Find and\/or Locate Files\/Directories Application Extensions Tutorial<\/p><\/div>\n<p>A lot of us have FOMO &#8230; ie. Fear of Missing Out &#8230; over something.   One that worries us, running a web server, is the fear of missing out on the daily report we get regarding software on the RJM Programming website telling us &#8230;<\/p>\n<blockquote><p>\nWhat, we term as <i>&#8220;Application Executable&#8221; files<\/i>, changed on the RJM Programming web server within the last 5 days\n<\/p><\/blockquote>\n<p>Today&#8217;s nuanced change to our arrangements revolve around the file extension list covering <i>&#8220;Application Executable&#8221; files<\/i>.  We&#8217;d been covering &#8230;<\/p>\n<ol>\n<li>*.htm*<\/li>\n<li>*.html*<\/li>\n<li>*.php* &#8230; but not, until today &#8230;<\/li>\n<li>*.*htm*<\/li>\n<\/ol>\n<p>Yes, read about the <a target=\"_blank\" title='Discussion regarding *.phtml extension' href='https:\/\/stackoverflow.com\/questions\/11859015\/what-is-phtml-and-when-should-i-use-a-phtml-extension-rather-than-php' rel=\"noopener\">*.phtml<\/a> extension, and we&#8217;ve seen with error handling <a target=\"_blank\" title='Discussion regarding *.shtml extension' href='https:\/\/stackoverflow.com\/questions\/519619\/what-is-the-purpose-and-uniqueness-shtml' rel=\"noopener\">*.shtml<\/a> and <a target=\"_blank\" title='Information about *.dhtml extension' href='https:\/\/fileinfo.com\/extension\/dhtml' rel=\"noopener\">*.dhtml<\/a> as well.  So, yes, we&#8217;re definitely interested!<\/p>\n<p>We&#8217;re hoping <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/todays_plist.gif\" rel=\"noopener\">today&#8217;s tweaked<\/a> and <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/todays_list.ksh---GETME\" title=\"todays_list.ksh\" rel=\"noopener\">changed Korn Shell script<\/a> called <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/todays_list.ksh---GETME\" title=\"todays_list.ksh\" rel=\"noopener\">todays_list.ksh<\/a> called (regarding the report creation only) via <a target=\"_blank\" title='crontab information from computerhope ... thanks' href='http:\/\/www.computerhope.com\/jargon\/c\/cron.htm' rel=\"noopener\">crontab<\/a> &#8230;<\/p>\n<p><code><br \/>\nmm hh * * * ksh \/etc\/init.d\/todays_list.ksh<br \/>\n<\/code><\/p>\n<p> &#8230; (mm represents minute of hour of day and hh represents hour of day) can ease the &#8220;FOMO within&#8221;, further to the previous <a title='Linux Find and\/or Locate Files\/Directories Double Quote Tutorial' href='#lf\/lf\/ddqt'>Linux Find and\/or Locate Files\/Directories Double Quote Tutorial<\/a>.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=\"_blank\" href='\/\/www.rjmprogramming.com.au\/ITblog\/linux-find-andor-locate-filesdirectories-application-extensions-tutorial\/' rel=\"noopener\">Linux Find and\/or Locate Files\/Directories Application Extensions Tutorial<\/a>.<\/p-->\n<hr>\n<p id='lf\/lf\/ddqt'>Previous relevant <a target=\"_blank\" title='Linux Find and\/or Locate Files\/Directories Double Quote Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/linux-find-and\/or-locate-files\/directories-double-quote-tutorial\/' rel=\"noopener\">Linux Find and\/or Locate Files\/Directories Double Quote Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/todaylist_fix_double_quote.gif\" rel=\"noopener\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Linux Find and\/or Locate Files\/Directories Double Quote Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/todaylist_fix_double_quote.gif\" title=\"Linux Find and\/or Locate Files\/Directories Double Quote Tutorial\" \/><\/a><p class=\"wp-caption-text\">Linux Find and\/or Locate Files\/Directories Double Quote Tutorial<\/p><\/div>\n<p>When you write inhouse procedures that end in reports you can occasionally &#8220;get sideswiped&#8221; by peculiarities in the data that occurs.  But it could be the cause of that irregularity that the report is meant to highlight.   And so, if there is a problem showing the report, then what&#8217;s the point?!<\/p>\n<p>This started happening to us the other day with the procedure that sends us information about &#8220;files changed in the last week&#8221; on this RJM Programming domain, whose blog you are reading now.   This report gives a list of Linux web server files changed since the last week, roughly.  We first talked about all this way back with <a title='Linux Find and\/or Locate Files\/Directories Primer Tutorial' href='#lf\/lf\/dpt'>Linux Find and\/or Locate Files\/Directories Primer Tutorial<\/a>.<\/p>\n<p>Our research started because of an error message when bringing up the &#8220;files since&#8221; report &#8230;<\/p>\n<blockquote><p>\n<b>Parse error:<\/b> syntax error, unexpected &#8216;Z&#8217; (T_STRING), expecting &#8216;,&#8217; or &#8216;;&#8217; in todaylist.php on line 155\n<\/p><\/blockquote>\n<p> &#8230; making us think this was a PHP coding issue.  Please don&#8217;t jump to conclusions though.  Anyway, step 1 should be to go to &#8220;todaylist.php&#8221; (the &#8220;files since&#8221; report, we needed to be reminded) to its line 155.  Doh?!?!  Got us to see the record &#8230;<\/p>\n<blockquote><p>\n&lt;br&gt;.\/PHP\/x_f(now)=sysdate().sleep(3),0))XOR&#8221;Z.htm\n<\/p><\/blockquote>\n<p>Huh?!  Yes, you are not alone aghast about this form of filename!  But it&#8217;s possible, so there are now two problem aspects &#8230;<\/p>\n<ul>\n<li>the immediate problem (of those files existing) &#8230; the date being old told us that this was caused by a one off coding issue on a day &#8230; so we deleted files of this <b>.\/PHP\/x_*.*<\/b> filespec &#8230; there were a few &#8230; but also &#8230;<\/li>\n<li>the long term issue &#8230; our reporting coding should be able to handle this, so as to proceed with the report, and hence lead us to the issue on an immediate basis, on which the rest of this tutorial concentrates<\/li>\n<\/ul>\n<p>Okay, then, we first did this.  We rewrote the todaylist.php content without problematic filenames into a tlist.php incarnation until we got a clear run.  The various line numbers encountered showed us the problematic filename characteristic in common with the problems was the existence of &#8230;<\/p>\n<blockquote><p>\n&#8221;\n<\/p><\/blockquote>\n<p> <font size=1>&#8230; we&#8217;ve always wanted to do this<\/font> &#8230; character within filenames.  This aligns with a common PHP issue.  Having double quotes <font size=1>un-<\/font>backslashed within data delimited by double quotes is bound to cause issues.  This made us follow the path of making the data contain backslashed double quotes, should they occur within file names.<\/p>\n<p>This filename data, we discovered, and were reminded about (though you can read below &#8230; doh!?!?) gets created via a crontab Korn Shell procedure we have <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/todays_list.ksh--GETME\" title=\"todays_list.ksh\" rel=\"noopener\">now changed<\/a> to be <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/todays_list.ksh--GETME\" title=\"todays_list.ksh\" rel=\"noopener\">todays_list.ksh<\/a> where a piped <a target=\"_blank\" title='Linux sed information' href='https:\/\/www.computerhope.com\/unix\/used.htm' rel=\"noopener\">sed<\/a> clause helps create this backslashed double quote scenario to occur at the filename data creation stage of the procedures, leaving any PHP involved not needing to change, as you can see with today&#8217;s <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/todaylist_fix_double_quote.gif\" rel=\"noopener\">tutorial animated GIF<\/a> presentation.   Aaaaaaaahh!<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=\"_blank\" href='\/\/www.rjmprogramming.com.au\/ITblog\/linux-find-andor-locate-filesdirectories-double-quote-tutorial\/' rel=\"noopener\">Linux Find and\/or Locate Files\/Directories Double Quote Tutorial<\/a>.<\/p-->\n<hr>\n<p id='lf\/lf\/dpt'>Previous relevant <a target=\"_blank\" title='Linux Find and\/or Locate Files\/Directories Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/linux-find-and\/or-locate-files\/directories-primer-tutorial\/' rel=\"noopener\">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\" rel=\"noopener\"><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' rel=\"noopener\">locate<\/a> and <a target=\"_blank\" title='Linux\/unix find command help from Computerhope ... thanks' href='http:\/\/www.computerhope.com\/unix\/ufind.htm' rel=\"noopener\">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' rel=\"noopener\">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\" rel=\"noopener\">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<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='#d57798' onclick='var dv=document.getElementById(\"d57798\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/korn-shell\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d57798' 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='#d64248' onclick='var dv=document.getElementById(\"d64248\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/report\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d64248' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>A lot of us have FOMO &#8230; ie. Fear of Missing Out &#8230; over something. One that worries us, running a web server, is the fear of missing out on the daily report we get regarding software on the RJM &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-find-and-or-locate-files-directories-application-extensions-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,33,37],"tags":[234,272,274,301,302,380,3929,1797,418,2655,435,4845,677,707,3279,885,1054,1105,1114,1138,1411],"class_list":["post-64216","post","type-post","status-publish","format-standard","hentry","category-elearning","category-software","category-tutorials","tag-command-line","tag-cron","tag-crontab","tag-date","tag-datetime","tag-email","tag-executable","tag-extension","tag-file","tag-file-extension","tag-find","tag-fomo","tag-korn-shell","tag-linux","tag-modified","tag-operating-system-2","tag-report","tag-script","tag-security","tag-shell","tag-web-server"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/64216"}],"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=64216"}],"version-history":[{"count":1,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/64216\/revisions"}],"predecessor-version":[{"id":64217,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/64216\/revisions\/64217"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=64216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=64216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=64216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}