<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Andrew Marlow</title>
    <description>The latest articles on DEV Community by Andrew Marlow (@andrewmarlow).</description>
    <link>https://dev.to/andrewmarlow</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4279364%2Fb4358e88-58ba-46e0-bc82-ca532c8f8dae.png</url>
      <title>DEV Community: Andrew Marlow</title>
      <link>https://dev.to/andrewmarlow</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/andrewmarlow"/>
    <language>en</language>
    <item>
      <title>How to Find Which Physical Disk Is /dev/sda on Linux</title>
      <dc:creator>Andrew Marlow</dc:creator>
      <pubDate>Sat, 05 Dec 2026 11:03:59 +0000</pubDate>
      <link>https://dev.to/andrewmarlow/how-to-find-which-physical-disk-is-devsda-on-linux-4jdd</link>
      <guid>https://dev.to/andrewmarlow/how-to-find-which-physical-disk-is-devsda-on-linux-4jdd</guid>
      <description>&lt;p&gt;A disk name such as &lt;code&gt;/dev/sda&lt;/code&gt; is convenient for the kernel, but it tells you almost nothing about the piece of hardware in the rack, the USB enclosure on the desk, or the drive bay behind a hot-swap backplane. The letter is assigned during device enumeration, so it can change after a reboot, a controller swap, or a new disk is added. Before you format, replace, or unplug a drive, confirm the mapping from the block device name to a model, serial number, bus path, and system role.&lt;/p&gt;

&lt;p&gt;This tutorial starts from a device name and works outward: first with &lt;code&gt;lsblk&lt;/code&gt;, then through the kernel's SCSI and sysfs view, then through persistent identifiers and direct drive queries. It ends with a safety checklist for remote systems, USB disks, and hardware RAID.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Start With the Block Device, Not the Letter&lt;/li&gt;
&lt;li&gt;Cross-Check the Kernel View: SCSI Address and Bus Path&lt;/li&gt;
&lt;li&gt;Confirm the Drive by Model and Serial&lt;/li&gt;
&lt;li&gt;Identify the Boot and Root Disk&lt;/li&gt;
&lt;li&gt;Safety Checklist Before Formatting or Unplugging&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Start With the Block Device, Not the Letter
&lt;/h2&gt;

&lt;p&gt;A block device is a device that moves data in fixed-size blocks, such as a hard drive, SSD, or USB stick. Linux exposes each one as a node under &lt;code&gt;/dev&lt;/code&gt;, and the &lt;code&gt;sd&lt;/code&gt; prefix means the device is handled through the SCSI disk driver. SATA, SAS, and most USB storage all pass through that subsystem, so they can appear as &lt;code&gt;/dev/sda&lt;/code&gt;, &lt;code&gt;/dev/sdb&lt;/code&gt;, and so on. NVMe drives normally use names such as &lt;code&gt;/dev/nvme0n1&lt;/code&gt; instead.&lt;/p&gt;

&lt;p&gt;The kernel does not promise that &lt;code&gt;sda&lt;/code&gt; will always be the same physical drive. &lt;a href="https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/managing_storage_devices/persistent-naming-attributes_managing-storage-devices" rel="noopener noreferrer"&gt;Red Hat's guide to persistent naming attributes&lt;/a&gt; notes that traditional names are assigned by enumeration order and can change when devices are added or removed, when the hardware configuration changes, or after a reboot. Treat the letter as a temporary handle, not an identity.&lt;/p&gt;

&lt;p&gt;Start with a full inventory that includes the fields you actually need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lsblk -d -o NAME,SIZE,TYPE,MODEL,SERIAL,TRAN,WWN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;-d&lt;/code&gt; option means "no dependencies," so &lt;code&gt;lsblk&lt;/code&gt; prints whole disks without their partitions. Remove it when you want the tree view:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS,MODEL,SERIAL,TRAN,WWN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A typical result looks like this:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;NAME&lt;/th&gt;
&lt;th&gt;SIZE&lt;/th&gt;
&lt;th&gt;TYPE&lt;/th&gt;
&lt;th&gt;MODEL&lt;/th&gt;
&lt;th&gt;SERIAL&lt;/th&gt;
&lt;th&gt;TRAN&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;sda&lt;/td&gt;
&lt;td&gt;1.8T&lt;/td&gt;
&lt;td&gt;disk&lt;/td&gt;
&lt;td&gt;Samsung SSD 870 EVO 1TB&lt;/td&gt;
&lt;td&gt;S5Y2NX0T123456&lt;/td&gt;
&lt;td&gt;sata&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;sdb&lt;/td&gt;
&lt;td&gt;3.6T&lt;/td&gt;
&lt;td&gt;disk&lt;/td&gt;
&lt;td&gt;WDC WD40EFRX-68N32N0&lt;/td&gt;
&lt;td&gt;WD-WCC7K0ABCDEF&lt;/td&gt;
&lt;td&gt;sata&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;sdc&lt;/td&gt;
&lt;td&gt;1.8T&lt;/td&gt;
&lt;td&gt;disk&lt;/td&gt;
&lt;td&gt;Seagate Expansion&lt;/td&gt;
&lt;td&gt;NA123456&lt;/td&gt;
&lt;td&gt;usb&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;MODEL&lt;/code&gt; and &lt;code&gt;SERIAL&lt;/code&gt; columns are the first useful anchors. Model alone is not enough because a batch of identical drives will share it; the serial number is what you match against the label on the drive. The &lt;code&gt;TRAN&lt;/code&gt; column shows the transport, such as &lt;code&gt;sata&lt;/code&gt;, &lt;code&gt;usb&lt;/code&gt;, &lt;code&gt;sas&lt;/code&gt;, or &lt;code&gt;nvme&lt;/code&gt;, when the kernel can determine it. &lt;code&gt;WWN&lt;/code&gt; is the World Wide Name, a storage identifier that is generally unique to the device.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;lsblk&lt;/code&gt; gathers its information from sysfs and the udev database, and the &lt;a href="https://man7.org/linux/man-pages/man8/lsblk.8.html" rel="noopener noreferrer"&gt;util-linux &lt;code&gt;lsblk&lt;/code&gt; manual page&lt;/a&gt; recommends always naming the columns you need with &lt;code&gt;--output&lt;/code&gt; in scripts because the default output can change between versions. That is especially important here: a script that parses &lt;code&gt;lsblk&lt;/code&gt; output should ask for &lt;code&gt;NAME&lt;/code&gt;, &lt;code&gt;SERIAL&lt;/code&gt;, and &lt;code&gt;MODEL&lt;/code&gt; explicitly.&lt;/p&gt;

