{"id":6191,"date":"2022-07-13T11:24:45","date_gmt":"2022-07-13T11:24:45","guid":{"rendered":"https:\/\/really.zonky.org\/?p=6191"},"modified":"2022-07-13T11:24:47","modified_gmt":"2022-07-13T11:24:47","slug":"shell-alias-may-be-dangerous","status":"publish","type":"post","link":"https:\/\/really.zonky.org\/?p=6191","title":{"rendered":"Shell Alias May Be Dangerous"},"content":{"rendered":"\n<p>Not all shell aliases of course, but <em>some<\/em>. I&#8217;ve just seen a youtube video that suggested creating a shell alias to run <em>rmtrash<\/em> when <em>rm<\/em> is invoked :-<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>alias rm='rmtrash'<\/code><\/pre>\n\n\n\n<p>Seems sensible enough doesn&#8217;t it? This is in fact the classic example of how dangerous shell aliases <em>can<\/em> be, although the classic example was to turn on &#8220;-i&#8221; :-<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>alias rm='rm -i'<\/code><\/pre>\n\n\n\n<p>The problem is that you get used to &#8220;rm&#8221; being safe &#8211; either it asks before it removes files (&#8220;-i&#8221;) or it safely preserves what is deleted in the Trash folder. But what happens when the alias doesn&#8217;t get created? Perhaps you have a broken <em>.zshrc<\/em> and Zsh stops interpreting before the alias is declared. Or you&#8217;ve logged on to a remote server that doesn&#8217;t have your <em>.zshrc<\/em> installed as yet?<\/p>\n\n\n\n<p>All of a sudden you are running the unadulterated <em>rm<\/em> command &#8211; deleting files without being asked, or preserving them in the Trash folder. See the danger now?<\/p>\n\n\n\n<p>It is better not to replace standard commands but create a new &#8216;command&#8217; :-<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>alias del=\"rmtrash\"<\/code><\/pre>\n\n\n\n<p>Perhaps you regard this as being excessively risk averse &#8211; fair enough. But just don&#8217;t say you weren&#8217;t warned &#8211; and I&#8217;ve encountered missing aliases every year over the last 30-odd years I&#8217;ve been using Linux and Unix. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"695\" height=\"463\" src=\"https:\/\/i0.wp.com\/really.zonky.org\/wp-content\/uploads\/2014-03-27-The-Bare-Family-1.jpg?resize=695%2C463&#038;ssl=1\" alt=\"\" class=\"wp-image-5792\" srcset=\"https:\/\/i0.wp.com\/really.zonky.org\/wp-content\/uploads\/2014-03-27-The-Bare-Family-1.jpg?resize=1024%2C682&amp;ssl=1 1024w, https:\/\/i0.wp.com\/really.zonky.org\/wp-content\/uploads\/2014-03-27-The-Bare-Family-1.jpg?resize=300%2C200&amp;ssl=1 300w, https:\/\/i0.wp.com\/really.zonky.org\/wp-content\/uploads\/2014-03-27-The-Bare-Family-1.jpg?resize=768%2C512&amp;ssl=1 768w, https:\/\/i0.wp.com\/really.zonky.org\/wp-content\/uploads\/2014-03-27-The-Bare-Family-1.jpg?w=1280&amp;ssl=1 1280w\" sizes=\"auto, (max-width: 695px) 100vw, 695px\" \/><figcaption>The Bare Family<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Not all shell aliases of course, but some. I&#8217;ve just seen a youtube video that suggested creating a shell alias to run rmtrash when rm is invoked :- Seems sensible enough doesn&#8217;t it? This is in fact the classic example of how dangerous shell aliases can be, although the classic example was to turn on <a href='https:\/\/really.zonky.org\/?p=6191' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false,"_share_on_mastodon":"1"},"categories":[4,209],"tags":[2114,1793,43,1287,2113,2115,2116],"class_list":["post-6191","post","type-post","status-publish","format-standard","hentry","category-it","category-linux-it","tag-alias","tag-cli","tag-linux","tag-risk","tag-rm","tag-rmtrash","tag-safety","category-4-id","category-209-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"share_on_mastodon":{"url":"https:\/\/mstdn.social\/@grumpygrimnir\/108639780089146971","error":""},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1f2KI-1BR","_links":{"self":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/6191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6191"}],"version-history":[{"count":1,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/6191\/revisions"}],"predecessor-version":[{"id":6192,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/6191\/revisions\/6192"}],"wp:attachment":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}