In Linux terminal, how to delete all files in a directory except one or two

前端 未结 5 816
傲寒
傲寒 2021-02-05 14:39

In a Linux terminal, how to delete all files from a folder except one or two?

For example.

I have 100 image files in a directory and one

5条回答
  •  我在风中等你
    2021-02-05 15:11

    In bash, you can use:

    $ shopt -s extglob  # Enable extended pattern matching features    
    $ rm !(*.txt)       # Delete all files except .txt files
    

提交回复
热议问题