{"id":541651,"date":"2023-01-20T20:00:11","date_gmt":"2023-01-20T17:00:11","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/everything-you-need-to-know-4\/"},"modified":"2023-01-20T20:00:11","modified_gmt":"2023-01-20T17:00:11","slug":"everything-you-need-to-know-4","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/everything-you-need-to-know-4\/","title":{"rendered":"#Everything You Need to Know"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2dfb8a16059\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2dfb8a16059\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/everything-you-need-to-know-4\/#%E2%80%9CEverything_You_Need_to_Know%E2%80%9D\" >&#8220;Everything You Need to Know&#8221;<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/everything-you-need-to-know-4\/#What_Is_the_rm_Command_in_Linux\" >What Is the rm Command in Linux?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/everything-you-need-to-know-4\/#How_to_Delete_Files_With_rm\" >How to Delete Files With rm<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/everything-you-need-to-know-4\/#Using_Wildcards_With_rm\" >Using Wildcards With rm<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/everything-you-need-to-know-4\/#Using_rm_Interactively\" >Using rm Interactively<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/buradabiliyorum.com\/en\/everything-you-need-to-know-4\/#Using_the_rm_Force_Option\" >Using the rm Force Option<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/buradabiliyorum.com\/en\/everything-you-need-to-know-4\/#Deleting_Directories_With_rm\" >Deleting Directories With rm<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/buradabiliyorum.com\/en\/everything-you-need-to-know-4\/#Avoiding_Mistakes_When_Using_rm\" >Avoiding Mistakes When Using rm<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/buradabiliyorum.com\/en\/everything-you-need-to-know-4\/#What_PPE\" >What PPE?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E2%80%9CEverything_You_Need_to_Know%E2%80%9D\"><\/span>&#8220;Everything You Need to Know&#8221;<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<div>\n<figure style=\"width: 1200px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage size-full wp-image-791996\" data-pagespeed-no-defer=\"\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/03\/shutterstock_321627716.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Linux laptop showing a bash prompt\" width=\"1200\" height=\"675\"\/><figcaption class=\"wp-caption-text\"><span class=\"type:primaryImage imagecredit\"><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.shutterstock.com\/image-vector\/linux-interface-screen-notebook-world-map-321627716\">fatmawati achmad zaenuri\/Shutterstock.com<\/a><\/span><\/figcaption><\/figure>\n<p>The rm command lets you delete a file or directory passing its name: &#8220;rm filename&#8221; or &#8220;rm -d directory.&#8221; You can include a directory path, too. If there are files in the directory, use the -r option &#8220;rm -r directory&#8221; to delete files and folders recursively.<\/p>\n<p>The Linux <code>rm<\/code> command deletes files and directories. To use this tool safely, you need to be certain what\u2019s going to h<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">app<\/a>en when you hit \u201cEnter.\u201d Here\u2019s what you need to know.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"What_Is_the_rm_Command_in_Linux\"><\/span>What Is the rm Command in Linux?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The Linux\u00a0<code>rm<\/code> command is primarily for deleting files. It\u2019s one that most people encounter soon after they start using Linux. Just by virtue of being a <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.howtogeek.com\/757339\/10-basic-linux-commands-for-beginners\/\">newcomer to Linux, you\u2019re likely to make mistakes. You\u2019ll create or copy files by accident, or with the wrong name, or to the wrong place. It\u2019s all part of the learning curve of the command line. The clean-up operations for such mistakes involve <code>rm<\/code> .<\/p>\n<p>The <code>rm<\/code> command can delete files, groups of files, directories, or complete directory trees. That\u2019s why it must be used with caution. Using <code>rm<\/code> isn\u2019t difficult, but the penalty for failure is high.<\/p>\n<p>When a file is deleted with <code>rm<\/code> , it is gone. It isn\u2019t moved to the trash. It is obliterated im<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/social-mediaa\/\" data-internallinksmanager029f6b8e52c=\"1\" title=\"Social Media\" target=\"_blank\" rel=\"noopener\">media<\/a>tely. That doesn\u2019t mean you should avoid using <code>rm<\/code> . But to use it safely, you need to be aware of what it can do, and ensure you\u2019re using it properly.<\/p>\n<p>Some tools are more dangerous than others, and far less forgiving of mistakes. That\u2019s why there\u2019s never been a movie called <em>The Texas Wrench Massacre<\/em>. <code>rm<\/code> isn\u2019t a wrench, it\u2019s definitely a chainsaw.<\/p>\n<p>People use chainsaws all day everyday, and as long as they use one responsibly and mindfully, they\u2019re fine. It\u2019s the same deal with <code>rm<\/code> . When you pull <code>rm<\/code> out of your tool bag, you ought to slow down and check, then double-check, your command line.<\/p>\n<p>The <code>rm<\/code> command is an executable, it\u2019s not part of the shell. So, although we\u2019re using Bash here, it\u2019s the standard Linux <code>rm<\/code>, not a special Bash <code>rm<\/code>.<\/p>\n<p><strong>RELATED:<\/strong> <strong><em>Command Lines: Why Do People Still Bother With Them?<\/em><\/strong><\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"How_to_Delete_Files_With_rm\"><\/span>How to Delete Files With rm<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The simplest way to use <code>rm<\/code> is to provide the name of a file you want to delete.<\/p>\n<pre>rm config.gc<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-858820\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/01\/1.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Deleting a single file by passing its filename to rm\" width=\"644\" height=\"75\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You\u2019re silently returned to the command line. <code>rm<\/code> adopts the classic, close-lipped Linux stance that if it doesn\u2019t complain about anything, you can assume it did what you asked. Providing a filename like this causes <code>rm<\/code> to look for the file in the current working directory.<\/p>\n<p>You can provide multiple file names on the command line. You can also provide a directory path if a file you want to delete isn\u2019t in the current directory.<\/p>\n<pre>rm memlog.sh \/home\/dave\/dev-archive\/config.gc<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-858822\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/01\/2.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Deleting two files by passing their filename and directory path to rm\" width=\"644\" height=\"95\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Again, nothing is reported if <code>rm<\/code> manages to delete the specified files.<\/p>\n<p><strong>RELATED:<\/strong> <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.howtogeek.com\/412055\/37-important-linux-commands-you-should-know\/\"><strong><em>37 Important Linux Commands You Should Know<\/em><\/strong><\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Using_Wildcards_With_rm\"><\/span>Using Wildcards With rm<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Wildcards allow you to specify groups or collections of files without having to list the individual files on the command line.<\/p>\n<p>The asterisk \u201c<code>*<\/code>\u201d represents any sequence of characters, including none. The question mark \u201c<code>?<\/code>\u201d represents any single character.<\/p>\n<p>To check that your wildcards are going to match what you expect them to, and nothing more, you can use them with ls before you use them with rm.<\/p>\n<p>To delete all of the PNG files in the current directory, use \u201c*.png.\u201d This means any sequence of characters followed by \u201c.png\u201d will be matched. When the files have been deleted, we can use <code>ls<\/code>\u00a0to verify that they\u2019ve gone.<\/p>\n<pre>ls *.png<\/pre>\n<pre>rm *.png<\/pre>\n<pre>ls *.png<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-858830\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/01\/3.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Using the asterisk wildcard to delete all files with file extension of PNG\" width=\"644\" height=\"170\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>On our test computer, we\u2019ve got two files in the current directory with names starting with \u201cconfig.\u201d<\/p>\n<p>We\u2019re able to delete both of these by using the asterisk wildcard.\u00a0It matches both files because <code>rm<\/code> is looking for filenames that start with \u201cconfig\u201d, followed by any sequence of characters. On one file, that sequence of characters is \u201c.sl3\u201d, the filename extension. The other filename has no characters after \u201cconfig\u201d, but because the asterisk matches any characters or <em>no characters<\/em>, it matches that filename too.<\/p>\n<pre>ls config*<\/pre>\n<pre>rm config*<\/pre>\n<pre>ls config*<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-858831\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/01\/4.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Using the asterisk wildcard to delete two files, one with and one without, a file extension\" width=\"644\" height=\"150\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You can use the question mark in pairs. This will delete files that have file extensions of two characters exactly.<\/p>\n<pre>ls *.??<\/pre>\n<pre>rm *.??<\/pre>\n<pre>ls *.??<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-858833\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/01\/5.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Using two question mark wildcards to delete files that have file extensions of exactly two characters\" width=\"644\" height=\"150\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p><strong>RELATED:<\/strong> <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.howtogeek.com\/439199\/15-special-characters-you-need-to-know-for-bash\/\"><strong><em>15 Special Characters You Need to Know for Bash<\/em><\/strong><\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Using_rm_Interactively\"><\/span>Using rm Interactively<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A safe way to use <code>rm<\/code> is to force it to ask for confirmation before it deletes each file. The <code>-i<\/code> (interactive) option lets you do this. When you add this option to your command line, <code>rm<\/code> will prompt you before each deletion, giving you a chance to step over actions you hadn\u2019t intended.<\/p>\n<p>We\u2019ll use the <code>-i<\/code> (interactive) option in this command. It tries to delete all files with a single character file extension.<\/p>\n<pre>rm -i *.?<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-858834\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/01\/6.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Using rm interactively so that it prompts before each deletion\" width=\"644\" height=\"315\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Each matching file is presented in turn. If you answer \u201cy\u201d or \u201cY\u201d the file is deleted. If you answer \u201cn\u201d, the file is retained. In fact, if you answer with anything other than \u201cy\u201d or \u201cy\u201d, the file is retained. You can just hit \u201cEnter\u201d and the file is retained.<\/p>\n<p>You can quickly work through your list of files, deleting or skipping over files to cherry-pick the ones you want to remove. As we\u2019ll see you can use the <code>i-<\/code> (interactive) option with other <code>rm<\/code> options.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Using_the_rm_Force_Option\"><\/span><a rel=\"nofollow noopener\" target=\"_blank\" name=\"autotoc_anchor_4\">Using the rm Force Option<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you try to delete a file that is read-only, <code>rm<\/code> prompts you for confirmation before it deletes the file. That\u2019s a good safety net, but one that could become tedious if you have a lot of files to delete.<\/p>\n<pre>rm geonames.sl3<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-858836\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/01\/7.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"rm prompting the user to confirm they want to delete a read-only file\" width=\"644\" height=\"95\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>The <code>-f<\/code> (force) option instructs <code>rm<\/code> to never prompt. You\u2019re telling it \u201cYes, delete all files that you would normally prompt me about.\u201d It also prevents <code>rm<\/code> from complaining about non-existent files.<\/p>\n<pre>rm -f geonames.sl3<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-858842\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/01\/7a-1.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Using the -f (force) option to prevent rm from prompting about deletions\" width=\"644\" height=\"75\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>The <code>-f<\/code> (force) option is often used when you\u2019re deleting a nested set of files and directories.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Deleting_Directories_With_rm\"><\/span><a rel=\"nofollow noopener\" target=\"_blank\" name=\"autotoc_anchor_5\">Deleting Directories With rm<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <code>rm<\/code> command can optionally remove directories too, along with the files they contain. This is similar to the <code>rmdir<\/code> command, but <code>rmdir<\/code> cannot delete directories with files in them. It only deletes empty directories. The <code>rm<\/code> command can easily delete directories that contain files and other directories.<\/p>\n<p>Deleting a directory is similar to deleting a file. We provide the name of the directory on the command line. We need to include the <code>-d<\/code> (directory) option. Like we did when we were deleting files, we can provide the name of several directories. We can provide a path to directory that is not in the current working directory.<\/p>\n<pre>rm -d old-projects<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-858843\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/01\/8.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Using the -d (directory) option to delete a directory\" width=\"644\" height=\"75\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>If the directory contains files, this will fail.<\/p>\n<p>To delete a directory <em>and<\/em> its contents, use the <code>-r<\/code> (recursive) flag. This deletes the directory, its files, and any nested directories it contains.<\/p>\n<pre>rm -d archive<\/pre>\n<pre>rm -r archive<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-858848\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/01\/9.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Using the -r (recursive) option to delete a directory and its files\" width=\"644\" height=\"110\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>The second command succeeds.<\/p>\n<p>To switch <code>rm<\/code> into full-on chainsaw mode, we can combine the <code>-r<\/code> (recursive) and <code>-f<\/code> (force) options. This tells <code>rm<\/code> to recursively delete all files and directories in a directory tree, even if they are read-only, and without ever prompting us.<\/p>\n<p>On our test computer, we\u2019ve got a directory called \u201cmigrated code.\u201d It contains files and another directory called \u201c6502.\u201d The \u201c6502\u201d directory also contains files and another directory called \u201cASM.\u201d There\u2019s files in that directory, too. Some of the files are read-only.<\/p>\n<p>We\u2019ll also include the <code>-v<\/code> (verbose) command so that <code>rm<\/code> tells us what it is doing.<\/p>\n<pre>rm -rfv migrated-code<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-858854\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/01\/10.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Using the -rfv flags to cause rm to remove files and directories, even read-only files, without prompting\" width=\"644\" height=\"55\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>In the output we can see that the files are removed and, when they\u2019re empty, the directories are removed too.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-858865\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/01\/11.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"The output of the -rfv flags showing the files that are deleted and the directories that are deleted once they are empty\" width=\"644\" height=\"270\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Avoiding_Mistakes_When_Using_rm\"><\/span><a rel=\"nofollow noopener\" target=\"_blank\" name=\"autotoc_anchor_6\">Avoiding Mistakes When Using rm<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Spaces and other weird characters in filenames can present problems. Filenames that start with a hyphen \u201c<code>-<\/code>\u201d for example, can be mistaken for command line options. If we have a file called \u201c-contributors.txt\u201d, <code>rm<\/code> will try to process the name as a sequence of command line options.<\/p>\n<p>Because <code>rm<\/code> doesn\u2019t have an option called \u201c<code>-c<\/code>\u201c, the command line parsing fails and the file isn\u2019t deleted.\u00a0To delete the file you need to precede it with \u201c.\/\u201d to provide a path to it.<\/p>\n<pre>rm -contributors.txt<\/pre>\n<pre>rm .\/-contributors.txt<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-858867\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/01\/12.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Using &quot;.\/&quot; to work around the problem of deleting a file whose first character is a hyphen\" width=\"644\" height=\"150\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Spaces in filenames are also problematic. Either quote the entire filename, or use tab completion to insert the name of the file onto the command line for you, escaping the spaces as it does so. If you don\u2019t use either of these options, <code>rm<\/code> will treat each portion of the filename as an individual file.<\/p>\n<p>Here, we\u2019ve got two files, one called \u201cbackup\u201d and one called \u201cbackup to delete.\u201d We can demonstrate the problem with these file names, using <code>ls<\/code>. If we try to use <code>ls<\/code> on the \u201cbackup to delete\u201d file and we don\u2019t escape or quote the file name, the command fails.<\/p>\n<pre>ls -hl backup to delete<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-858868\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/01\/13.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Trying to use ls on a file with spaces in its name, without quoting the string or escaping the spaces\" width=\"644\" height=\"130\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p><code>ls<\/code> complains that it can\u2019t find files called \u201cto\u201d or \u201cdelete\u201d, but it does find a file called \u201cbackup.\u201d That\u2019s what <code>rm<\/code> will do, too. It\u2019ll complain about two missing files, and it\u2019ll then delete the file called \u201cbackup\u201d, which isn\u2019t what we wanted.<\/p>\n<pre>rm backup to delete<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-858869\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/01\/14.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Trying to use rm on a file with spaces in its name, without quoting the string or escaping the spaces\" width=\"644\" height=\"110\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p><code>rm<\/code> thinks it is working with three files, \u201cbackup\u201d, \u201cto\u201d, and \u201cdelete.\u201d It complains that it can\u2019t find \u201cto\u201d and \u201cdelete\u201d, but it finds and silently deletes \u201cbackup.\u201d<\/p>\n<p>Quoting the filename allows <code>rm<\/code> to delete the correct file.<\/p>\n<pre>rm 'backup to delete'<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-858870\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/01\/15.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Using rm with a quoted filename to overcome the problem of spaces in the filename\" width=\"644\" height=\"75\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You could also escape the spaces with backslashes \u201c<code>\\<\/code>\u201c, like this:<\/p>\n<pre>rm backup\\ to\\ delete<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-858871\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2023\/01\/16.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Using rm with a filename with escaped spaces to overcome the problem of spaces in the filename\" width=\"644\" height=\"75\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>If you <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.howtogeek.com\/195207\/use-tab-completion-to-type-commands-faster-on-any-operating-system\/\">use tab completion to enter your filenames, they\u2019ll be automatically escaped, if required.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"What_PPE\"><\/span>What PPE?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Unlike real-world chainsaws, there\u2019s no personal protective equipment you can use with <code>rm<\/code>.<\/p>\n<p>What you can do, is <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.howtogeek.com\/788955\/how-to-validate-the-syntax-of-a-linux-bash-script-before-running-it\/\">check your syntax with <code>ls<\/code> before you try it with <code>rm<\/code>, and use the interactive mode so that you get to decide what gets deleted.<\/p>\n<p>Other than that, it\u2019s practice until you feel comfortable and confident. The safest way to do that is to copy a bunch of sacrificial files to a directory and practice on those.<\/p>\n<p><strong>RELATED:<\/strong> <strong><em>Delete Files Older Than x Days on Linux<\/em><\/strong><\/p>\n<\/div>\n<p><script>\n setTimeout(function(){\n  !function(f,b,e,v,n,t,s)\n  {if(f.fbq)return;n=f.fbq=function(){n.callMethod?\n  n.callMethod.apply(n,arguments):n.queue.push(arguments)};\n  if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';\n  n.queue=[];t=b.createElement(e);t.async=!0;\n  t.src=v;s=b.getElementsByTagName(e)[0];\n  s.parentNode.insertBefore(t,s) } (window, document,'script',\n  'https:\/\/connect.facebook.net\/en_US\/fbevents.js');\n   fbq('init', '335401813750447');\n   fbq('track', 'PageView');\n  },3000);\n<\/script><\/p>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.howtogeek.com\/858815\/linux-rm-command\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;Everything You Need to Know&#8221; fatmawati achmad zaenuri\/Shutterstock.com The rm command lets you delete a file or directory passing its name: &#8220;rm filename&#8221; or &#8220;rm -d directory.&#8221; You can include a directory path, too. If there are files in the directory, use the -r option &#8220;rm -r directory&#8221; to delete files and folders recursively. The&#8230;<\/p>\n","protected":false},"author":1,"featured_media":541652,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/03\/shutterstock_321627716.png?height=200p&trim=2,2,2,2","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-541651","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/541651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=541651"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/541651\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/541652"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=541651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=541651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=541651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}