Link to home
Start Free TrialLog in
Avatar of rugman_66
rugman_66

asked on

Bash script to remove files in directory but exlude by owner

Hello,

I'm new to Bash scripting, and need a scrip to run as a cron that will remove all files recursively
in specific directories, but exclude any files owned by specific users. How can this be done?

Thank you
Avatar of farzanj
farzanj
Flag of Canada image

You need to use a simple find command like
/path/to/dir is the path of directory under which you want to do a recursive search
In this command, I didn't want to remove files owned by root

find /path/to/dir -not -user root -type f -exec rm '{}' \;
ASKER CERTIFIED SOLUTION
Avatar of farzanj
farzanj
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rugman_66
rugman_66

ASKER

Thanks farzanj

I added a few options, and works great!

-John