繁体   English   中英

使用命令行在多个文件上执行命令

[英]Perform a command on multiple files using command line

说我有以下文件:

myfile1_1.dat
myfile1_2.dat
myfile2_1.dat
myfile2_2.dat
...

并且我想对它们每个使用相同的命令(而忽略目录中不是以myfile开头的其他文件)。 有一个简单的方法吗?

到目前为止,我一直在玩通配符:

mycommand myfile*.dat

编辑:我同时使用Linux和MinGW

mycommand myfile*.dat仅在mycommand支持多个文件时才有效。 如果没有,则可以使用xargs将单个文件传递给mycommand ,如下所示:

echo myfile*.dat | xargs -n 1 mycommand

或者,使用循环:

for file in myfile*.dat; do
    mycommand "$file"
done

如果您在Linux中执行此操作,则通常使用xargs -n1

ls | xargs -n1 echo File: 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM