{"id":404,"date":"2012-09-23T22:11:10","date_gmt":"2012-09-24T05:11:10","guid":{"rendered":"http:\/\/www.hongyu.org\/wordpress\/?p=404"},"modified":"2012-09-23T22:41:51","modified_gmt":"2012-09-24T05:41:51","slug":"a-safe-program-to-replace-unix-command-rm","status":"publish","type":"post","link":"https:\/\/www.hongyu.org\/wordpress\/?p=404","title":{"rendered":"A safe program to replace unix command &#8216;rm&#8217;"},"content":{"rendered":"<p>[sourcecode]<br \/>\n#!\/usr\/bin\/perl -w<\/p>\n<p>## A safer program to replace unix command &quot;rm&quot;<br \/>\n## Author: Hongyu Zhang<\/p>\n<p>if($#ARGV &lt; 0) {<br \/>\n    die(&quot;Usage:  $0 filename\\n&quot;);<br \/>\n}<\/p>\n<p>$dir = `echo ~\/dumpster`;<br \/>\nchomp $dir;<br \/>\nmkdir $dir unless(-d $dir);<\/p>\n<p>for($i=0; $i&lt;=$#ARGV; $i++) {<br \/>\n    croak(&quot;Directory $ARGV[$i] not existed&quot;) unless(-e $ARGV[$i]);<br \/>\n    my @arr = split \/\\\/\/, $ARGV[$i];<br \/>\n    if(-e &quot;$dir\/$arr[$#arr]&quot;) {<br \/>\n        $command = &quot;rm -rf $dir\/$arr[$#arr]&quot;;<br \/>\n        system(&quot;$command&quot;);<br \/>\n        croak(&quot;error running command: $command&quot;) if($?);<br \/>\n    }<\/p>\n<p>    $command = &quot;mv -fv $ARGV[$i] $dir&quot;;<br \/>\n    system(&quot;$command&quot;);<br \/>\n    croak(&quot;error running command: $command&quot;) if($?);<br \/>\n}<br \/>\n[\/sourcecode]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[sourcecode] #!\/usr\/bin\/perl -w ## A safer program to replace unix command &quot;rm&quot; ## Author: Hongyu Zhang if($#ARGV &lt; 0) { die(&quot;Usage: $0 filename\\n&quot;); } $dir = `echo ~\/dumpster`; chomp $dir; mkdir $dir unless(-d $dir); for($i=0; $i&lt;=$#ARGV; $i++) { croak(&quot;Directory $ARGV[$i] not existed&quot;) unless(-e $ARGV[$i]); my @arr = split \/\\\/\/, $ARGV[$i]; if(-e &quot;$dir\/$arr[$#arr]&quot;) { $command = &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.hongyu.org\/wordpress\/?p=404\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;A safe program to replace unix command &#8216;rm&#8217;&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/404"}],"collection":[{"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=404"}],"version-history":[{"count":3,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/404\/revisions"}],"predecessor-version":[{"id":409,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/404\/revisions\/409"}],"wp:attachment":[{"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}