Append a text to the end of multiple files in Linux

前端 未结 6 1428
囚心锁ツ
囚心锁ツ 2021-02-05 01:05

I need to append the following code to the end to all the php files in a directory and its sub directory:

6条回答
  •  误落风尘
    2021-02-05 01:35

    You can do (Work even if there's space in your file path) :

    #!/bin/bash
    
    # Create a tempory file named /tmp/end_of_my_php.txt
    cat << EOF > /tmp/end_of_my_php.txt
    
    EOF find . -type f -name "*.php" | while read the_file do echo "Processing $the_file" #cp "$the_file" "${the_file}.bak" # Uncomment if you want to save a backup of your file cat /tmp/end_of_my_php.txt >> "$the_file" done echo echo done

    PS: You must run the script from the directory you want to browse

提交回复
热议问题