&lt;p&gt;If a field is blank, do not guess. Virtual disks, cheap USB bridges, and some RAID controllers do not pass through a real model or serial. You will need a second method.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cross-Check the Kernel View: SCSI Address and Bus Path
&lt;/h2&gt;

&lt;p&gt;Kernel messages often identify a disk with a four-part SCSI address such as &lt;code&gt;0:4:0:0&lt;/code&gt;. The parts are host, channel, target, and LUN (logical unit number). The &lt;code&gt;lsscsi&lt;/code&gt; utility prints the same tuple and maps it to the device node, which makes it a direct way to answer, "Which disk is &lt;code&gt;sd 0:4:0:0&lt;/code&gt;?"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lsscsi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[0:0:0:0]    disk    ATA      Samsung SSD 870  2B6Q  /dev/sda
[2:0:0:0]    disk    ATA      WDC WD40EFRX-68N 0A82  /dev/sdb
[4:0:0:0]    disk    Seagate  Expansion        0304  /dev/sdc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you already have the address, pass it as a filter. This prints only the matching device:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lsscsi 0:4:0:0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;a href="https://doug-gilbert.github.io/scsi/lsscsi.html" rel="noopener noreferrer"&gt;upstream &lt;code&gt;lsscsi&lt;/code&gt; documentation&lt;/a&gt; explains that the first field is the host, channel, target, and LUN tuple, and that the last field is the primary device node. It also shows how &lt;code&gt;-g&lt;/code&gt; adds the SCSI generic node (&lt;code&gt;/dev/sgN&lt;/code&gt;), &lt;code&gt;-t&lt;/code&gt; shows transport details, and &lt;code&gt;-H&lt;/code&gt; lists the SCSI hosts or controllers. That is useful when you need to know not just the model but which HBA or USB controller the drive is attached to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lsscsi -g
lsscsi -t
lsscsi -H
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The kernel's own view is under &lt;code&gt;/sys&lt;/code&gt;. The &lt;a href="https://docs.kernel.org/filesystems/sysfs.html" rel="noopener noreferrer"&gt;Linux kernel sysfs documentation&lt;/a&gt; notes that &lt;code&gt;/sys/block/&lt;/code&gt; contains symlinks to all block devices discovered on the system, and those links point into directories under &lt;code&gt;/sys/devices&lt;/code&gt;. Resolve the link to see the physical device path:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;readlink -f /sys/block/sda
readlink -f /sys/block/sda/device
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first command typically returns a path containing the controller and target; the second resolves the SCSI device directory. When the driver exposes them, you can read attributes directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cat /sys/block/sda/device/model
cat /sys/block/sda/device/serial
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The resulting path is often the most useful clue for a bay or port. A SATA disk may resolve through a path containing &lt;code&gt;ata1/host0/target0:0:0/0:0:0:0&lt;/code&gt;, while a USB disk may resolve through a &lt;code&gt;usb2/2-1/...&lt;/code&gt; path. That path is topology, not a random name: it reflects where the device is connected.&lt;/p&gt;

&lt;p&gt;For a more readable port mapping, list the persistent path links:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ls -l /dev/disk/by-path/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see entries such as &lt;code&gt;pci-0000:00:17.0-ata-1 -&amp;gt; ../../sda&lt;/code&gt;. Red Hat's persistent naming documentation describes &lt;code&gt;by-path&lt;/code&gt; as being based on physical hardware placement, such as the slot or port where a disk is connected. On a server with numbered bays, this is often the fastest way to translate a device name into a physical location. For a broader catalog of block-device listing commands and their options, see this guide to &lt;a href="https://linuxvox.com/blog/list-devices-in-linux/" rel="noopener noreferrer"&gt;Linux commands for listing block devices&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Confirm the Drive by Model and Serial
&lt;/h2&gt;

