[英]Glob to files with suffixes within a numeric range
I have a list of files with the following names:我有一个具有以下名称的文件列表:
document1
document2
document3
..
document41
document42
document43
To check all the all document space, I could use du -sh file*.要检查所有文档空间,我可以使用 du -sh file*. I am trying to access documents from document1 to document 10. I tried the following:
我正在尝试访问从 document1 到 document 10 的文档。我尝试了以下操作:
du -sh document[1-10]
But it returns document 28
and document 15
.但它返回
document 28
和document 15
。 I would like to know how could I access a range of files with document name from document1 to document10?我想知道如何访问文档名称从 document1 到 document10 的一系列文件?
如果dan 的解决方案太多而无法输入或记住,您可以使用bash 的大括号扩展功能来创建十个文件名,然后通过将 stderr 重定向到 /dev/null 来删除du
关于丢失文件的潜在错误消息:
du -sk document{1..10} 2>/dev/null
In bash:在 bash 中:
shopt -s nullglob
du -sh document[1-9] document1[0]
Only existing files numbered 1-10 will be passed to du
.只有编号为 1-10 的现有文件将传递给
du
。
Regular sh doesn't have nullglob.常规 sh 没有 nullglob。 If a pattern doesn't match, it's passed literally.
如果模式不匹配,则按字面意思传递。 This causes either a file not found error, or importantly, a non matching file to be passed (ie. an existing file literally named
document1[0]
).这会导致文件未找到错误,或者重要的是,传递一个不匹配的文件(即,一个字面上名为
document1[0]
的现有文件)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.