<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>linux rm command &#8211; TECH POINT MAGAZINE</title>
	<atom:link href="https://techpointmag.com/tag/linux-rm-command/feed/" rel="self" type="application/rss+xml" />
	<link>https://techpointmag.com</link>
	<description>-Beyond Technology-</description>
	<lastBuildDate>Thu, 23 Feb 2023 20:42:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.5</generator>

<image>
	<url>https://techpointmag.com/wp-content/uploads/2019/06/cropped-tech-point-logo@2x-3-32x32.png</url>
	<title>linux rm command &#8211; TECH POINT MAGAZINE</title>
	<link>https://techpointmag.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">141627558</site>	<item>
		<title>How to delete files on Linux using the rm command</title>
		<link>https://techpointmag.com/how-to-delete-files-on-linux-using-the-rm-command/</link>
		
		<dc:creator><![CDATA[Humphrey Mpairwe]]></dc:creator>
		<pubDate>Thu, 23 Feb 2023 20:42:13 +0000</pubDate>
				<category><![CDATA[Guides]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Picks]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[delete files on linux]]></category>
		<category><![CDATA[linux rm command]]></category>
		<category><![CDATA[rm command]]></category>
		<guid isPermaLink="false">https://techpointmag.com/?p=16238</guid>

					<description><![CDATA[All operating systems have the option of deleting files easily. If you&#8217;re a command line kind of person, you can delete files on Linux using the rm command which permanently removes file by default. Unlike other file deletion tools on desktop operating systems, once you use the rm command on Linux, you will not be [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>All operating systems have the option of deleting files easily. If you&#8217;re a command line kind of person, you can delete files on Linux using the rm command which permanently removes file by default. Unlike other file deletion tools on desktop operating systems, once you use the rm command on Linux, you will not be able to receiver the deleted files.</p>



<p>By structure, the <code>rm</code> command follows a strict syntax when deleting files on Linux, and this includes checking whether you are deleting a single file or a whole directory. On usage, the <code>rm</code> command will remove files without prompting you for any action, and you can easily identify whether you&#8217;re about to delete a file or directory by viewing the first long listing identifier.</p>



<p>For example, when you list files with the command below.</p>



<p><code>$ ls</code></p>



<p>Your output will be similar to the following.</p>



<pre class="wp-block-preformatted">total 32                                                                        
drwxr-xr-x 2 sysadmin sysadmin 4096 Feb  8  2021 Desktop                        
drwxr-xr-x 4 sysadmin sysadmin 4096 Feb  8  2021 Documents                      
drwxr-xr-x 2 sysadmin sysadmin 4096 Feb  8  2021 Downloads                      
drwxr-xr-x 2 sysadmin sysadmin 4096 Feb  8  2021 Music                          
drwxr-xr-x 2 sysadmin sysadmin 4096 Feb  8  2021 Pictures                       
drwxr-xr-x 2 sysadmin sysadmin 4096 Feb  8  2021 Public                         
drwxr-xr-x 2 sysadmin sysadmin 4096 Feb  8  2021 Templates                      
drwxr-xr-x 2 sysadmin sysadmin 4096 Feb  8  2021 Videos                         
-rw-rw-r-- 1 sysadmin sysadmin    0 Feb 23 19:37 techpointmag.com </pre>



<p>As per the above example, <code>techpointmag.com</code> is the only file because it starts with the identifier <code>-</code> instead of <code>d</code> which starts for directory. Hence, when you delete the file using the <code>rm</code> command, it is permanently deleted with no error. But if you attempt to delete a directory, you are presented an error similar to the one below.</p>



<pre class="wp-block-preformatted">rm: cannot remove 'Desktop': Is a directory</pre>



<p>So, by usage, you can delete files on linux using the <code>rm</code> command using the syntax below.</p>



<p><code>$ rm -[option] &lt;file or directory&gt;</code></p>



<p>The following are the options accepted by the <code>rm</code> command:</p>



<figure class="wp-block-table"><table><thead><tr><th>Option</th><th>Description</th></tr></thead><tbody><tr><td><code>-i</code></td><td>Interactive deletion. When used the <code>rm</code> command will ask for user confirmation before deleting a file or directory.</td></tr><tr><td><code>-r</code></td><td>Recursive deletion. When used, the <code>rm</code> command will delete a directory and any sub-directories under it.</td></tr><tr><td><code>-d</code></td><td>Remove empty directories that contain Zero files or subdirectories.</td></tr><tr><td><code>-v</code></td><td>Verbose. When uses, the <code>rm</code> command will output each and every file being deleted.</td></tr></tbody></table></figure>



<p>By default, the <code>rm</code> command runs in forced (<code>f</code>)mode and does not give require any confirmation prompts unless you define interactive deletion <code>i</code>. In alliance with the <code>rmdir</code> command, you can safely delete files and directories on Linux as explained below.</p>



<h2 class="wp-block-heading">Delete a single File on Linux using the <code>rm </code>command</h2>



<p>To delete a single file on Linux using the rm command, follow the syntax below.</p>



<pre class="wp-block-preformatted">$ rm &lt;file name&gt;</pre>



<p>Example:</p>



<pre class="wp-block-preformatted"><code>$ rm techpointmag.com</code></pre>



<p>The above command removes the file techpointmag.com if its present in your current directory. For safe deletion, we don&#8217;t recommend using a path since you may delete valuable information by mistake, but in any case, delete a single file from a path as below.</p>



<pre class="wp-block-preformatted">$ rm ~/techpointmag.com</pre>



<p>The above command deletes the file <code>techpointmag.com</code> from your home directory. If the file does not exist, the command returns an error as below.</p>



<pre class="wp-block-preformatted">$ rm: /home/example/techpointmag.com: No such file or directory</pre>



<h2 class="wp-block-heading">Delete multiple files on Linux using the <code>rm</code> command</h2>



<p>To delete multiple files on Linux using the rm command, you must use wildcard expressions which include <code>?</code> that represents 1 character or more, <code>*</code> that represents all, and <code>[]</code> that accepts a range. By usage, you must follow the syntax below.</p>



<pre class="wp-block-preformatted">$ rm &lt;expression&gt;</pre>



<p><strong>Example</strong></p>



<pre class="wp-block-preformatted">$ rm *</pre>



<p>The above command removes all files in your current directory as the following command can remove files with exactly 3 characters.</p>



<pre class="wp-block-preformatted">$ rm ???</pre>



<p>To provide a range, you must specify it in the curl brackets. For example, the following command removes the files named <code>hello</code> and <code>hullo</code> from your current directory.</p>



<pre class="wp-block-preformatted">$ rm h[eua]llo</pre>



<p>The files <code>hello</code>, <code>hullo</code> and <code>hallo</code> are all matched for deletion if they exist in your directory.</p>



<p>Delete a directory on Linux using the rm command</p>



<p>Unlike files, to delete a directory on Linux using the <code>rm</code> command, you must specify an option as illustrated earlier in this article, and the command follows the syntax below.</p>



<pre class="wp-block-preformatted">$ rm -r &lt;directory&gt;</pre>



<p>Alternatively, the <code>rmdir</code> works straight out of the box with a much easier syntax as below.</p>



<pre class="wp-block-preformatted">$ rmdir &lt;directory&gt;</pre>



<p><strong>Example:</strong></p>



<pre class="wp-block-preformatted">$ rm -r Documents</pre>



<p>OR</p>



<pre class="wp-block-preformatted">$ rmdir Documents</pre>



<p>Either of the above commands deletes the <code>Documents</code> directory if it exists.</p>



<h2 class="wp-block-heading">Delete multiple directories on Linux using the <code>rm</code> command</h2>



<p>Just like deleting multiple files, to delete multiple directories on Linux using the <code>rm</code> command, you must supply a wildcard expression to follow. This is useful when deleting many directories you can&#8217;t mark individually. To achieve this, follow the syntax below.</p>



<pre class="wp-block-preformatted"><code>$ rm -r &lt;wildcard-expression&gt;</code></pre>



<p><strong>Example</strong></p>



<pre class="wp-block-preformatted"><code>$ rm -r *</code></pre>



<p>The above command deletes all directories and files in your current working directory. The <code>*</code> expression marks all files and directories for deletion, to limit the loss of important files, simply supply a range as below.</p>



<pre class="wp-block-preformatted"><code>$ rm -r Do[cw]ments</code></pre>



<p>The above command will match the directory <code>Documents</code> and <code>Dowments</code> for deletion while the following will match any directory with exactly 9 characters.</p>



<pre class="wp-block-preformatted"><code>$ rm -r ?????????</code></pre>



<p>Again, the <code>Documents</code> directory and any other with 9 characters matches for deletion.</p>



<h2 class="wp-block-heading">Control the <code>rm</code> command on Linux</h2>



<p>As explained in the above examples, the <code>rm</code> command is final, and deletes matched data permanently. So, how about controlling it to save your valuable data that you may never have intended to delete? Well, here is how you can achieve that with the <code>i</code> – Interactive option.</p>



<p><strong>Syntax</strong></p>



<pre class="wp-block-preformatted"><code>$ rm -i&lt;any other option&gt; &lt;file or directory name&gt;</code></pre>



<p><strong>Example:</strong></p>



<pre class="wp-block-preformatted"><code>$ rm -ir *</code></pre>



<p>The above command will prompt you to accept the deletion of all files and directories one by one as below.</p>



<pre class="wp-block-preformatted">rm: remove directory 'Desk'? yes
rm: remove directory 'hello'? no
rm: remove directory 'techpointmag.com'? no</pre>



<p>You must reply either <code>yes</code> or <code>no</code> to each file or directory deletion. When you press enter, it is marked as <code>yes</code> by default.</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>The <code>rm</code> command is a very useful command since it does not keep any temporary files after deletion unlike the recycle bin on Windows. If you found this article useful, please leave us a comment in the section below.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">16238</post-id>	</item>
	</channel>
</rss>
