0

Some time ago we migrated services from an old CentOs installation to RedHat. Part of this process was copying the /home directory to the new installation.

The new RedHat installation has fewer users than that old CentOs installation. We would like to move any directory in the /home directory that does not have a user to /home/abandoned.

How can this be done?

I would like to do it in one operation. The /home/abandoned directory is only temporary. We will eventually delete that directory once we are sure all the non-user directories are not needed

This will be a one time process, so it doesn't have to be flexible or pretty.

edit

I believe that the following will work, but I don't want to run it without some input from the folks here. Does this look acceptable? find /home -maxdepth 1 -nouser -type d -exec mv {} /home/abandoned/. \;

/edit

4
  • 1
    Bad choice of location. Under /home there should be users' folders only. Other than that I don't understand your question. What is stopping you from moving those folders to anywhere else you consider fit? – user353477 Sep 19 '19 at 20:00
  • I believe that the following will work, but I don't want to run it without some input from the folks here. Does this look acceptable? find /home -maxdepth 1 -nouser -type d -exec mv {} /home/abandoned/. \; – Calab Sep 19 '19 at 20:03
  • @GabrielaGarcia - I would like to do it in one operation. The /home/abandoned directory is only temporary. We will eventually delete that directory once we are sure all the non-user directories are not needed. – Calab Sep 19 '19 at 20:07
  • Your comment should be a part of the question. It shows your research effort, something we like. Please edit the question. – Kamil Maciorowski Sep 19 '19 at 20:39
0

Please don't forget to cd to home, you definitely don't want to run the last command from /.

To list all the directories with no user:

cd /home ; find -type d -maxdepth 1 -nouser

DANGEROUS To move them AFTER checking them:

cd /home ; mkdir abandoned; find -type d -maxdepth 1 -nouser -exec mv -iv \{\} 'abandoned' \;
1
  • 1
    Little less dangerous: cd /home && mkdir abandoned && find …. – Kamil Maciorowski Sep 20 '19 at 6:48
0

Normally, users' /home directories are named after the username of the user. As a simple preliminary check, you can check the directory name in /home against the username in /etc/passwd. If you find no matching record in /etc/passwd, then you can further validate your decision process with the -nouser argument to the find command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.