分页: 1 / 1

在文件尾追加内容的命令。

发表于 : 2011-12-14 13:53
CuiCan
一般情况下用这个命令就行了:echo "xxxxxx" >>file。
如果要向需要特权的文件(例如,系统配置文件)追加内容怎么办,上面的命令不行啊,sudo echo "xxxxxx" >>file 也不行,可有人知道怎么办?

Re: 在文件尾追加内容的命令。

发表于 : 2011-12-14 14:01
ttand
sudo sh -c "echo xxxxxx >>file"
唉 sudo有时候挺麻烦的

Re: 在文件尾追加内容的命令。

发表于 : 2011-12-14 14:01
mjp123
echo password | sudo echo "Xxxxxxxxxxx" >>file

Re: 在文件尾追加内容的命令。

发表于 : 2011-12-14 15:31
CuiCan
2楼正解。sudo是有些麻烦,不过安全些。3楼的方法不行,结果和 sudo echo "xxxxxx" >>file 一样,都是Permission denied。谢谢了!

Re: 在文件尾追加内容的命令。

发表于 : 2011-12-14 16:05
枫叶饭团
3楼sudo 少了个参数

Re: 在文件尾追加内容的命令。

发表于 : 2011-12-14 16:47
CuiCan
枫叶饭团 写了:3楼sudo 少了个参数
少了什么参数,求解啊 :em06

Re: 在文件尾追加内容的命令。

发表于 : 2011-12-14 16:50
eexpress
-S
多看man

Re: 在文件尾追加内容的命令。

发表于 : 2011-12-14 17:22
CuiCan
哦,结果还是一样。

Re: 在文件尾追加内容的命令。

发表于 : 2011-12-14 17:26
枫叶饭团
也对sudo只对echo提高了权限,重定向却没有。echo和>>用单引号括在一起再看看

Re: 在文件尾追加内容的命令。

发表于 : 2011-12-14 17:58
mjp123
:em01
mjp123 写了:echo password | sudo echo "Xxxxxxxxxxx" >>file
是错了,谢谢指正。
:em01

Re: 在文件尾追加内容的命令。

发表于 : 2011-12-20 13:00
josephyoung
用sed
sudo sed -i '$a xxxxxxxx' urfile

Re: 在文件尾追加内容的命令。

发表于 : 2011-12-20 14:07
josephyoung
又研究出一个新方法,呵呵
echo -e "a\nxxxxxxxxxxxxxx\n.\nwq" | sudo ed -s urfile

Re: 在文件尾追加内容的命令。

发表于 : 2011-12-22 13:18
astolia
echo "text" | sudo tee -a filename

Re: 在文件尾追加内容的命令。

发表于 : 2011-12-26 9:55
HuntXu
用tee才王道