Shell Scripting / Bash Tricks
Stop burying your errors in deep directory loops
🧩 The Challenge
Trying to run a script across thousands of subdirectories is a nightmare when one faulty directory throws a permission denied error that drowns out your actual work. I’ve wasted so many hours manually hunting down which subfolder triggered the chain reaction of noise.
💡 The Fix
Use find with a custom filter to handle the heavy lifting while redirecting stderr to a separate file or dev null so you can actually see the output that matters. It’s way cleaner than trying to parse a wall of text that’s mostly red noise.
find /data/path -type d -name "configs" 2>/dev/null -execdir sh -c 'ls -ld "$PWD"' \;
⚙️ Why It Works
By sending the error stream to null, you stop the garbage from cluttering your terminal and only look at the data your script successfully pulled. Using -execdir is safer too, since it runs the command from inside the directory it found, preventing path expansion headaches.
🚀 Pro-Tip: Pipe that error stream to a log file instead of dev null if you actually want to debug the failures later without interrupting your current session.
Linux Tips & Tricks | © ngelinux.com | 10/19/2026