&lt;p&gt;Once you have a candidate device, confirm it with a persistent identifier. The &lt;code&gt;/dev/disk/by-id/&lt;/code&gt; directory contains udev-created symlinks built from hardware attributes. Red Hat's documentation describes these names as a combination of vendor, model, and serial string, and notes that &lt;code&gt;by-id&lt;/code&gt;, &lt;code&gt;by-path&lt;/code&gt;, &lt;code&gt;by-uuid&lt;/code&gt;, and related links are the stable alternatives to kernel-assigned names.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ls -l /dev/disk/by-id/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look for names beginning with &lt;code&gt;ata-&lt;/code&gt;, &lt;code&gt;wwn-&lt;/code&gt;, &lt;code&gt;usb-&lt;/code&gt;, or &lt;code&gt;scsi-&lt;/code&gt;. A typical entry looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ata-Samsung_SSD_870_EVO_1TB_S5Y2NX0T123456 -&amp;gt; ../../sda
wwn-0x5002538e40a1b2c3 -&amp;gt; ../../sda
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;ata-&lt;/code&gt; name embeds the model and serial, while the &lt;code&gt;wwn-&lt;/code&gt; name uses the drive's World Wide Name. Both are far more meaningful than &lt;code&gt;sda&lt;/code&gt;. You can also ask udev for every link associated with the device:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;udevadm info --query=property --property=DEVLINKS --value /dev/sda
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a direct query to the drive itself, &lt;code&gt;hdparm -I&lt;/code&gt; requests identification information from the device rather than reading a cached sysfs value. On SATA and IDE drives it reports the model, serial, firmware, and often the LU WWN:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo hdparm -I /dev/sda &lt;span class="o"&gt;|&lt;/span&gt; grep -E &lt;span class="s1"&gt;'Model Number|Serial Number|LU WWN'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;a href="https://man7.org/linux/man-pages/man8/hdparm.8.html" rel="noopener noreferrer"&gt;&lt;code&gt;hdparm&lt;/code&gt; manual page&lt;/a&gt; notes that it works through the kernel's SATA/PATA/SAS libata subsystem and that some USB enclosures support SAT (SCSI-ATA Command Translation), so &lt;code&gt;-I&lt;/code&gt; may work through those bridges too. It is not universal: if the enclosure does not translate the command, use the enclosure's own tools or check the bridge serial.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;lshw&lt;/code&gt; provides another independent view that combines bus information with disk attributes. Its &lt;a href="https://manpages.ubuntu.com/manpages/noble/en/man1/lshw.1.html" rel="noopener noreferrer"&gt;&lt;code&gt;lshw&lt;/code&gt; manual page&lt;/a&gt; notes that it must be run as superuser to report complete information, and its &lt;code&gt;-businfo&lt;/code&gt; option shows SCSI, USB, IDE, and PCI addresses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo lshw -class disk -short
sudo lshw -class disk -businfo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The full &lt;code&gt;lshw -class disk&lt;/code&gt; output usually includes a logical name, product, vendor, serial, and bus info. Cross-checking &lt;code&gt;lsblk&lt;/code&gt;, &lt;code&gt;hdparm&lt;/code&gt;, and &lt;code&gt;lshw&lt;/code&gt; is a good habit because they collect data in different ways: sysfs and udev, a direct ATA identify command, and a hardware inventory scan.&lt;/p&gt;

&lt;p&gt;No single method is perfect. A USB enclosure may report the bridge's serial instead of the drive's serial, and two identical adapters may even report the same value. A hardware RAID controller may present a logical volume as &lt;code&gt;/dev/sda&lt;/code&gt; while hiding the member disks entirely. A virtual machine may use a synthetic serial that has no relation to the host's physical drive. In those cases, the device name identifies the presented volume, not necessarily the piece of hardware you can hold.&lt;/p&gt;

&lt;h2&gt;
  
  
  Identify the Boot and Root Disk
&lt;/h2&gt;

&lt;p&gt;Before touching any disk, identify the boot and root devices. The safest starting point is the mounted filesystem table, not the &lt;code&gt;sd&lt;/code&gt; letter. The &lt;a href="https://man7.org/linux/man-pages/man8/findmnt.8.html" rel="noopener noreferrer"&gt;&lt;code&gt;findmnt&lt;/code&gt; manual page&lt;/a&gt; explains that it searches the kernel mount table and can print just the source device for a path:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;findmnt -n -v -o SOURCE /
findmnt -n -v -o SOURCE /boot
findmnt -n -v -o SOURCE /boot/efi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;-n&lt;/code&gt; option suppresses the header, &lt;code&gt;-o SOURCE&lt;/code&gt; selects only the source column, and &lt;code&gt;-v&lt;/code&gt; avoids printing a &lt;code&gt;[/subvolume]&lt;/code&gt; suffix for bind mounts or Btrfs subvolumes. If &lt;code&gt;/&lt;/code&gt; is on LVM, the source may be &lt;code&gt;/dev/mapper/vg-root&lt;/code&gt;; if it is on a RAID array, it may be &lt;code&gt;/dev/md0&lt;/code&gt;. Either way, that is the filesystem you must not damage.&lt;/p&gt;

