Avatar of ttist25

asked on 

Linux Command line Delete everything but 1 folder


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.


Avatar of undefined
Last Comment

8/22/2022 - Mon