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

1 replies
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
#files #folder #linux #remove
  • Profile picture of the author IdeaBox
    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
    {{ DiscussionBoard.errors[8559922].message }}

Trending Topics