0

How to delete files except one file in the Ubuntu directory?

Asked 3 years ago (Apr 08, 2021) in the field of Operating Systems by Vaynald

Hi, I want to delete all the files in a directory that I am in except one file. How should I execute the command in the terminal?Thanks


Answers


0
Answered 3 years ago (Apr 08, 2021) by Eldernode staff

Dear Vaynald, 

 

To delete all the files, first, you need to enter to your considered directory and then use the below PHP codes:

rm !(file.txt)

Or

rm -f !(file.txt) 

Note that you need to type the name of the file you do not want to delete Instead of file.txt.

 

Thank you for sending the message.

Good Luck 

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way

+8595670151

7 days a week, 24 hours a day