{"id":57798,"date":"2022-12-18T03:01:18","date_gmt":"2022-12-17T17:01:18","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=57798"},"modified":"2022-12-17T14:37:49","modified_gmt":"2022-12-17T04:37:49","slug":"linux-find-andor-locate-filesdirectories-double-quote-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-find-andor-locate-filesdirectories-double-quote-tutorial\/","title":{"rendered":"Linux Find and\/or Locate Files\/Directories Double Quote Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/todaylist_fix_double_quote.gif\"><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\">now changed<\/a> to be <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/todays_list.ksh--GETME\" title=\"todays_list.ksh\">todays_list.ksh<\/a> where a piped <a target=_blank title='Linux sed information' href='https:\/\/www.computerhope.com\/unix\/used.htm'>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\">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\/'>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\/'>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<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","protected":false},"excerpt":{"rendered":"<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 &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-find-andor-locate-filesdirectories-double-quote-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":[4177,234,274,2276,3186,418,4174,2671,3336,4175,677,707,932,997,1764,4176,1115,1319,1411],"class_list":["post-57798","post","type-post","status-publish","format-standard","hentry","category-elearning","category-operating-system","category-tutorials","tag-backslash","tag-command-line","tag-crontab","tag-delimitation","tag-double-quote","tag-file","tag-file-name","tag-file-specification","tag-filename","tag-files-since","tag-korn-shell","tag-linux","tag-php","tag-programming","tag-reporting","tag-reprt","tag-sed","tag-tutorial","tag-web-server"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/57798"}],"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=57798"}],"version-history":[{"count":4,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/57798\/revisions"}],"predecessor-version":[{"id":57802,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/57798\/revisions\/57802"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=57798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=57798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=57798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}