&lt;p&gt;To walk from that source back to the physical disk, use &lt;code&gt;lsblk&lt;/code&gt; in inverse order. The &lt;code&gt;-s&lt;/code&gt; option prints dependencies in reverse, so an LVM logical volume leads back through its physical volume to the underlying partition and disk:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lsblk -s -o NAME,TYPE /dev/mapper/vg-root
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NAME    TYPE
vg-root lvm
└─sda3  part
  └─sda disk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a plain partition, the same technique works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lsblk -s -o NAME,TYPE /dev/sda2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also view the whole hierarchy with mount points in one pass:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lsblk -o NAME,TYPE,SIZE,FSTYPE,MOUNTPOINTS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Confirm that the candidate disk is not mounted anywhere and is not the parent of a mounted filesystem. &lt;code&gt;findmnt -S /dev/sda1&lt;/code&gt; checks a specific source, and &lt;code&gt;lsblk&lt;/code&gt; shows mount points for every partition. On a system with LVM, MD RAID, or device-mapper multipath, the disk may not appear directly as a mount source; it appears as a parent in the &lt;code&gt;lsblk&lt;/code&gt; tree. That is exactly why the inverse lookup matters.&lt;/p&gt;

&lt;p&gt;Do not assume the boot disk is &lt;code&gt;sda&lt;/code&gt;. Enumeration order is not a boot-order guarantee. The drive that was &lt;code&gt;sda&lt;/code&gt; in the installer may be &lt;code&gt;sdb&lt;/code&gt; after a controller is added, and a USB installer can take &lt;code&gt;sda&lt;/code&gt; on one boot and &lt;code&gt;sdb&lt;/code&gt; on the next. Confirm the root device by its serial or WWN, not by its position in the list.&lt;/p&gt;

&lt;h2&gt;
  
  
  Safety Checklist Before Formatting or Unplugging
&lt;/h2&gt;

&lt;p&gt;Once you believe you have the right disk, slow down and verify the destructive step from several angles. &lt;code&gt;wipefs&lt;/code&gt;, documented in the &lt;a href="https://man7.org/linux/man-pages/man8/wipefs.8.html" rel="noopener noreferrer"&gt;&lt;code&gt;wipefs&lt;/code&gt; manual page&lt;/a&gt;, is a useful inspection tool before any format: run without options and it lists visible filesystem, RAID, and partition-table signatures without erasing anything.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo wipefs /dev/sda
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The tool is explicit that it does not erase the filesystem itself or other data; it erases signatures so that libraries such as libblkid no longer recognize them. That is still dangerous on the wrong device, because it can make an existing array or filesystem unbootable. Use &lt;code&gt;-n&lt;/code&gt; for a dry run before &lt;code&gt;-a&lt;/code&gt;, and use &lt;code&gt;--backup&lt;/code&gt; if you are intentionally wiping:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo wipefs -n -a /dev/sda
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A practical pre-destructive checklist:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Match the serial&lt;/strong&gt; from &lt;code&gt;lsblk -o SERIAL&lt;/code&gt;, &lt;code&gt;/dev/disk/by-id/&lt;/code&gt;, or &lt;code&gt;hdparm -I&lt;/code&gt; to the label on the physical drive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Match the port&lt;/strong&gt; from &lt;code&gt;/dev/disk/by-path/&lt;/code&gt; or &lt;code&gt;readlink -f /sys/block/sda/device&lt;/code&gt; to the bay or slot you intend to service.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check mounts&lt;/strong&gt; with &lt;code&gt;findmnt -S /dev/sda1&lt;/code&gt;, &lt;code&gt;findmnt -n -o SOURCE /&lt;/code&gt;, and &lt;code&gt;lsblk -o NAME,MOUNTPOINTS&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check holders and layers&lt;/strong&gt; with &lt;code&gt;ls /sys/class/block/sda/holders&lt;/code&gt;, &lt;code&gt;pvs&lt;/code&gt;, and &lt;code&gt;cat /proc/mdstat&lt;/code&gt; when LVM or RAID is in use.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check swap&lt;/strong&gt; with &lt;code&gt;swapon --show&lt;/code&gt;; a swap partition will not necessarily appear as a normal mount.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Exclude the boot and root disks&lt;/strong&gt; you identified in the previous section, including any separate &lt;code&gt;/boot&lt;/code&gt; or EFI system partition.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;On a remote server, do not rely on memory or a ticket description. Use an out-of-band console or IPMI/iDRAC/iLO session if available, and ask a person on site to read the drive label or confirm a location LED before you remove anything. A serial number in a terminal is only useful if it matches the sticker on the hardware.&lt;/p&gt;

