LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Line numbers in /etc/sudoers file ? (https://www.linuxquestions.org/questions/linux-general-1/line-numbers-in-etc-sudoers-file-4175414173/)

redhat70 06-30-2012 11:30 AM

Line numbers in /etc/sudoers file ?
 
Hi,

How to get the Line numbers in /etc/sudoers file ?

sudo: >>> /usr/local/etc/sudoers: syntax error near line 39 <<<
sudo: >>> /usr/local/etc/sudoers: syntax error near line 55 <<<
sudo: >>> /usr/local/etc/sudoers: syntax error near line 57 <<<
sudo: parse error in /usr/local/etc/sudoers near line 39

How to find the Line numbers 39,55,57 in /etc/sudoers file ?

Is their any command to display the line numbers in /etc/sudoers file ?

Please help me in knowing that command.

Regards,
Aparna.

acid_kewpie 06-30-2012 12:17 PM

well that's nothign to do with sudo, just the text editor you decide to use. Under vi (and so for visudo) just type ":39" in command mode.

towheedm 06-30-2012 12:20 PM

You can use the 'nl' utility to number the lines:
Code:

nl -nln /usr/local/etc/sudoers
I'm not quite sure if sudo count blank lines, if so:
Code:

nl -ba -nln /usr/local/etc/sudoers
will number blank lines.

You can pass it through grep:
Code:

nl -nln /usr/local/etc/sudoers | grep -E "(^39|^55|^57)"
or you may need to add the -ba option to number blank lines.

Hope it helps.

TobiSGD 06-30-2012 12:42 PM

Just for completeness: You wouldn't have problems with syntax errors in the sudoers file if you would edit in the recommended way using visudo.

anomie 07-01-2012 05:21 PM

Quote:

Originally Posted by TobiSGD
... if you would edit in the recommended way using visudo.

Bingo. Use visudo(8). After launching it, if you still want to see line numbers, use the sequence:
  1. Esc
  2. :
  3. set nu
  4. Enter

(Well, technically, that's assuming "Defaults editor" is set to nvi(1) or vim(1). If not, then use cat(1) with -n option to see line numbers.)


All times are GMT -5. The time now is 12:56 PM.