Skip to main content
added 114 characters in body
Source Link

Here is a bit of somewhat hairy bash code to similarly sort the shadow/gshadow files safely (using vipw -s/vigr -s) and in-place from the command line:

EDITOR="/usr/bin/vi -c \"1,\\\$!awk 'BEGIN {FS = \\\":\\\"} FNR==NR {x2[\\\$1] = \\\$0; next} \\\$1 in x2 {print x2 [\\\$1]x2[\\\$1]}' - /etc/passwdpasswd\" ^V^J
:wq\"-c \"wq! \" >/dev/null 2>&1" vipw -s

EDITOR="/usr/bin/vi -c \"1,\\\$!awk 'BEGIN {FS = \\\":\\\"} FNR==NR {x2[\\\$1] = \\\$0; next} \\\$1 in x2 {print x2 [\\\$1]x2[\\\$1]}' - /etc/groupgroup\" ^V^J
-c \"wq! :wq\"\" >/dev/null 2>&1" vigr -s

NOTE:

  1. ^V^J is CtrlVCtrlJ which generates a new line - this new line is needed to separate the vim command lines.
  2. vi -c passes the command to the vim editor which is assigned to be the editor for vipw/vigr by the EDITOR variable
  3. The awk code sorts shadow by passwd (and gshadow by group)
  4. The backslashes are just the multiple levels of escape needed corresponding to the quotation levels.
  5. The second command (-c "wq! ") force writes and closes the sorted file. The force is necessary since shadow/gshadow are often mode 000 (i.e unwritable). Note the space between '!' and '' is necessary to prevent interpretation by the shell as '!' which references a bash event.

Here is a bit of somewhat hairy bash code to similarly sort the shadow/gshadow files safely (using vipw -s/vigr -s) and in-place from the command line:

EDITOR="/usr/bin/vi -c \"1,\\\$!awk 'BEGIN {FS = \\\":\\\"} FNR==NR {x2[\\\$1] = \\\$0; next} \\\$1 in x2 {print x2 [\\\$1]}' - /etc/passwd ^V^J
:wq\" >/dev/null 2>&1" vipw -s

EDITOR="/usr/bin/vi -c \"1,\\\$!awk 'BEGIN {FS = \\\":\\\"} FNR==NR {x2[\\\$1] = \\\$0; next} \\\$1 in x2 {print x2 [\\\$1]}' - /etc/group ^V^J
  :wq\" >/dev/null 2>&1" vigr -s

NOTE:

  1. ^V^J is CtrlVCtrlJ which generates a new line - this new line is needed to separate the vim command lines.
  2. vi -c passes the command to the vim editor which is assigned to be the editor for vipw/vigr by the EDITOR variable
  3. The awk code sorts shadow by passwd (and gshadow by group)
  4. The backslashes are just the multiple levels of escape needed corresponding to the quotation levels.

Here is a bit of somewhat hairy bash code to similarly sort the shadow/gshadow files safely (using vipw -s/vigr -s) and in-place from the command line:

EDITOR="/usr/bin/vi -c \"1,\\\$!awk 'BEGIN {FS = \\\":\\\"} FNR==NR {x2[\\\$1] = \\\$0; next} \\\$1 in x2 {print x2[\\\$1]}' - /etc/passwd\" -c \"wq! \" >/dev/null 2>&1" vipw -s

EDITOR="/usr/bin/vi -c \"1,\\\$!awk 'BEGIN {FS = \\\":\\\"} FNR==NR {x2[\\\$1] = \\\$0; next} \\\$1 in x2 {print x2[\\\$1]}' - /etc/group\" -c \"wq! \" >/dev/null 2>&1" vigr -s

NOTE:

  1. vi -c passes the command to the vim editor which is assigned to be the editor for vipw/vigr by the EDITOR variable
  2. The awk code sorts shadow by passwd (and gshadow by group)
  3. The backslashes are just the multiple levels of escape needed corresponding to the quotation levels.
  4. The second command (-c "wq! ") force writes and closes the sorted file. The force is necessary since shadow/gshadow are often mode 000 (i.e unwritable). Note the space between '!' and '' is necessary to prevent interpretation by the shell as '!' which references a bash event.
fixed formatting
Source Link
Olorin
  • 4.7k
  • 1
  • 15
  • 25

Here is a bit of somewhat hairy bash code to similarly sort the shadow/gshadow files safely (using vipw -svipw -s/vigr -svigr -s) and in-place from the command line:

EDITOR="/usr/bin/vi -c \"1,\\\$!awk 'BEGIN {FS = \\\":\\\"} FNR==NR {x2[\\\$1] = \\\$0; next} \\\$1 in x2 {print x2 [\\\$1]}' - /etc/passwd ^V^J
:wq\" >/dev/null 2>&1" vipw -s

EDITOR="/usr/bin/vi -c \"1,\\\$!awk 'BEGIN {FS = \\\":\\\"} FNR==NR {x2[\\\$1] = \\\$0; next} \\\$1 in x2 {print x2 [\\\$1]}' - /etc/group ^V^J
  :wq\" >/dev/null 2>&1" vigr -s

NOTE:

  1. ^V^J^V^J is [control-V][control-J]CtrlVCtrlJ which generates a new line - this new line is needed to separate the vim command lines.
  2. 'vi -c'vi -c passes the command to the vim editor which is assigned to be the editor for vipwvipw/vigrvigr by the EDITOREDITOR variable
  3. The awk code sorts 'shadow'shadow by 'passwd'passwd (and 'gshadow'gshadow by 'group;group)
  4. The backslashes are just the multiple levels of escape needed corresponding to the quotation levels.

Here is a bit of somewhat hairy bash code to similarly sort the shadow/gshadow files safely (using vipw -s/vigr -s) and in-place from the command line:

EDITOR="/usr/bin/vi -c \"1,\\\$!awk 'BEGIN {FS = \\\":\\\"} FNR==NR {x2[\\\$1] = \\\$0; next} \\\$1 in x2 {print x2 [\\\$1]}' - /etc/passwd ^V^J
:wq\" >/dev/null 2>&1" vipw -s

EDITOR="/usr/bin/vi -c \"1,\\\$!awk 'BEGIN {FS = \\\":\\\"} FNR==NR {x2[\\\$1] = \\\$0; next} \\\$1 in x2 {print x2 [\\\$1]}' - /etc/group ^V^J
:wq\" >/dev/null 2>&1" vigr -s

NOTE:

  1. ^V^J is [control-V][control-J] which generates a new line - this new line is needed to separate the vim command lines.
  2. 'vi -c' passes the command to the vim editor which is assigned to be the editor for vipw/vigr by the EDITOR variable
  3. The awk code sorts 'shadow' by 'passwd' (and 'gshadow' by 'group;)
  4. The backslashes are just the multiple levels of escape needed corresponding to the quotation levels.

Here is a bit of somewhat hairy bash code to similarly sort the shadow/gshadow files safely (using vipw -s/vigr -s) and in-place from the command line:

EDITOR="/usr/bin/vi -c \"1,\\\$!awk 'BEGIN {FS = \\\":\\\"} FNR==NR {x2[\\\$1] = \\\$0; next} \\\$1 in x2 {print x2 [\\\$1]}' - /etc/passwd ^V^J
:wq\" >/dev/null 2>&1" vipw -s

EDITOR="/usr/bin/vi -c \"1,\\\$!awk 'BEGIN {FS = \\\":\\\"} FNR==NR {x2[\\\$1] = \\\$0; next} \\\$1 in x2 {print x2 [\\\$1]}' - /etc/group ^V^J
  :wq\" >/dev/null 2>&1" vigr -s

NOTE:

  1. ^V^J is CtrlVCtrlJ which generates a new line - this new line is needed to separate the vim command lines.
  2. vi -c passes the command to the vim editor which is assigned to be the editor for vipw/vigr by the EDITOR variable
  3. The awk code sorts shadow by passwd (and gshadow by group)
  4. The backslashes are just the multiple levels of escape needed corresponding to the quotation levels.
added 308 characters in body
Source Link

Here is a bit of somewhat hairy bash code to similarly sort the shadow/gshadow files safely (using vipw -s/vigr -s) and in-place from the command line:

EDITOR="/usr/bin/vi -c "1,\$!awk 'BEGIN {FS = \":\"} FNR==NR {x2[\$1] = \$0; next} \$1 in x2 {print x2 [\$1]}' - /etc/passwd ^V^J :wq" >/dev/null 2>&1" vipw -s

EDITOR="/usr/bin/vi -c \"1,\\\$!awk 'BEGIN {FS = \\\":\\\"} FNR==NR {x2[\\\$1] = \\\$0; next} \\\$1 in x2 {print x2 [\\\$1]}' - /etc/passwd ^V^J
:wq\" >/dev/null 2>&1" vipw -s

EDITOR="/usr/bin/vi -c \"1,\\\$!awk 'BEGIN {FS = \\\":\\\"} FNR==NR {x2[\\\$1] = \\\$0; next} \\\$1 in x2 {print x2 [\\\$1]}' - /etc/group ^V^J
:wq\" >/dev/null 2>&1" vigr -s

EDITOR="/usr/bin/vi -c "1,\$!awk 'BEGIN {FS = \":\"} FNR==NR {x2[\$1] = \$0; next} \$1 in x2 {print x2 [\$1]}' - /etc/group ^V^J NOTE:wq" >/dev/null 2>&1" vigr -s

NOTE ^V^J is which generates a new line - this new line is needed to separate the vim command lines.

  1. ^V^J is [control-V][control-J] which generates a new line - this new line is needed to separate the vim command lines.
  2. 'vi -c' passes the command to the vim editor which is assigned to be the editor for vipw/vigr by the EDITOR variable
  3. The awk code sorts 'shadow' by 'passwd' (and 'gshadow' by 'group;)
  4. The backslashes are just the multiple levels of escape needed corresponding to the quotation levels.

Here is a bit of somewhat hairy bash code to similarly sort the shadow/gshadow files safely (using vipw -s/vigr -s) and in-place from the command line:

EDITOR="/usr/bin/vi -c "1,\$!awk 'BEGIN {FS = \":\"} FNR==NR {x2[\$1] = \$0; next} \$1 in x2 {print x2 [\$1]}' - /etc/passwd ^V^J :wq" >/dev/null 2>&1" vipw -s

EDITOR="/usr/bin/vi -c "1,\$!awk 'BEGIN {FS = \":\"} FNR==NR {x2[\$1] = \$0; next} \$1 in x2 {print x2 [\$1]}' - /etc/group ^V^J :wq" >/dev/null 2>&1" vigr -s

NOTE ^V^J is which generates a new line - this new line is needed to separate the vim command lines.

Here is a bit of somewhat hairy bash code to similarly sort the shadow/gshadow files safely (using vipw -s/vigr -s) and in-place from the command line:

EDITOR="/usr/bin/vi -c \"1,\\\$!awk 'BEGIN {FS = \\\":\\\"} FNR==NR {x2[\\\$1] = \\\$0; next} \\\$1 in x2 {print x2 [\\\$1]}' - /etc/passwd ^V^J
:wq\" >/dev/null 2>&1" vipw -s

EDITOR="/usr/bin/vi -c \"1,\\\$!awk 'BEGIN {FS = \\\":\\\"} FNR==NR {x2[\\\$1] = \\\$0; next} \\\$1 in x2 {print x2 [\\\$1]}' - /etc/group ^V^J
:wq\" >/dev/null 2>&1" vigr -s

NOTE:

  1. ^V^J is [control-V][control-J] which generates a new line - this new line is needed to separate the vim command lines.
  2. 'vi -c' passes the command to the vim editor which is assigned to be the editor for vipw/vigr by the EDITOR variable
  3. The awk code sorts 'shadow' by 'passwd' (and 'gshadow' by 'group;)
  4. The backslashes are just the multiple levels of escape needed corresponding to the quotation levels.
Source Link
Loading