What does `cat passwd | awk -F':' '{printf $1}'` do?
What does this command do? How do I see that in the terminal because I don't have anything when I write cat passwd | awk -F':' '{printf $1}'
cat passwd
outputs the contents of a file named passwd
in the current directory. The awk
command then parses it, splits each line with :
as the field separator and prints the first field.
If you don't get any output, either:
- there is no file named
passwd
in the current directory - there is a file, but it is empty
- there is a file, but the first fields of all lines in it are empty (the lines begin with
:
).
What the command presumably is meant to do is parse /etc/passwd
. In which case, you can do:
awk -F: '{print $1}' /etc/passwd
Further, unless you want to restrict the command to local accounts, uses getent passwd
instead of using the /etc/passwd
file:
getent passwd | awk -F: '{print $1}'
I assume this is a malformed command to extract all usernames from the system:
-
cat passwd
prints the output of the filepasswd
, presumably/etc/passwd
. -
awk -F':' {printf $1}
separates the input (given by cat) using:
as a delimiter and then only prints the first token, i.e. the username.
It doesn't work because /etc
is not in the path variable by default, so the path would have to be given, not just the file name. Also, the result wouldn't be parsable properly, as awk's printf
doesn't put newlines at the end, as opposed to print
.
The IMO correct command would look like this:
cat /etc/passwd | awk -F':' '{print $1}'