user3320668
user3320668

Reputation: 23

shell how to find last entry in /etc/passwd

I am trying to write my own shell script to add a user in Linux. I don´t want to use useradd. So how to I find the last entry in passwd ? I would like to check the USER ID, and GROUP ID. So i can make +1 to UISER ID and +1 Group ID.

Or is there any possibility to make a grep on the last entry in a file?

e.G.

simpson:x:103:103:Lisa Simpson, etc...

Upvotes: 0

Views: 946

Answers (2)

Panta
Panta

Reputation: 199

With sed:

sed -n '$'p /etc/passwd

http://www.gnu.org/software/sed/manual/sed.html#tail

Upvotes: 0

Paul R
Paul R

Reputation: 212939

Just use tail:

tail -1 /etc/passwd

Upvotes: 3

Related Questions