troubleshooting Question

Linux Command line Delete everything but 1 folder

Avatar of ttist25
ttist25 asked on
5 Comments1 Solution103 ViewsLast Modified:

I need to delete all files from a directory except for one folder:

The directory with all of the files I want to delete:

The directory I want to keep:

/home/user has a bunch of files and folders in it that I want to blow away
/home/user/backup has a bunch of files and folders that would make me sad if I blew them away (i.e., I want to keep the backjup directory and all of the files in it).

I created a test directory structure and touched a few files in each and used "rm -rf /home/user/*" thinking it would balk because the child directory wasn't empty but it just wiped everything out.  

Any help would be greatly appreciated.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros