Find the answer to your Linux question:
Results 1 to 6 of 6
Hello, I was hoping that doing Code: rm file123\D.txt would delete all files of the following format: file123.txt, file123a.txt, file123b.txt. But instead it complains that file123D.txt could not be found. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2010
    Posts
    27

    Not a number


    Hello,

    I was hoping that doing
    Code:
    rm file123\D.txt
    would delete all files of the following format: file123.txt, file123a.txt, file123b.txt. But instead it complains that file123D.txt could not be found. What am I doing wrong?
    Many thanks in advance for you help.

  2. #2
    Linux User peteh's Avatar
    Join Date
    Oct 2006
    Location
    UK
    Posts
    339
    You need
    Code:
    rm file123*.txt
    But be careful that will remove all files that start file 123+anything.txt in the current working directory.
    If you know there's just one character after "123" and before ".txt" you could use
    Code:
     rm file123?.txt
    Pete

  3. #3
    Just Joined!
    Join Date
    Aug 2010
    Posts
    27
    Thank you for replying.

    I need to delete files that named like : file123.txt, file123A.txt, file123B.txt, file123C.txt, and so on. But I don't want to delete file1234.txt, file1234A.txt, file1234B.txt. Please advice.

  4. #4
    Linux User peteh's Avatar
    Join Date
    Oct 2006
    Location
    UK
    Posts
    339
    I'm not sure if you can do that in one go. You can try this
    Code:
    rm file123.txt && rm file123[A-Z].txt
    This would leave "file1234.txt" or "file1235.txt" untouched.
    If you google "bash scripts" or specifically "bash wildcards", there's plenty of help online.
    Pete

  5. #5
    Just Joined!
    Join Date
    Aug 2010
    Posts
    27
    That worked. I did not think of it that way. Thank you again.

  6. #6
    Linux User peteh's Avatar
    Join Date
    Oct 2006
    Location
    UK
    Posts
    339
    You're welcome.
    Pete

Posting Permissions

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