Site icon New Generation Enterprise Linux

Ghost files owned by numeric UIDs? Clean ’em up.

User & Group Management

Ghost files owned by numeric UIDs? Clean ’em up.

🧩 The Challenge

Ever deleted a user, then later you’re looking at a directory and `ls -l` is just spitting out numeric UIDs like `1005` instead of an actual username? Yeah, that happens. Those are files owned by a user that’s no longer on the system. It’s annoying, it’s messy, and it can even be a security headache if a new user gets that UID later on. Nobody ever tells you how to properly clean this up after `userdel` sometimes.

💡 The Fix

You don’t need to manually hunt down every single file. There’s a quick way to find all files owned by that phantom UID and reassign them to a proper user, like an administrative account or a specific service user. Keeps things tidy and secure.

sudo find / -uid <numeric_UID_here> -xdev -print0 2>/dev/null | sudo xargs -0 chown <new_username>:<new_groupname>

⚙️ Why It Works

What’s going on here is `find` is searching the entire filesystem (except crossing mount points, thanks to `-xdev`) for files whose owner ID matches the numeric one you specify, ignoring permission errors. It then pipes those paths safely to `xargs` which executes `chown` on them, changing the owner and group to something valid again.

🚀 Pro-Tip: Always run the `find` part *without* the `xargs` first to just list the files you’re about to change. Always helps avoid oopsies.

Linux Tips & Tricks | © ngelinux.com | 10/22/2026

0 0 votes
Article Rating
Exit mobile version