Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
nfs /dev/sda4我想使用 shell 脚本在 conf 文件中搜索模式。如果存在,我只需要忽略它,如果不存在,我需要添加该模式
nfs /dev/sda4
nfs /dev/sda4如果在文件中找不到该行,这将在文件顶部插入该行:
grep -q 'nfs /dev/sda4' file || sed -i 'i\nfs \/dev\/sda4' file
或在底部:
grep -q 'nfs /dev/sda4' file || sed -i '$a\nfs \/dev\/sda4' file