Rm except one file

In this article let’s discuss about Rm except one file. Let’s go through the following methods without any delay.

Method 1:

shopt -s extglob 
rm !(file.txt)

If you are facing any issues with the above approach then try the alternative that is given below. It may look similar but have a try!

Method 2 :

# if you are using a loop

shopt -s extglob

rm -rf !("abc.txt" | "abc.log" )  # others will be removed except these two

shopt -u extglob 

Hope the above solution works.

Realted Posts : How to upload with httpie