0

I'm taking over a Linux Ubuntu machine from a previous employee whose recently left. I've created an account for myself on the machine.

I want to preserve their home directory, but change ownership of any system files and directories outside of their home directory to myself.

Basically if User X is the previous user who has left I want to change any system files and directories belonging to User X outside of their home directory to myself now (e.g. stuff within /var/www, /usr/local etc. The only thing left that should have ownership to User X would be their home directory and anything within it. Later I can then backup anything within their home directory and then delete when ready.

Is there a known tool for such a job? Or am I looking for long piped command from the Terminal? E.g. from root, search entire file system for all files &dirs belonging to user X | chown to me? What would a long command like that look like?

Thanks.

skålfyfan
  • 4,931
  • 5
  • 41
  • 59

2 Answers2

0
find / -user X \( -name ~X -prune -o -exec chown Y:Y {} \; \)
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
0

These commands search for all files and folders which owned by the olduser, then change the ownership to newuser one-by-one.

find / -user olduser 2>/dev/null -exec chown newuser {} \;
find / -group olduser 2>/dev/null -exec chown newsuer {} \;
Feriman
  • 503
  • 8
  • 17