I need to find all users home directories listed using grep from /etc/passwd
You can use cut
to split files with columns on a specific delimiter:
cut -d: -f6 /etc/passwd
Or -f1,6
for columns (fields) 1 and 6.
Grep is really not the tool for parsing out data this way; grep is more for pattern matching and you're trying to do text-processing. You would want to use awk.
awk -F":" '$7 == "/bin/false" {print "User: "$1 "Home Dir: "$6}' /etc/passwd
awk
– The command-F":"
– Sets the data delimiter to:
$7 == "/bin/false"
– Checks if the 7th data column is/bin/false
{print "User: "$1 "Home Dir: "$6}'
– Says to print the first column and sixth column in the specified format./etc/passwd
– Is the file we're processing