How to Restrict Find Command to a Single Filesystem in Ubuntu (find -xdev)

The Mount Point Problem

In Ubuntu Linux, multiple different hard drives are often mounted seamlessly into a single continuous directory structure. For example, your primary solid-state drive might be mounted at the root (/), while a massive, slow 10-Terabyte backup hard drive might be mounted at /mnt/backup. If you run a standard find command starting from the root directory, the search engine will violently cross over the boundary into the /mnt/backup folder and spend hours pointlessly scanning the massive, slow backup drive. To execute a rapid, highly efficient search of only your primary operating system files, you must instruct the command to never cross physical hardware boundaries.

Using the find Command with -xdev

The Linux find command utilizes the -xdev flag (which stands for “exclude devices”) to strictly confine the search to the single physical filesystem where the search originated.

  1. Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
  2. To search for all files ending in .log starting from the root directory, but completely ignoring any attached external drives or network mounts, type the following command exactly:
    sudo find / -xdev -name "*.log"
  3. Press Enter and provide your administrator password.

Confined Execution

The command will execute significantly faster. When the search engine hits the /mnt/backup directory, it will detect that the folder is actually a mount point pointing to a completely different physical disk partition. The -xdev flag forces the engine to instantly skip that entire directory branch and return to scanning the primary root filesystem, saving massive amounts of time and avoiding unnecessary disk thrashing on your secondary drives.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.