I have some files in some directory. For example:
/path/file1.out
/path/file2.out
/path/file3.out
/path/file4.out
/path/file5.out
Is it possible to write something to all of these files using echo with a single command? I would expect something like
echo "asd" > /path/file*.out
but it is not recognizing the glob.
It is not possible to redirect to more files, you need to use a loop:
shopt -s nullglob
for file in /path/file*.out; do
echo "foo" > "$file"
done
Or you can use tee that will output to stdout at the same time:
shopt -s nullglob
echo "foo" | tee /path/file*.out
Note that shopt -s nullglob is important so that you don't create an undesired file if there are no files matching your pattern.
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