How can I add a string to the beginning of each file in a folder in bash?

前端 未结 9 896
天命终不由人
天命终不由人 2021-01-01 17:04

I want to be able to prepend a string to the beginning of each text file in a folder. How can I do this using bash on Linux?

9条回答
  •  佛祖请我去吃肉
    2021-01-01 17:16

    You can do this as well:

    for f in *; do
      cat <(echo "someline") $f > tempfile
      mv tempfile $f
    done
    

    It's not much different from the 1st post but does show how to treat the output of the 'echo' statement as a file without having to create a temporay file to store the value.

提交回复
热议问题