Commands.page Logo

How to Use Sudo with Find Command in Ubuntu

This guide explains how to combine the sudo command with the find utility in Ubuntu to search for files across the entire system. You will learn the correct syntax to avoid permission errors when accessing restricted directories and understand how to execute find operations with root privileges safely.

Basic Syntax

To run the find command with administrative privileges, place sudo before the command. The standard structure looks like this:

sudo find /path/to/search -name "filename"

Using sudo ensures the command can read directories owned by the root user or other system accounts that a standard user cannot access.

Why Use Sudo with Find

When running find as a standard user, you will often encounter “Permission denied” errors. This happens when the command attempts to scan system folders like /root, /etc, or /var/log. Prepending sudo grants the necessary permissions to traverse these protected paths without stopping the search process.

Practical Examples

Search for a specific file across the whole system:

sudo find / -name "nginx.conf"

Find files larger than 100MB:

sudo find / -size +100M

Find and list details of files owned by root:

sudo find /home -user root -ls

Safety Precautions

Using sudo with find grants powerful access to your file system. Be extremely careful when combining sudo find with the -exec or -delete flags. Always test your search query without deletion flags first to ensure you are targeting the correct files before modifying or removing them.