{"id":55327,"date":"2022-04-07T03:01:59","date_gmt":"2022-04-06T17:01:59","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=55327"},"modified":"2022-04-07T11:20:46","modified_gmt":"2022-04-07T01:20:46","slug":"php-file-finding-shell-exec-versus-exec-plus-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-file-finding-shell-exec-versus-exec-plus-tutorial\/","title":{"rendered":"PHP File Finding shell_exec Versus exec Plus Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/s_e\/find_minus.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"PHP File Finding shell_exec Versus exec Plus Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/s_e\/find_minus_exec.jpg\" title=\"PHP File Finding shell_exec Versus exec Plus Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">PHP File Finding shell_exec Versus exec Plus Tutorial<\/p><\/div>\n<p>Yesterday&#8217;s <a title='PHP File Finding Signed Time shell_exec Versus exec Tutorial' href='#phpffst_vt'>PHP File Finding Signed Time shell_exec Versus exec Tutorial<\/a>, and postings before it considered &#8220;exec&#8221; &#8230;<\/p>\n<ul>\n<li>to be related to the PHP function <a target=_blank title='PHP exec() method information' href='http:\/\/php.net\/manual\/en\/function.exec.php'>exec<\/a> <font size=1>(a favourite of ours)<\/font> &#8230; but then, we introduce today, the idea of &#8220;exec&#8221; as a &#8230;<\/li>\n<li>command line (on Linux or unix or macOS) <a target=_blank title='Linux find command information from computerhope' href='http:\/\/www.computerhope.com\/unix\/ufind.htm'>find<\/a> command switch &#8220;exec&#8221;<\/a> switch &#8230;<br \/>\n<blockquote cite='https:\/\/man7.org\/linux\/man-pages\/man1\/find.1.html'><p>\n       -exec command ;<br \/>\n              Execute command; true if 0 status is returned.  All<br \/>\n              following arguments to find are taken to be arguments to<br \/>\n              the command until an argument consisting of `;&#8217; is<br \/>\n              encountered.  The string `{}&#8217; is replaced by the current<br \/>\n              file name being processed everywhere it occurs in the<br \/>\n              arguments to the command, not just in arguments where it<br \/>\n              is alone, as in some versions of find.  Both of these<br \/>\n              constructions might need to be escaped (with a `\\&#8217;) or<br \/>\n              quoted to protect them from expansion by the shell.  See<br \/>\n              the EXAMPLES section for examples of the use of the -exec<br \/>\n              option.  The specified command is run once for each<br \/>\n              matched file.  The command is executed in the starting<br \/>\n              directory.  There are unavoidable security problems<br \/>\n              surrounding use of the -exec action; you should use the<br \/>\n              -execdir option instead.\n<\/p><\/blockquote>\n<\/li>\n<\/ul>\n<p> &#8230; that we start improving upon for those Linux or unix or macOS users to see information about via hovering over the &#8220;result set&#8221; table presented (via title attribute).<\/p>\n<p>So, feel free to try <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/s_e\/find_minus.php--GETME\" title=\"find_minus.php\">the changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/s_e\/find_minus.php--GETME\" title=\"find_minus.php\">find_minus.php<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/s_e\/find_minus.php\" title=\"Click picture\">live run link<\/a> also available <a href='#iffinds'>here below<\/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\/php-file-finding-shell_exec-versus-exec-plus-tutorial\/'>PHP File Finding shell_exec Versus exec Plus Tutorial<\/a>.<\/p-->\n<hr>\n<p id='phpffst_vt'>Previous relevant <a target=_blank title='PHP File Finding Signed Time shell_exec Versus exec Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/php-file-finding-signed-time-shell_exec-versus-exec-tutorial\/'>PHP File Finding Signed Time shell_exec Versus exec Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/s_e\/find_minus.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"PHP File Finding Signed Time shell_exec Versus exec Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/s_e\/find_minus_st.jpg\" title=\"PHP File Finding Signed Time shell_exec Versus exec Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">PHP File Finding Signed Time shell_exec Versus exec Tutorial<\/p><\/div>\n<p>The recent <a title='PHP File Finding shell_exec Versus exec Tutorial' href='#phpff_vt'>PHP File Finding shell_exec Versus exec Tutorial<\/a>, on the Linux and\/or unix and\/or macOS side of functionality, did not factor in the choice of &#8230;<\/p>\n<ul>\n<li>+<\/li>\n<li>&#8211;<\/li>\n<\/ul>\n<p> &#8230; signage possibilities for the &#8220;find&#8221; command we use via PHP&#8217;s exec function.  The <a target=_blank title='man find' href='https:\/\/man7.org\/linux\/man-pages\/man1\/find.1.html'>&#8220;man find&#8221;<\/a> <font color=blue>tells us<\/font> &#8230;<\/p>\n<blockquote cite='https:\/\/man7.org\/linux\/man-pages\/man1\/find.1.html'><p>\n       -atime n<br \/>\n              File was last accessed less than, more than or exactly<br \/>\n              n*24 hours ago.  When find figures out how many 24-hour<br \/>\n              periods ago the file was last accessed, any fractional<br \/>\n              part is ignored, so to match -atime +1, a file has to have<br \/>\n              been accessed <font color=blue>at least<\/font> two days ago.\n<\/p><\/blockquote>\n<p> &#8230; that not involving these &#8220;time sign<font size=1>age<\/font>&#8221; ideas (we add in a new dropdown), by choosing a <i>blank sign<\/i> could be causing you not to see files you expected if you had included one of these signs.<\/p>\n<p>And so, feel free to try <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/s_e\/find_minus.php-GETME\" title=\"find_minus.php\">the changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/s_e\/find_minus.php-GETME\" title=\"find_minus.php\">find_minus.php<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/s_e\/find_minus.php\" title=\"Click picture\">live run link<\/a> also available <a href='#iffinds'>here below<\/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\/php-file-finding-signed-time-shell_exec-versus-exec-tutorial\/'>PHP File Finding Signed Time shell_exec Versus exec Tutorial<\/a>.<\/p-->\n<hr>\n<p id='phpff_vt'>Previous relevant <a target=_blank title='PHP File Finding shell_exec Versus exec Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/php-file-finding-shell_exec-versus-exec-tutorial\/'>PHP File Finding shell_exec Versus exec Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/s_e\/find_minus.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"PHP File Finding shell_exec Versus exec Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/s_e\/find_minus.jpg\" title=\"PHP File Finding shell_exec Versus exec Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">PHP File Finding shell_exec Versus exec Tutorial<\/p><\/div>\n<p>Lots of software based desktop application problems are centred around the <i>finding of files via a time based criteria<\/i>.  With this in mind, today, we combine &#8230;<\/i><\/p>\n<ul>\n<li>the PHP [<a target=_blank title='PHP exec() method information' href='http:\/\/php.net\/manual\/en\/function.shell-exec.php'>shell_<\/a>]<a target=_blank title='PHP exec() method information' href='http:\/\/php.net\/manual\/en\/function.exec.php'>exec<\/a> arrangements featuring in the day before yesterday&#8217;s <a title='PHP shell_exec Versus exec Tutorial' href='#php_vt'>PHP shell_exec Versus exec Tutorial<\/a> &#8230; with &#8230;<\/li>\n<li>the &#8220;smarts&#8221; (at least for macOS and unix\/linux underlying operating systems) for some time based <a target=_blank title='Linux find command information from computerhope' href='http:\/\/www.computerhope.com\/unix\/ufind.htm'>&#8220;find&#8221;<\/a> command filtering ideas<\/li>\n<\/ul>\n<p> &#8230; whether that be related to &#8230;<\/p>\n<ul>\n<li>file modified time<\/li>\n<li>file access time<\/li>\n<li>file created time<\/li>\n<li>file inode creation time<\/li>\n<\/ul>\n<p>That sort of &#8220;find&#8221; file finding functionality <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/s_e\/find_minus.php_GETME\" title=\"find_minus.php\">find_minus.php<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/s_e\/find_minus.php\" title=\"Click picture\">live run link<\/a> can be a part of a &#8220;housekeeping&#8221; type of scheduled job, such as described via a crontab entry such as &#8230;<\/p>\n<p><code><br \/>\n04 3 * * * ksh -c 'for i in `find .\/PHP\/animegif -name \"0*.php\" -mtime +7`; do rm -f $i; done'<br \/>\n<\/code><\/p>\n<p><iframe id=iffinds src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/s_e\/find_minus.php\" style=\"width:100%;height:900px;\"><\/iframe><\/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\/php-file-finding-shell_exec-versus-exec-tutorial\/'>PHP File Finding shell_exec Versus exec Tutorial<\/a>.<\/p-->\n<hr>\n<p id='php_vt'>Previous relevant <a target=_blank title='PHP shell_exec Versus exec Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/php-shell_exec-versus-exec-tutorial\/'>PHP shell_exec Versus exec Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/s_e\/s_e.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"PHP shell_exec Versus exec Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/s_e\/s_e.jpg\" title=\"PHP shell_exec Versus exec Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">PHP shell_exec Versus exec Tutorial<\/p><\/div>\n<p>Being suckers for &#8220;out of the box&#8221; solutions to programming issues, what comes &#8220;out of the box&#8221; with your (perhaps underlying) operating system of use is always inflicting &#8220;sucker punches&#8221; onto areas we didn&#8217;t know existed before <font size=1>&#8230; well, you had to be there, didn&#8217;t you?<\/font><\/p>\n<p>That&#8217;s why we really like PHP&#8217;s <a target=_blank title='PHP exec() method information' href='http:\/\/php.net\/manual\/en\/function.exec.php'>&#8220;exec&#8221;<\/a> and <a target=_blank title='PHP exec() method information' href='http:\/\/php.net\/manual\/en\/function.passthru.php'>&#8220;passthru&#8221;<\/a> that we have used quite a bit in the past, to get through to that underlying operating system set of commands in its command line environment, as applicable.  Even mobile platforms get a go here, because PHP is a serverside language addressing the RJM Programming linux web server, though you can download <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/s_e\/s_e.php_GETME\" title=\"s_e.php\">s_e.php<\/a> to your local (client) environment, and access a different perspective in an Apache\/PHP\/MySql local web server environment such as <a target=_blank title='MAMP for Apache\/PHP\/MySql on Mac OS X local web server' href='http:\/\/www.mamp.info'>MAMP<\/a> to work in.<\/p>\n<p>Today, we compare <a target=_blank title='PHP exec() method information' href='http:\/\/php.net\/manual\/en\/function.shell-exec.php'>&#8220;shell_exec&#8221;<\/a> to &#8220;exec&#8221; with our <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/s_e\/s_e.php\">proof of concept PHP web application<\/a> we&#8217;ve written for you to try today, for you to see that &#8220;shell_exec&#8221; is everything &#8220;exec&#8221; is plus returning the entire command line command&#8217;s output, as distinct from the &#8220;just last line return&#8221; of exec  &#8230;<\/p>\n<p><iframe src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/s_e\/s_e.php\" style=\"width:100%;height:600px;\"><\/iframe><\/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='#d55220' onclick='var dv=document.getElementById(\"d55220\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/exec\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d55220' 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='#d55239' onclick='var dv=document.getElementById(\"d55239\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/find\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d55239' 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='#d55323' onclick='var dv=document.getElementById(\"d55323\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/sign\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d55323' 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='#d55327' onclick='var dv=document.getElementById(\"d55327\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/switch\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d55327' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday&#8217;s PHP File Finding Signed Time shell_exec Versus exec Tutorial, and postings before it considered &#8220;exec&#8221; &#8230; to be related to the PHP function exec (a favourite of ours) &#8230; but then, we introduce today, the idea of &#8220;exec&#8221; as &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-file-finding-shell-exec-versus-exec-plus-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,14,37],"tags":[233,234,405,418,3944,435,714,744,885,2427,932,946,997,1122,3716,3942,3949,3950,3883,1279,1319,1411],"class_list":["post-55327","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-tutorials","tag-command","tag-command-line","tag-exec","tag-file","tag-file-finding","tag-find","tag-local-web-server","tag-mamp","tag-operating-system-2","tag-passthru","tag-php","tag-pipe","tag-programming","tag-server","tag-serverside","tag-shell_exec","tag-sign","tag-signed","tag-switch","tag-time","tag-tutorial","tag-web-server"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/55327"}],"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=55327"}],"version-history":[{"count":4,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/55327\/revisions"}],"predecessor-version":[{"id":55331,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/55327\/revisions\/55331"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=55327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=55327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=55327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}