&lt;p&gt;USB disks deserve extra caution. A removable drive can be the installer you booted from, and unplugging it can remove the running root filesystem. Check &lt;code&gt;TRAN&lt;/code&gt; in &lt;code&gt;lsblk&lt;/code&gt;, the &lt;code&gt;usb-&lt;/code&gt; links in &lt;code&gt;/dev/disk/by-id/&lt;/code&gt;, and the &lt;code&gt;usb...&lt;/code&gt; path in sysfs before pulling a cable. If the enclosure reports only a bridge serial, identify it by its port path and physical label rather than assuming the serial belongs to the disk inside.&lt;/p&gt;

&lt;p&gt;Hardware RAID is the other common trap. When a controller presents a single logical volume, &lt;code&gt;/dev/sda&lt;/code&gt; may represent the array, not any individual member. &lt;code&gt;lsblk&lt;/code&gt;, &lt;code&gt;hdparm&lt;/code&gt;, and &lt;code&gt;lshw&lt;/code&gt; can only see what the controller exposes. To map a logical volume to a physical slot, use the controller's management utility or its out-of-band interface; pulling a drive based on the &lt;code&gt;sd&lt;/code&gt; letter alone can degrade or destroy the array.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;To find which physical disk is &lt;code&gt;/dev/sda&lt;/code&gt;, build the identification from several independent signals instead of trusting the letter. Start with &lt;code&gt;lsblk -o NAME,MODEL,SERIAL,TRAN,WWN&lt;/code&gt;, use &lt;code&gt;lsscsi&lt;/code&gt; and sysfs to translate a SCSI tuple or bus path, then confirm the model and serial through &lt;code&gt;/dev/disk/by-id/&lt;/code&gt;, &lt;code&gt;hdparm -I&lt;/code&gt;, or &lt;code&gt;lshw&lt;/code&gt;. Before any destructive command, use &lt;code&gt;findmnt&lt;/code&gt; and &lt;code&gt;lsblk -s&lt;/code&gt; to identify the boot and root disks, and check mounts, holders, swap, and RAID members. The final confirmation should be a serial number or WWN that matches the physical hardware, not a device name that may change on the next boot.&lt;/p&gt;

</description>
      <category>cli</category>
      <category>hardware</category>
      <category>linux</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Find Permission Denied: Report Skipped Directories</title>
      <dc:creator>Andrew Marlow</dc:creator>
      <pubDate>Thu, 03 Dec 2026 12:22:28 +0000</pubDate>
      <link>https://dev.to/andrewmarlow/find-permission-denied-report-skipped-directories-pjk</link>
      <guid>https://dev.to/andrewmarlow/find-permission-denied-report-skipped-directories-pjk</guid>
      <description>&lt;p&gt;A backup or inventory job can print "done" while entire directory trees were never examined. When &lt;code&gt;find&lt;/code&gt; cannot search a directory, it writes a diagnostic to standard error, skips that branch, and keeps going. If your script discards standard error, the only evidence of the gap disappears with it.&lt;/p&gt;

&lt;p&gt;This article shows a completeness-first workflow for GNU &lt;code&gt;find&lt;/code&gt; on Linux: preserve the diagnostics, check the exit status, turn permission errors into a skipped-path report, and make every known-unreadable tree an explicit decision rather than an invisible omission.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Why quiet output is dangerous&lt;/li&gt;
&lt;li&gt;Capture stderr and the exit status&lt;/li&gt;
&lt;li&gt;Build the skipped-path report&lt;/li&gt;
&lt;li&gt;Make omissions explicit&lt;/li&gt;
&lt;li&gt;A completeness checklist&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why quiet output is dangerous
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;find&lt;/code&gt; uses two output streams. Matching paths go to standard output, while diagnostics such as &lt;code&gt;find: '/var/lib/private': Permission denied&lt;/code&gt; go to standard error. They are independent, so &lt;code&gt;2&amp;gt;/dev/null&lt;/code&gt; removes the error messages without changing the list of paths that were found. That makes a partial inventory look clean.&lt;/p&gt;

&lt;p&gt;If you only need a quieter interactive search, the common advice on &lt;a href="https://linuxvox.com/blog/linux-find-ignore-permission-denied/" rel="noopener noreferrer"&gt;ignoring Permission denied errors in find&lt;/a&gt; covers the usual redirection and filtering tricks. It is also candid about the limit: hiding the messages does not restore access to the directories that were skipped. For an inventory, a backup, or a compliance scan, those skipped directories are the important part.&lt;/p&gt;

&lt;p&gt;The exit status is the second signal, and it is easy to lose. The &lt;a href="https://gnu.org/software/findutils/manual/html_node/Invoking-find.html" rel="noopener noreferrer"&gt;GNU findutils manual describes find's exit status&lt;/a&gt; as zero when all files matched are processed successfully and greater than zero when errors occur. The &lt;a href="https://manpages.debian.org/testing/findutils/find.1.en.html" rel="noopener noreferrer"&gt;find(1) manual page is more explicit&lt;/a&gt;: if the return value is non-zero, you should not rely on the correctness of the results. A permission-denied directory produces exactly that kind of error.&lt;/p&gt;

