I need a bash script command to look in /etc/fstab and find the line that contains a mount name "/mymount" and just puts a "#" at the beginning of the line to comment it out.
from this:
/dev/lv_mymount /mymount ext4 defaults 1 2
to this (with a #):
#/dev/lv_mymount /mymount ext4 defaults 1 2
sed -i '/[/]mymount/ s/^/#/' /etc/fstab
How it works:
-i
Edit the file in-place
/[/]mymount/
Select only lines that contain /mymount
s/^/#/
For those selected lines, place at the beginning of the line, ^
, the character #
.
awk '/[/]mymount/{$0="#"$0} 1' /etc/fstab >/etc/fstab.tmp && mv /etc/fstab.tmp /etc/fstab
How it works:
/[/]mymount/ {$0="#"$0}
For those lines containing /mymount
and place a #
at the beginning of the line.
1
This is awk's cryptic shorthand for "print each line."
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.