Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append a text to the end of multiple files in Linux

Tags:

file

bash

unix

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

</div> <div id="preloader" style="display:none;position: absolute;top: 90px;margin-left: 265px;"> <img src="ajax-loader.gif"/> </div> 

I have tried with

echo "my text" >> *.php 

But terminal showed the error:

bash : *.php: ambiguous redirect 

What should I do. there are hundreds of files to add this code segment and it would be a real tough time adding it in each file. Thanks in advance.

like image 887
Harikrishnan Avatar asked Jun 02 '12 21:06

Harikrishnan


People also ask

How do I add text to the end of a file in Linux?

Append Text Using >> Operator The >> operator redirects output to a file, if the file doesn't exist, it is created but if it exists, the output will be appended at the end of the file. For example, you can use the echo command to append the text to the end of the file as shown.


1 Answers

I usually use tee because I think it looks a little cleaner and it generally fits on one line.

echo "my text" | tee -a *.php 
like image 108
Dantastic Avatar answered Sep 29 '22 18:09

Dantastic