&lt;p&gt;Do not test for a specific failure code such as &lt;code&gt;1&lt;/code&gt;. The manual deliberately calls the exit status a broad description, so treat any non-zero status as "incomplete until explained." The exact number is useful in a log, not as a pass/fail contract.&lt;/p&gt;

&lt;p&gt;Pipelines add another trap. A command like this looks like it checks &lt;code&gt;find&lt;/code&gt;, but it does not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;find /srv -type f -print0 &lt;span class="o"&gt;|&lt;/span&gt; sort -z &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; inventory.nul
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, a pipeline returns the status of its last command, which is &lt;code&gt;sort&lt;/code&gt; here. &lt;a href="https://www.gnu.org/software/bash/manual/html_node/Pipelines.html" rel="noopener noreferrer"&gt;Bash's pipeline documentation explains&lt;/a&gt; that enabling &lt;code&gt;pipefail&lt;/code&gt; changes the result to the last non-zero status in the pipeline. Bash also records every stage in &lt;code&gt;PIPESTATUS&lt;/code&gt;, though &lt;a href="https://gnu.org/software/bash/manual/html_node/Bash-Variables.html" rel="noopener noreferrer"&gt;that array is reset by the next command&lt;/a&gt;, so inspect it immediately.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;set&lt;/span&gt; -o pipefail

find /srv -type f -print0 &lt;span class="o"&gt;|&lt;/span&gt; sort -z &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; inventory.nul
&lt;span class="nv"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$?&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; status != 0 &lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"inventory incomplete (find pipeline status $status)"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A related option is not a fix: &lt;code&gt;-ignore_readdir_race&lt;/code&gt; suppresses errors for files that vanish between the directory read and the &lt;code&gt;stat&lt;/code&gt; call. That narrow purpose does not cover permission denied, and using it as a blanket silencer would hide errors you need to see.&lt;/p&gt;

&lt;h2&gt;
  
  
  Capture stderr and the exit status
&lt;/h2&gt;

&lt;p&gt;Keep the diagnostics in a file, and keep &lt;code&gt;find&lt;/code&gt;'s data output separate. The following script writes a NUL-delimited inventory, a raw stderr log, a summary, and a parsed list of skipped directories.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; -uo pipefail

&lt;span class="nv"&gt;root&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;${1:?usage: find-audit.sh ROOT REPORT_DIR}&lt;/span&gt;
&lt;span class="nv"&gt;report_dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;${2:?usage: find-audit.sh ROOT REPORT_DIR}&lt;/span&gt;
mkdir -p &lt;span class="s2"&gt;"$report_dir"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 1

&lt;span class="nv"&gt;out&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;mktemp&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 1
&lt;span class="nv"&gt;err&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;mktemp&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 1
&lt;span class="nb"&gt;trap&lt;/span&gt; &lt;span class="s1"&gt;'rm -f "$out" "$err"'&lt;/span&gt; EXIT

&lt;span class="nv"&gt;LC_ALL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;C find &lt;span class="s2"&gt;"$root"&lt;/span&gt; -type f -print0 &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="s2"&gt;"$out"&lt;/span&gt; 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="s2"&gt;"$err"&lt;/span&gt;
&lt;span class="nv"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$?&lt;/span&gt;

&lt;span class="nv"&gt;permission_lines&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;grep -cF &lt;span class="s1"&gt;': Permission denied'&lt;/span&gt; &lt;span class="s2"&gt;"$err"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;error_lines&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;wc -l &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="s2"&gt;"$err"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'find_status=%d\npermission_denied_lines=%d\nstderr_lines=%d\n'&lt;/span&gt; \
  &lt;span class="s2"&gt;"$status"&lt;/span&gt; &lt;span class="s2"&gt;"$permission_lines"&lt;/span&gt; &lt;span class="s2"&gt;"$error_lines"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="s2"&gt;"$report_dir/summary.txt"&lt;/span&gt;

sed -n &lt;span class="s2"&gt;"s/^find: '\(.*\)': Permission denied$/\1/p"&lt;/span&gt; &lt;span class="s2"&gt;"$err"&lt;/span&gt; \
  &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="s2"&gt;"$report_dir/skipped-directories.txt"&lt;/span&gt;

