Skip to content

How to Fix Linux find: Permission Denied Error

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix Linux find: Permission Denied Error. We cover key concepts, practical examples, and best practices.

You run find and the output is cluttered with Permission denied messages — find tries to search directories that your user does not have permission to read.

The Problem

find: '/root': Permission denied
find: '/var/log/private': Permission denied
find: '/etc/ssl/private': Permission denied

Step-by-Step Fix

Step 1: Suppress permission denied errors

# WRONG — shows all errors
find / -name "config.txt"

# RIGHT — suppress permission errors
find / -name "config.txt" 2>/dev/null

Step 2: Skip inaccessible directories

find / -name "config.txt" -not -path "*/proc/*" -not -path "*/sys/*" 2>/dev/null
sudo find / -name "config.txt"

Step 4: Search only user-accessible paths

find ~ -name "config.txt"
find /home -name "config.txt"
find /tmp -name "config.txt"
find /var/www -name "config.txt"

Step 5: Limit search depth

# Only search 3 levels deep
find / -maxdepth 3 -name "config.txt" 2>/dev/null

Step 6: Exclude system directories

find / \( -path /proc -o -path /sys -o -path /dev \) -prune -false -o -name "config.txt" -print 2>/dev/null

Step 7: Use locate instead of find

# Faster, uses pre-built database
sudo updatedb
locate config.txt

locate runs as root and accesses the entire filesystem without permission errors.

Prevention Tips

  • Use 2>/dev/null to suppress expected permission errors
  • Use sudo find when you need complete results
  • Prefer locate for filename searches
  • Exclude system directories with -prune
  • Limit search depth with -maxdepth for large directories

Common Mistakes with find permission

  1. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  2. Misunderstanding that String is [Char] with poor performance for large text operations
  3. Using foldl instead of foldl' causing stack overflow on large lists

These mistakes appear frequently in real-world LINUX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does find show Permission denied even with sudo?

If sudo is not configured correctly, or the filesystem has been mounted with noexec or nosuid options that affect sudo. Use sudo -s or sudo -i first, then run find.

How do I exclude all Permission denied errors from find output?

Redirect stderr: find / -name "file" 2>/dev/null. This discards all error messages including Permission denied. For more selective filtering, use -not -readable to prune unreadable directories: find / -type d -not -readable -prune -false -o -name "file" -print.

What is the difference between find and locate?

find searches the filesystem in real-time — it is accurate but slow. locate searches a pre-built database — it is fast but may not reflect recent file changes. Run sudo updatedb to refresh the database.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro