我想添加以下行:
nohup java -jar /mnt/fusion/nfs/labStats/LabInfoAutoLog.jar > /dev/null &
/etc/rc.d/rc.local
如果文件不存在,则到文件末尾。
我怎样才能从linux命令行做到这一点?我假设grep
或sed
会工作,但我对任何一个都不够熟悉,无法让它工作。现在我使用echo
,但这只是一遍又一遍地添加它。
假设您希望它在文件末尾:
LINE="nohup java -jar /mnt/fusion/nfs/labStats/LabInfoAutoLog.jar > /dev/null &"
FILE=/etc/rc.d/rc.local
grep -q "$LINE" "$FILE" || echo "$LINE" >> "$FILE"
one option is two steps:
grep -q "yourline" /path/file||sed -i '/..place../ a \the line' file
also possible to do with awk,
save all lines in array, during saving if the line was found, exit. otherwise, add the line in END{}
block to the right place.
P.S. You didn't tell in the file, where to add that line.