How best to extract the users home from /etc/password


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How best to extract the users home from /etc/password
# 1  
Old 03-23-2005
How best to extract the users home from /etc/password

What would be the best way to extract a users home from /etc/passwd. I intended to use cut but have been semi advised that a can do it using and eval statement and the ~ operator. Unfortunately this was just a casual conversation so made little sense at the time. Any help much appreciated.

cheers
# 2  
Old 03-23-2005
Look at the password file on your machine.

Type:
cat /etc/passwd at the prompt. Entries in /etc/passwd look something like this:

arushkin:Igljf78DS:132:20:Amy Rushkin:/usr/people/arushkin:/bin/csh
trsmith:*:543:20:Trent Smith, sys adm:/usr/people/trsmith/:/bin/tcsh

To extract a field, where NAME is set to the UserID of the user you are trying to query.

awk -v NAME=${NAME} 'BEGIN{FS=":"} /NAME/ {print $7}'

or

cat /etc/passwd | awk -F ":" '{print $7}'

Last edited by google; 03-23-2005 at 10:39 AM..
# 3  
Old 03-23-2005
Quote:
Originally Posted by google
cat /etc/passwd | awk -F ":" '{print $7}'
Would that be a UUOC?

Code:
awk -F\: '{print $7}' /etc/passwd 

or 

awk -F\: '/username/{print $7}'  /etc/passwd 

or

awk -F\: '/'${USERNAME}'/{print $7}'  /etc/passwd

where username in the second example is replaced by the user you want to search for.

Last edited by reborg; 03-23-2005 at 11:36 AM.. Reason: spelling
# 4  
Old 03-23-2005
A user's home directory can be found by using tide-expansion,e.g...
Code:
echo ~username

dir=~username
echo $dir

# 5  
Old 03-30-2006
its ok i have solved it

cat /etc/passwd | awk -F ":" '{print $6}' #this displays 6th field ie home directories

awk -F\: '{print $6}' /etc/passwd |grep pauline #this displays pauline home directory

or echo ~pauline.fowler

thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Permissions on a directory in /home for all users

Hi, I have created a shared directory on /home, where all users on a certain group have read, write and execute permissions. I did this using chmod -R g+rwx /home/shared/ The problem is, when a particular user creates a directory within /home/shared, other users are not able to write to... (8 Replies)
Discussion started by: lost.identity
8 Replies

2. UNIX for Advanced & Expert Users

Files disappearing from /users/home

We have seen an issue whereby every morning around the same time , we see files being deleted from /users/$userid . We have many crons and processes running across 40+ different servers . Possibly some rogue process is doing this . How can one isolate the process removing stuff from the... (4 Replies)
Discussion started by: taherkf
4 Replies

3. Cybersecurity

ssh many users to one home

Hey guys, Hmm.. I'm not quite sure where to open this. If any mod thinks this is not the place, please move it to wherever its suited :) So, I want to allow some trusted users to scp files into my server (to an specific user), but I do not want to give these users a home, neither ssh... (1 Reply)
Discussion started by: flpgdt
1 Replies

4. Solaris

Common Home directory for different users??

Hi Guys, I have a problem with configuring a server. this is a solaris 10 with sparc platform. I have setup so that the server is Authenticating through NIS but I dont want the server to Mount the Home directories. The users need to logged in through the CDE/display. I have over 200 users... (2 Replies)
Discussion started by: Luky
2 Replies

5. UNIX for Dummies Questions & Answers

lost /home/directory for users

I'm using HPUX 11i. The other day a user logon to the workstation and was not able to find the /home/directory (tom is the directory) I login myself and it is the same thing. The home directory is on the server, so I was thinking of using sam to map it again. does anyone know how to do it... (5 Replies)
Discussion started by: blizzgamer
5 Replies

6. Solaris

Can't create users in /home

Hi Friends,, I installed solaris 10 in vmware just now.I got a simple problem while i want to create users in /home directory.It is saying "cannot create ".So i checked the permission and then i find that the perm to user(root) is r-x.So i tried to change it to rwx using chmod but again i got a... (4 Replies)
Discussion started by: sdspawankumar
4 Replies

7. UNIX for Dummies Questions & Answers

Home Directory Jail for Users

Hi, I am looking for a shell script (or any other way), that puts a user in a home directory jail. So for example, I have a user named richard and I don't want him wandering outside /usr/users/richard. I don't want him to cd to anywhere including cd .. Somebody said you can do that with... (3 Replies)
Discussion started by: mz043
3 Replies

8. HP-UX

Home dir for users

Hello all, Most of our users have the same home directory, I know it's weird but it has been like this before me and we don't want to change that for now. When creating a new user using command useradd, it is not allowing me to create it because it is using the home directory of someone else. I... (2 Replies)
Discussion started by: qfwfq
2 Replies

9. AIX

HACMP users home directories

What would be the best approach to configure one external /home f/s in simple two node config and have concurrent access ? (1 Reply)
Discussion started by: zz2kzq
1 Replies

10. UNIX for Dummies Questions & Answers

Profiles for users without home directory

Hi I want to know which profile will be called when a user without home directory is created. When I created a user without home directory(by setting in /etc/default/useradd), the user is able to login directly into the main "/" folder but with only read permissions. Thanks naina (3 Replies)
Discussion started by: naina
3 Replies
Login or Register to Ask a Question