[英]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. 我正在使用我编写的python脚本从
ls
获取一些标准输入并将数据加载到该路径描述的文件中。 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). 我想要使用的文件具有名称结构
A<fileID>_###.txt
(其中###
总是一些3位数字)。 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*
. 我只能通过将上面的内容稍微更改为
ls -d /path/to/files/A*
来完成仅获取以A开头的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. 但是,有些文件有一个名为B的后缀标志(所以文件看起来像
A<fileID>_###B.txt
),我不想包含那些。
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)? 所以,我的问题是,有没有办法排除那些以
...B.txt
结尾的文件(或者只包含以数字结尾的文件的方式)? 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. 仅包含以数字结尾的文件,后跟文件扩展名,但找不到任何类型的文档。
你可以试试这个: ls A*[^B].txt
With extended globbing . 随着扩展的globbing 。
shopt -s extglob
ls R*!(B).txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.