Posted: . At: 12:14 PM. This was 1 year ago. Post ID: 17482
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


How to list all users in the /etc/passwd file.


Listing users in the /etc/passwd file is very easy. This example below will list all users with a UID 1000 or over and have a home directory under /home.

(base) ┌─jason-Lenovo-H50-55@jason⬎
└─◉ 5.1-~-11:27-⚫ ◉--[$]awk -F: '$6 ~ "^/home/" && $4 > 999 {print $1}' /etc/passwd
jason
cudauser
mike

Quite a useful one-liner.

To list all home directories sorted by disk space usage, this one-liner will be perfect.

(base) ┌─jason-Lenovo-H50-55@jason⬎
└─◉ 5.1-~-11:41-⚫ ◉--[$]find /home/* -maxdepth 0 -type d -exec du -sh {} + | sort -hr
103G	/home/jason
20K	/home/cudauser
16K	/home/mike

This is great for tracking disk usage.

This is another, shorter version.

(base) ┌─jason-Lenovo-H50-55@jason⬎
└─◉ 5.1-~-11:42-⚫ ◉--[$]du -sh /home/* | sort -hr
103G	/home/jason
20K	/home/cudauser
16K	/home/mike

Works just as well though.

To determine which groups on Linux a user belongs to, use this command. This will return this information.

(base) ┌─jason-Lenovo-H50-55@jason⬎
└─◉ 5.1-~-12:10-⚫ ◉--[$]grep "jason" /etc/group | awk -F ":" '{print $1}'
adm
cdrom
sudo
dip
video
plugdev
lpadmin
lxd
jason
sambashare

Could be a very useful tip.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.