mv &lt;span class="s2"&gt;"$out"&lt;/span&gt; &lt;span class="s2"&gt;"$report_dir/inventory.nul"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 1
cp &lt;span class="s2"&gt;"$err"&lt;/span&gt; &lt;span class="s2"&gt;"$report_dir/find-stderr.log"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 1

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; status != 0 &lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  cat &lt;span class="s2"&gt;"$err"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"find exited $status; see $report_dir"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
  &lt;span class="nb"&gt;exit&lt;/span&gt; &lt;span class="s2"&gt;"$status"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A few details matter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;set -uo pipefail&lt;/code&gt; deliberately omits &lt;code&gt;-e&lt;/code&gt;. With &lt;code&gt;set -e&lt;/code&gt;, a failing &lt;code&gt;find&lt;/code&gt; could terminate the script before the report is written.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.gnu.org/software/coreutils/manual/html_node/mktemp-invocation.html" rel="noopener noreferrer"&gt;&lt;code&gt;mktemp&lt;/code&gt; creates unpredictable temporary files&lt;/a&gt; with permissions limited to the current user, which is safer than a predictable name in &lt;code&gt;/tmp&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;LC_ALL=C&lt;/code&gt; keeps diagnostic text in English, so the permission-denied match is stable across hosts with different locales.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;2&amp;gt;"$err"&lt;/code&gt; is separate from &lt;code&gt;&amp;gt;"$out"&lt;/code&gt; on purpose. Using &lt;code&gt;2&amp;gt;&amp;amp;1&lt;/code&gt; would mix error text into the inventory data.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;status=$?&lt;/code&gt; runs immediately after &lt;code&gt;find&lt;/code&gt;; any command in between would overwrite the value.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On GNU &lt;code&gt;find&lt;/code&gt;, a stderr line normally looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find: '/srv/private': Permission denied
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the job exits, it exits with &lt;code&gt;find&lt;/code&gt;'s status, so cron, systemd, or CI can see the failure. The report files remain available for diagnosis. That combination is the main improvement over &lt;code&gt;2&amp;gt;/dev/null&lt;/code&gt;: the job fails visibly and still leaves an audit trail.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build the skipped-path report
&lt;/h2&gt;

&lt;p&gt;The summary and the parsed list serve different purposes. Capture the raw log first, then derive the human-readable report from it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;permission_lines&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;grep -cF &lt;span class="s1"&gt;': Permission denied'&lt;/span&gt; &lt;span class="s2"&gt;"$err"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;error_lines&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;wc -l &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="s2"&gt;"$err"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

sed -n &lt;span class="s2"&gt;"s/^find: '\(.*\)': Permission denied$/\1/p"&lt;/span&gt; &lt;span class="s2"&gt;"$err"&lt;/span&gt; \
  &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; skipped-directories.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;|| true&lt;/code&gt; after &lt;code&gt;grep&lt;/code&gt; prevents a zero-match run from looking like a script error. &lt;code&gt;grep -c&lt;/code&gt; prints &lt;code&gt;0&lt;/code&gt; but exits with status &lt;code&gt;1&lt;/code&gt; when nothing matches.&lt;/p&gt;

&lt;p&gt;Treat the &lt;code&gt;sed&lt;/code&gt; extraction as a convenience, not a stable interface. GNU &lt;code&gt;find&lt;/code&gt; quotes unusual characters in diagnostics, and a filename containing a single quote or a newline can break a one-path-per-line parser. Different &lt;code&gt;find&lt;/code&gt; implementations also format errors differently. If the tree may contain hostile or unusual names, keep the raw log as the authoritative evidence and use the exit status and count for the job's pass/fail decision. The parsed list is for a human reviewer, not for a security boundary.&lt;/p&gt;

&lt;p&gt;A useful report makes the distinction clear:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Artifact&lt;/th&gt;
&lt;th&gt;Contents&lt;/th&gt;
&lt;th&gt;Role&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;inventory.nul&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;NUL-delimited paths that &lt;code&gt;find&lt;/code&gt; visited&lt;/td&gt;
&lt;td&gt;Machine-readable partial inventory&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;find-stderr.log&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Raw diagnostics, including permission errors&lt;/td&gt;
&lt;td&gt;Audit evidence&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;skipped-directories.txt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Parsed paths, one per line&lt;/td&gt;
&lt;td&gt;Review aid&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;summary.txt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Exit status and error counts&lt;/td&gt;
&lt;td&gt;Gate for automation&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The table also exposes a common mistake: counting only the permission-denied lines can miss other errors. Check &lt;code&gt;stderr_lines&lt;/code&gt; and the raw log too. A disk I/O error, a vanished mount point, or an unreadable file is not a permission-denied directory, but it is still a reason to distrust the inventory.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make omissions explicit
&lt;/h2&gt;

&lt;p&gt;Once a path is skipped, you have three honest choices: fail, approve the omission, or get more visibility. Pick one per path; do not let the default be silence.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Fail the job.&lt;/strong&gt; This is the right default for backups, compliance scans, and anything where a partial result is worse than a visible failure.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Approve the omission.&lt;/strong&gt; Record the path, reason, owner, and review date in a version-controlled allowlist. The report should include that list, so the omission is documented rather than merely quiet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Re-run with sufficient privilege.&lt;/strong&gt; Scan only the skipped paths as a separate, audited job, and keep its status and log separate from the original run.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Descending into a directory requires search permission, and the kernel reports a missing search bit as &lt;code&gt;EACCES&lt;/code&gt;, which &lt;code&gt;find&lt;/code&gt; prints as "Permission denied." The &lt;a href="https://man7.org/linux/man-pages/man7/path_resolution.7.html" rel="noopener noreferrer"&gt;Linux path_resolution(7) manual explains that permission check&lt;/a&gt; in more detail.&lt;/p&gt;

