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."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With