I’ve been trying the following:
cut -d: -f3 | last -1 /etc/passwd
and
last -1 | cut -d: -f3 /etc/passwd
These statements aren’t working, I’m not sure how to join both of them to get the result I want. It just takes the current command that is in front of the /etc/passwd directory.
I’m fairly new to Linux and combining commands together.
Thank you for the help in advance.
Advertisement
Answer
Try:
cut -d: -f3 /etc/passwd | tail -1
Or:
tail -1 /etc/passwd | cut -d: -f3
Notes
The command
last
shows a listing of last logged in users. By contrast,tail
provides the end of a file andtail -1
provides just the last line.Consider this command:
cut -d: -f3 | last -1 /etc/passwd
This runs
cut -d: -f3
but since in file names are provided,cut
will wait for you to provide input on stdin. This is not what you want. By contrast, the command below provides the file/etc/passwd
as input tocut
and then selects the last line of cut’s output:cut -d: -f3 /etc/passwd | tail -1