The file /etc/passwd has colon-separated fields. Type the complete command that prints only the third field (the UID) of every line, using cut and passing the file as an argument.
LPIC-1 Exam 101-500, objective 103. GNU and Unix commands medium
Draft — not checked yet. This question was written from the published exam objectives and cites the clause it comes from, but nobody has yet read it against that clause and signed for it.
It is kept out of search results and out of mock exams until they have. Read the source below before you take the answer as settled.
Answer
Type the answer.
Accepted answers
cut -d: -f3 /etc/passwdcut -d: -f 3 /etc/passwdcut -d : -f3 /etc/passwdcut -d : -f 3 /etc/passwdcut -d ':' -f3 /etc/passwdcut -d ':' -f 3 /etc/passwdcut -d':' -f3 /etc/passwdcut -d':' -f 3 /etc/passwdcut -d ":" -f3 /etc/passwdcut -d":" -f3 /etc/passwdcut -f3 -d: /etc/passwdcut -f 3 -d: /etc/passwdcut --delimiter=: --fields=3 /etc/passwd
Case sensitive — Linux is, and grading LS as ls would teach a falsehood.
Why
cut -d sets the field delimiter and -f selects the fields; -f3 is one field, -f1,3 a list, -f1-3 a range. Without -d, cut assumes TAB, which is why cutting fields out of a space-aligned listing usually fails. -c selects character positions instead of fields.
Where this comes from
- Cited
- LPI exam objective 103.2
- What it says
- Extract fields from a delimited text stream with cut.
Practise this
Reading one question is not practice. The trainer will draw a set from objective 103 and space the ones you get wrong.