简体   繁体   中英

How to update all the files under the current directory in Ubuntu with some comments at the start of the files

I have an issue where in, I am trying to add copyrights message in all our files in the project. Since it will affect many directories and files, our team has split the task. so each on of us will be updating the files manually. Can I automate it.

I tried with:
find -exec sed -i "1i # x CONFIDENTIAL\n# _____________________\n#\n# 1997 - 2012 x Incorporated\n# All Rights Reserved.\n#\n# NOTICE: All information contained herein is, and remains\n# the property of x Incorporated and its suppliers,\n# if any. The intellectual and technical concepts contained\n# herein are proprietary to x Incorporated\n# and its suppliers and may be covered by US and Foreign Patents,\n# patents in process, and are protected by trade secret or copyright law.\n# Dissemination of this information or reproduction of this material\n# is strictly forbidden unless prior written permission is obtained\n# from x Incorporated.\n" -- {} \;

It just stops, as soon as it encounters the. folder and any folder under the current directory.

Can we control the command to affect some of the files in the directory by specifying the complete/partial name of the file?

You can do so by executing the following commands for each file:

cp file temp
cat copy_right_notice temp > file

Note that > overwrites file (while >> appends to file, which is not what you want (referring to your comment))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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