Find the answer to your Linux question:
Results 1 to 2 of 2
Hello I have directory which has many files and sub directories similar to what this command will do mkdir dir{1..100} && touch file{1..100}.txt I would like to remove all files ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2009
    Location
    Toronto
    Posts
    34

    how to remove all files except few directories


    Hello

    I have directory which has many files and sub directories

    similar to what this command will do

    mkdir dir{1..100} && touch file{1..100}.txt

    I would like to remove all files and directories excluding file15.txt and dir 79

    Thank you

  2. #2
    Just Joined!
    Join Date
    Aug 2009
    Location
    Toronto
    Posts
    34
    I found the answer for this question

    you need to run this command first

    Code:
    shopt -s extglob
    then delete all files except the files between brackets

    Code:
    rm !(file1|dir|)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •