Actually, you could just grep the username in /etc/passwd as well. The issue with doing:
Code:
ls -ln /home/username
If /home/username had been mistakenly chowned to the wrong user, which has happened, you'll get the wrong UID and GID. It's better to just grep the password file:
Code:
grep username /etc/passwd
That will show the UID and GID for that user.
To show an example, let's say I have the user monkey I created and want that user's UID and GID, but someone mistakenly chowned the /home/monkey directory to the system's bug4 user. When I do ls -ld, I would get:
Code:
# ls -ln /home/monkey
total 48
drwx------ 8 513 510 4096 Oct 17 14:12 ./
drwx--x--x 16 0 0 4096 Oct 17 14:12 ../
lrwxrwxrwx 1 513 510 30 Oct 17 14:12 access-logs -> /usr/local/apache/domlogs/bug4/
-rw-r--r-- 1 513 510 33 Oct 17 14:12 .bash_logout
-rw-r--r-- 1 513 510 176 Oct 17 14:12 .bash_profile
-rw-r--r-- 1 513 510 124 Oct 17 14:12 .bashrc
drwxr-xr-x 2 513 510 4096 Oct 17 14:12 etc/
drwxr-x--- 8 513 510 4096 Oct 17 14:12 mail/
drwxr-xr-x 3 513 510 4096 Oct 17 14:12 public_ftp/
drwxr-x--- 3 513 510 4096 Oct 17 14:12 public_html/
drwxr-xr-x 9 513 510 4096 Oct 17 14:12 rails_apps/
drwxr-xr-x 7 513 510 4096 Oct 17 14:12 tmp/
lrwxrwxrwx 1 513 510 11 Oct 17 14:12 www -> public_html/
I might then mistakenly believe 513 is the UID and 510 the GID for the monkey user. If I instead check /etc/passwd, I get this:
Code:
# grep monkey /etc/passwd
monkey:x:32009:32011::/home/monkey:/usr/local/cpanel/bin/noshell
Then to see the 513 UID, I would do:
Code:
# grep 513 /etc/passwd
bug4:x:513:510::/home/bug4:/usr/local/cpanel/bin/noshell
As a final note, it's better if you just want to see the top level of a directory to add the -d flag to ls, so you'd do:
Code:
# ls -lnd /home/monkey
drwx------ 8 513 510 4096 Oct 17 14:12 /home/monkey/
This way you don't see all the contents.