Say I have the following files:
myfile1_1.dat
myfile1_2.dat
myfile2_1.dat
myfile2_2.dat
...
and I want to use the same command on each of them (whilst ignoring other files in the directory that do not begin with myfile). Is there an easy way of doing this?
So far, I have been toying with wildcards:
mycommand myfile*.dat
EDIT: I am using both Linux and MinGW
mycommand myfile*.dat will only work if mycommand supports multiple files. If it doesn't, you can use xargs to pass a single file to mycommand as shown below:
echo myfile*.dat | xargs -n 1 mycommand
Alternatively, use a loop:
for file in myfile*.dat; do
mycommand "$file"
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With