I
I
Intelide2016-07-22 06:59:24
linux
Intelide, 2016-07-22 06:59:24

How to add line to linux files with script?

Hello, there are files in the directory
file1.conf
file2.conf
file3.conf
you need to add a new line with text to all files, is it possible to do this?
thanks in advance

Answer the question

In order to leave comments, you need to log in

6 answer(s)
S
Saboteur, 2016-07-22
@Intelide

Вот так будет работать и в ksh и в bash и в zsh:
echo "строка" | tee -a file*.conf

Назар Мокринский, 2016-07-22
@nazarpc

echo "тут строка" >> file1.conf

S
strelmax, 2016-07-22
@strelmax

echo "ваша строка" | tee -a file1.conf file2.conf file3.conf
либо так
for i in {1.conf,2.conf,3.conf};do echo "ваша строка" >> $i;done

A
abcd0x00, 2016-07-22
@abcd0x00

sed -i -s '$a text' *.txt

Пример
[[email protected] t]$ ls
file1.txt  file2.txt  file3.txt
[[email protected] t]$ 
[[email protected] t]$ cat file1.txt 
a
[[email protected] t]$ cat file2.txt 
b
[[email protected] t]$ cat file3.txt 
c
[[email protected] t]$ 
[[email protected] t]$ sed -i -s '$a text' *.txt
[[email protected] t]$ 
[[email protected] t]$ cat file1.txt 
a
text
[[email protected] t]$ cat file2.txt 
b
text
[[email protected] t]$ cat file3.txt 
c
text
[[email protected] t]$

A
Azazel PW, 2016-07-22
@azazelpw

console
ls -1 /path >> list.file
bash
echo `ls -1 /path` >> list.file

I
Igor Nikolaev, 2016-07-22
@nightvich

zsh перкрасно ест:
echo "ololololo" >> *.txt

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question