[SOLVED] How to commet out specific lines of text?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello ladies and gents, im trying to commet out tty2-tty63 in /etc/securetty (to disable unneeded terminals for security reasons). But everything that I have previously tried has failed to work.. Any ideas would be much appreciated, thank you! Btw this is what I already tried.
Code:
for i in `cat /etc/securetty|grep tty[2-63]` {1..63}; do
echo "#" >> $i
done
And im sure that's written completely wrong.
Last edited by justmy2cents; 07-26-2017 at 10:09 AM.
Lol I tried.. Anywho thanks, and yeah it's going to be part of a script that does other configuration changes that I don't really want to do by hand, partly cause im a slow typer.
I think a little differently - specify what you want to keep (one line) and comment everything else rather than have to construct potentially ever more complex regex.
Code:
sed -r '/^tty1$/! s/^/#/' /etc/securetty
If you need to accommodate whitespace before the end of record, trivial to add.
I think a little differently - specify what you want to keep (one line) and comment everything else rather than have to construct potentially ever more complex regex.
Code:
sed -r '/^tty1$/! s/^/#/' /etc/securetty
If you need to accommodate whitespace before the end of record, trivial to add.
I think both modes of thinking are useful, so thanks that helps too!
file=/etc/securetty
if [ -f $file ]; then
cp -p $file $file.orig &&
sed '/^tty1$/!s/^tty[1-9][0-9]*/#&/' $file.orig >$file
fi
It leaves a .orig file behind.
I keep this one in mind if I need to do this in a work environment or something, but im just doing it in a live install so I not too worried about messing up the file.. Thanks bro!
Last edited by justmy2cents; 07-26-2017 at 11:28 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.