[Linux] How to remove all folder and files except one folder?

by 1 replies
2
sorry if re post. i just wanna be careful, and also i didn't find any answer that suit with my case.

i have few folder name under /home/user/www
say it: f1, f2, f3, f4, f5
and there are few files under folder f1-f5 as well

i usually use: rm -rf /home/user/www/* to delete them all [f1-f5]

but how to delete all of them except folder f1?

thanks
#programming #files #folder #linux #remove
  • sudo rm -r folder1 folder2 folder 3 *.* -f

    the *.* will remove all files...replace folder1, 2, 3 etc with the dir names you want to remove.

    Also, you could do mv foldertokeep /var/tmp then delete everything and the move it back mv /var/tmp/foldertokeep /var/www
    • [ 1 ] Thanks

Next Topics on Trending Feed