<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged blocks</title>
<link>https://coderlegion.com/tag/blocks</link>
<description>Powered by Question2Answer</description>
<item>
<title>How Files Are Stored, Deleted, and Copied Inside Your Computer</title>
<link>https://coderlegion.com/14656/how-files-are-stored-deleted-and-copied-inside-your-computer</link>
<description>
&lt;p&gt;&lt;img src=&quot;https://blog.ratnesh-maurya.com/images/blog/How-Files-Are-Stored-Deleted-and-Copied-Inside-Your-Computer.jpg&quot; alt=&quot;How Files Are Stored, Deleted, and Copied Inside Your Computer&quot;&gt;&lt;/p&gt;&lt;h1 id=&quot;how-files-are-stored-deleted-and-copied-inside-your-computer&quot;&gt;How Files Are Stored, Deleted, and Copied Inside Your Computer&lt;/h1&gt;
&lt;p&gt;Have you ever noticed something interesting?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Deleting a file happens instantly.&lt;/li&gt;
&lt;li&gt;Copying a file takes time.&lt;/li&gt;
&lt;li&gt;Moving a file is sometimes instant and sometimes slow.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Why does this happen?&lt;/p&gt;
&lt;p&gt;If you're new to operating systems and storage internals, this article explains everything in simple terms using real-world analogies, while also giving you a deeper technical understanding of what&amp;rsquo;s happening behind the scenes.&lt;/p&gt;
&lt;p&gt;By the end, you&amp;rsquo;ll understand:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How files are stored on disk&lt;/li&gt;
&lt;li&gt;Why delete is fast&lt;/li&gt;
&lt;li&gt;Why copy takes time&lt;/li&gt;
&lt;li&gt;Whether files are really deleted&lt;/li&gt;
&lt;li&gt;How HDD and SSD behave differently&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&quot;how-files-are-actually-stored-on-disk&quot;&gt;How Files Are Actually Stored on Disk&lt;/h2&gt;
&lt;p&gt;Your computer does not store files the way you see them in folders.&lt;/p&gt;
&lt;p&gt;Internally, storage is divided into:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Data Blocks (or clusters)&lt;/strong&gt; &amp;ndash; These contain the actual bytes of your file.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Metadata&lt;/strong&gt; &amp;ndash; Information about the file:
&lt;ul&gt;
&lt;li&gt;File name&lt;/li&gt;
&lt;li&gt;File size&lt;/li&gt;
&lt;li&gt;Location of data blocks&lt;/li&gt;
&lt;li&gt;Permissions&lt;/li&gt;
&lt;li&gt;Created/modified timestamps&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;A file system (like NTFS, ext4, FAT32) manages this structure.&lt;/p&gt;
&lt;h3 id=&quot;example-file-systems&quot;&gt;Example File Systems&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Windows &amp;rarr; NTFS&lt;/li&gt;
&lt;li&gt;Linux &amp;rarr; ext4&lt;/li&gt;
&lt;li&gt;USB drives &amp;rarr; FAT32&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Each filesystem maintains:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A directory entry (file name)&lt;/li&gt;
&lt;li&gt;A metadata record (inode in Linux, MFT entry in NTFS)&lt;/li&gt;
&lt;li&gt;Pointers to the actual disk blocks&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can think of it like a database that tracks where your file data lives on disk.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;real-life-analogy-a-library&quot;&gt;Real-Life Analogy: A Library&lt;/h2&gt;
&lt;p&gt;Imagine this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;library catalog&lt;/strong&gt; = filesystem metadata&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;books on shelves&lt;/strong&gt; = actual file data&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;shelf location number&lt;/strong&gt; = pointer to disk blocks&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When you open a file:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The system checks the catalog.&lt;/li&gt;
&lt;li&gt;It finds the shelf location.&lt;/li&gt;
&lt;li&gt;It retrieves the book (data blocks).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Now let&amp;rsquo;s see what happens during delete and copy.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;why-deleting-a-file-is-instant&quot;&gt;Why Deleting a File Is Instant&lt;/h2&gt;
&lt;p&gt;When you delete a file, the system usually does &lt;strong&gt;not erase the data immediately&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Instead, it:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Removes the file name from the directory.&lt;/li&gt;
&lt;li&gt;Marks its data blocks as &amp;ldquo;free&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Updates metadata records.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;That&amp;rsquo;s it.&lt;/p&gt;
&lt;p&gt;The actual bytes are still physically on disk &amp;mdash; but the system marks that space as available for reuse.&lt;/p&gt;
&lt;p&gt;Since this is mainly a metadata update, it happens very fast.&lt;/p&gt;
&lt;h3 id=&quot;important-insight&quot;&gt;Important Insight&lt;/h3&gt;
&lt;p&gt;Deleting is like removing the book&amp;rsquo;s entry from the library catalog.&lt;/p&gt;
&lt;p&gt;The book is still on the shelf &amp;mdash; but nobody knows it exists anymore.&lt;/p&gt;
&lt;p&gt;This is why:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;File recovery tools can restore deleted files.&lt;/li&gt;
&lt;li&gt;Secure deletion requires special tools.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&quot;do-files-actually-get-deleted&quot;&gt;Do Files Actually Get Deleted?&lt;/h2&gt;
&lt;p&gt;Short answer: &lt;strong&gt;Not immediately.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;They are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Marked as free space&lt;/li&gt;
&lt;li&gt;Eventually overwritten by new data&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;On SSDs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The operating system sends a &lt;strong&gt;TRIM command&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;The SSD later clears unused blocks internally&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Deletion is logical first, physical later.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;why-copying-a-file-takes-time&quot;&gt;Why Copying a File Takes Time&lt;/h2&gt;
&lt;p&gt;Copying is completely different.&lt;/p&gt;
&lt;p&gt;When copying:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The system reads every block from the source file.&lt;/li&gt;
&lt;li&gt;Loads it into memory (RAM).&lt;/li&gt;
&lt;li&gt;Writes those blocks to a new location.&lt;/li&gt;
&lt;li&gt;Creates new metadata for the copied file.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This process depends on:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Disk speed&lt;/li&gt;
&lt;li&gt;File size&lt;/li&gt;
&lt;li&gt;HDD vs SSD&lt;/li&gt;
&lt;li&gt;CPU and memory performance&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Since the entire file&amp;rsquo;s data must be read and written, copying takes time.&lt;/p&gt;
&lt;h3 id=&quot;example&quot;&gt;Example&lt;/h3&gt;
&lt;p&gt;Copying a 10GB file means:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Reading 10GB&lt;/li&gt;
&lt;li&gt;Writing 10GB&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That&amp;rsquo;s 20GB of total I/O operations.&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s real physical work being done.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;why-moving-files-is-sometimes-instant&quot;&gt;Why Moving Files Is Sometimes Instant&lt;/h2&gt;
&lt;p&gt;This depends on where you move the file.&lt;/p&gt;
&lt;h3 id=&quot;case-1-same-drive-same-filesystem&quot;&gt;Case 1: Same Drive (Same Filesystem)&lt;/h3&gt;
&lt;p&gt;Move = metadata update only.&lt;/p&gt;
&lt;p&gt;The system just:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Updates the directory entry&lt;/li&gt;
&lt;li&gt;Keeps data blocks unchanged&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is very fast.&lt;/p&gt;
&lt;h3 id=&quot;case-2-different-drive&quot;&gt;Case 2: Different Drive&lt;/h3&gt;
&lt;p&gt;Move becomes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Copy the file&lt;/li&gt;
&lt;li&gt;Delete the original&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So it takes time.&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s why:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Moving inside C: is instant&lt;/li&gt;
&lt;li&gt;Moving from C: to D: takes time&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&quot;hdd-vs-ssd-behavior&quot;&gt;HDD vs SSD Behavior&lt;/h2&gt;
&lt;h3 id=&quot;hdd-hard-disk-drive&quot;&gt;HDD (Hard Disk Drive)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Mechanical spinning disk&lt;/li&gt;
&lt;li&gt;Moving read/write head&lt;/li&gt;
&lt;li&gt;Slower seek time&lt;/li&gt;
&lt;li&gt;Sequential reads are faster&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Copying large files can be slower because of mechanical movement.&lt;/p&gt;
&lt;h3 id=&quot;ssd-solid-state-drive&quot;&gt;SSD (Solid State Drive)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;No moving parts&lt;/li&gt;
&lt;li&gt;Much faster random access&lt;/li&gt;
&lt;li&gt;Uses flash memory cells&lt;/li&gt;
&lt;li&gt;Uses TRIM and garbage collection&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Deletion marks blocks unused first. The physical erase happens later internally.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;what-happens-in-the-os-layer&quot;&gt;What Happens in the OS Layer&lt;/h2&gt;
&lt;p&gt;At the system-call level (Linux example):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;delete&lt;/code&gt; &amp;rarr; &lt;code&gt;unlink()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;copy&lt;/code&gt; &amp;rarr; multiple &lt;code&gt;read()&lt;/code&gt; and &lt;code&gt;write()&lt;/code&gt; calls&lt;/li&gt;
&lt;li&gt;&lt;code&gt;move (same filesystem)&lt;/code&gt; &amp;rarr; &lt;code&gt;rename()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;hljs language-bash&quot;&gt;strace &lt;span class=&quot;hljs-built_in&quot;&gt;rm&lt;/span&gt; file.txt

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You'll see something like:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;unlink(&quot;file.txt&quot;)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;That's simply removing the reference to the file.&lt;/p&gt;
&lt;p&gt;Copying involves many &lt;code&gt;read()&lt;/code&gt; and &lt;code&gt;write()&lt;/code&gt; operations, which take time.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;why-deleting-many-files-can-be-slow&quot;&gt;Why Deleting Many Files Can Be Slow&lt;/h2&gt;
&lt;p&gt;Deleting one file is fast.&lt;/p&gt;
&lt;p&gt;Deleting thousands of small files can take time because:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Each file has metadata.&lt;/li&gt;
&lt;li&gt;Directory entries must be updated.&lt;/li&gt;
&lt;li&gt;Journaling systems must commit changes.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Even metadata operations add up when repeated many times.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;secure-deletion&quot;&gt;Secure Deletion&lt;/h2&gt;
&lt;p&gt;Normal delete:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Marks space as free&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Secure delete:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Overwrites data blocks&lt;/li&gt;
&lt;li&gt;Ensures recovery is impossible&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;On SSDs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use drive-level secure erase&lt;/li&gt;
&lt;li&gt;Or enable full-disk encryption&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&quot;key-takeaways&quot;&gt;Key Takeaways&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Delete is fast because it removes metadata, not actual data.&lt;/li&gt;
&lt;li&gt;Copy is slow because it transfers real bytes.&lt;/li&gt;
&lt;li&gt;Move is fast only within the same filesystem.&lt;/li&gt;
&lt;li&gt;Deleted files remain until overwritten.&lt;/li&gt;
&lt;li&gt;SSDs and HDDs behave differently.&lt;/li&gt;
&lt;li&gt;Secure deletion requires special handling.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&quot;what-to-explore-next&quot;&gt;What to explore next&lt;/h2&gt;
&lt;p&gt;File operations look simple from the UI, but under the surface the OS is managing metadata, block allocation, caching, journaling, and hardware coordination.&lt;/p&gt;
&lt;p&gt;If this interested you, here are some rabbit holes worth going down:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;strace&lt;/code&gt; on Linux&lt;/strong&gt; &amp;mdash; run &lt;code&gt;strace rm file.txt&lt;/code&gt; or &lt;code&gt;strace cp src dst&lt;/code&gt; to see the actual system calls involved&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Filesystem internals&lt;/strong&gt; &amp;mdash; look into how ext4 journaling works, or how ZFS and Btrfs use copy-on-write to make snapshots nearly free&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Flash Translation Layer&lt;/strong&gt; &amp;mdash; how SSDs remap logical blocks to physical NAND pages, and why TRIM exists&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data recovery tools&lt;/strong&gt; &amp;mdash; tools like &lt;code&gt;testdisk&lt;/code&gt; and &lt;code&gt;photorec&lt;/code&gt; exploit the fact that &quot;deleted&quot; data is still on disk&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The next time a file deletes instantly, you'll know &amp;mdash; it wasn't magic. It was just a metadata update.&lt;/p&gt;
</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/14656/how-files-are-stored-deleted-and-copied-inside-your-computer</guid>
<pubDate>Thu, 16 Apr 2026 00:35:04 +0000</pubDate>
</item>
</channel>
</rss>