如何在bash文件夹中的每个文件的开头添加字符串? [英] How can I add a string to the beginning of each file in a folder in bash?

查看:125
本文介绍了如何在bash文件夹中的每个文件的开头添加字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在文件夹中每个文本文件的开头添加一个字符串.如何在Linux上使用bash做到这一点?

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?

推荐答案

这将完成此操作.如果您对每个文件使用相同的文本,则可以提高效率.

This will do that. You could make it more efficient if you are doing the same text to each file...

for f in *; do 
  echo "whatever" > tmpfile
  cat $f >> tmpfile
  mv tmpfile $f
done

这篇关于如何在bash文件夹中的每个文件的开头添加字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