&lt;p&gt;Pruning belongs to option 2. It is not a way to make unknown errors disappear. If you need to discover candidate paths for an approved list, GNU &lt;code&gt;find&lt;/code&gt; can test read and search access before descending:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;LC_ALL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;C find /srv \
  -type d ! \&lt;span class="o"&gt;(&lt;/span&gt; -readable -executable \&lt;span class="o"&gt;)&lt;/span&gt; -prune -print0 \
  &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; unreadable-dirs.nul
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This lists directories the current account cannot read or search and avoids descending into them. It is a discovery aid: it does not replace the real job's exit-status check, and access can change between the scan and the job.&lt;/p&gt;

&lt;p&gt;Once a path is approved, feed it into a prune expression:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;prune&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="nv"&gt;IFS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;read&lt;/span&gt; -r path&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt; -n &lt;span class="nv"&gt;$path&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;continue&lt;/span&gt;
  prune+=&lt;span class="o"&gt;(&lt;/span&gt; -path &lt;span class="s2"&gt;"$path"&lt;/span&gt; -prune -o &lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; approved-unreadable.txt

&lt;span class="nv"&gt;LC_ALL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;C find /srv &lt;span class="s2"&gt;"${prune[@]}"&lt;/span&gt; -type f -print0 &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; inventory.nul 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; stderr.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two cautions apply. &lt;code&gt;-path&lt;/code&gt; matches a shell pattern, so a literal path containing &lt;code&gt;*&lt;/code&gt;, &lt;code&gt;?&lt;/code&gt;, or &lt;code&gt;[&lt;/code&gt; needs escaping. More importantly, &lt;a href="https://www.gnu.org/software/findutils/manual/html_node/Directories.html" rel="noopener noreferrer"&gt;&lt;code&gt;-prune&lt;/code&gt; has no effect when &lt;code&gt;-depth&lt;/code&gt; is in effect&lt;/a&gt;, and &lt;code&gt;-delete&lt;/code&gt; implies &lt;code&gt;-depth&lt;/code&gt;. A prune-based exclusion list will not protect a &lt;code&gt;find ... -delete&lt;/code&gt; job from descending into those trees.&lt;/p&gt;

&lt;p&gt;When you prune a known-unreadable tree, add it to the report. The reader should see "excluded by policy" alongside "skipped by permission denied." Those are different facts, and only one of them is a surprise.&lt;/p&gt;

&lt;p&gt;If you choose an elevated re-run, point it at the skipped paths rather than the whole tree:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;find /srv/private -type f -print0 &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; rescan.nul
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it as the account that actually has access, keep its stderr and status, and store it as a separate artifact. If you merge it with the original inventory, deduplicate first; overlapping starting points can otherwise list the same file twice. The goal is not to make the first run look complete. The goal is to record exactly what became visible under different credentials.&lt;/p&gt;

&lt;h2&gt;
  
  
  A completeness checklist
&lt;/h2&gt;

&lt;p&gt;For a backup, migration, compliance, or file-counting job where missing files are unacceptable, verify these points before trusting the output:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Standard output and standard error are redirected separately.&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;find&lt;/code&gt;'s exit status is captured immediately, before any other command runs.&lt;/li&gt;
&lt;li&gt;[ ] Pipelines use &lt;code&gt;pipefail&lt;/code&gt; or check &lt;code&gt;PIPESTATUS[0]&lt;/code&gt; directly.&lt;/li&gt;
&lt;li&gt;[ ] The raw stderr log is retained with the job's run ID or timestamp.&lt;/li&gt;
&lt;li&gt;[ ] The summary reports both permission-denied lines and total stderr lines.&lt;/li&gt;
&lt;li&gt;[ ] Skipped paths are listed for review, with the parser's limits documented.&lt;/li&gt;
&lt;li&gt;[ ] Approved exclusions are version-controlled and included in the report.&lt;/li&gt;
&lt;li&gt;[ ] Any privileged re-run is scoped to the skipped paths and logged separately.&lt;/li&gt;
&lt;li&gt;[ ] The job fails closed unless every omission is explicitly approved.&lt;/li&gt;
&lt;li&gt;[ ] The failure path is tested with a &lt;code&gt;chmod 000&lt;/code&gt; directory before the job is trusted.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That last test is worth doing on every new host image or container base. Create a directory, remove all permissions, run the job as the same unprivileged account, and confirm that it fails and names the directory. Restore the permissions afterward, and check that a clean run reports zero skipped paths.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Permission denied is not cosmetic noise. It is a completeness signal. &lt;code&gt;2&amp;gt;/dev/null&lt;/code&gt; hides that signal, while &lt;code&gt;find&lt;/code&gt; continues with a partial walk and a non-zero exit status that many scripts never inspect.&lt;/p&gt;

&lt;p&gt;Capture stderr to a log, capture the status immediately, and handle pipelines explicitly. Parse the permission-denied lines into a report, but keep the raw log as the evidence. Then make each skipped tree a decision: fail the job, approve and prune it as a documented exception, or rescan it with the credentials it requires. That turns "the inventory finished" into a statement you can actually defend.&lt;/p&gt;

</description>
      <category>bash</category>
      <category>cli</category>
      <category>devops</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
