Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
acshearer Honored Contributor.
Honored Contributor.
939 views

Delete all files in all user's home directories

Hello,

Is there a program out there or a way to delete all the files/folders in all user's home directories but not delete the home directory folder itself?

Thanks,
Andrew
Labels (2)
0 Likes
5 Replies
Knowledge Partner
Knowledge Partner

Re: Delete all files in all user's home directories

Are there any other limitations on your request? If you login to the
server as that user (SSH or whatever) or just become that user ('root' can
do that with the 'su' command) you could probably just do the following
(do NOT do this as 'root' or another powerful user, just in case):


pwd #Verify you're in the right location
rm -rf * #Delete everything in here that is not hidden (dot-prepended)


--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...
0 Likes
Micro Focus Expert
Micro Focus Expert

Re: Delete all files in all user's home directories

Hi Andrew,

I'm not a Linux guru like AB is, but this is how I would do it.... Just whack the entire "users" directory with all user folders, contents, etc. Use a tool like "Homes" from HBWare to recreate the home directory structure with blank folders for each user.

Just a suggestion.

Cheers,
Laura Buckley

Views/comments expressed here are entirely my own.
If you find this post helpful, please show your appreciation and click on "Like" below...
0 Likes
acshearer Honored Contributor.
Honored Contributor.

Re: Delete all files in all user's home directories

Thanks for the replies. I am doing what Laura suggested and that is working, so all is well.

Thanks,
Andrew
0 Likes
mdallair Absent Member.
Absent Member.

Re: Delete all files in all user's home directories

Hi,

You can use the find command with the mindepth parameter

find /media/nss/DATA/users -mindepth 2 -print0 | xargs rm -r 2>/dev/null

This command is for deleting all files and folders inside each folders UNDER the directory /media/nss/DATA/users

To be sure which files and folders the command shoud delete you can check with the command find /media/nss/DATA/users -mindepth 2 to get the list

Martin Dallaire
0 Likes
Micro Focus Expert
Micro Focus Expert

Re: Delete all files in all user's home directories

Hi Andrew,

As long as you have come right? Thanks for the feedback 🙂 Sorry, I forgot to add the link to the tool that I was referencing!

Cheers,
Laura Buckley

Views/comments expressed here are entirely my own.
If you find this post helpful, please show your appreciation and click on "Like" below...
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.