Search code examples
bashls

How to exclude files using ls?


I'm using a python script I wrote to take some standard input from ls and load the data in the files described by that path. It looks something like this:

    ls -d /path/to/files/* | python read_files.py

The files have a certain name structure based on what data they have in them but are all stored in the same directory. The files I want to use have the name structure A<fileID>_###.txt (where ### is always some 3 digit number). I can accomplish getting only the files that start with A by just changing what I have above slightly to ls -d /path/to/files/A*. HOWEVER, some files have a suffix flag called B (so the file looks like A<fileID>_###B.txt) and I DO NOT want to include those.

So, my question is, is there a way to exclude those files that end in ...B.txt (or a way to only include files that end in a number)? I thought about something to the effect of:

    ls -d /path/to/file/R*%d.txt

to only include files that end in a number followed by the file extension, but couldn't find any documentation on anything of the sort.


Solution

  • You could try this : ls A*[^B].txt