Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

how to find out the home directory of a user??

Shell Programming and Scripting


Tags
solaris

Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 04-08-2008
wrapster wrapster is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 26 January 2011, 9:16 AM EST
Posts: 194
Thanks: 0
Thanked 0 Times in 0 Posts
how to find out the home directory of a user??

Hi all,
I would like to know how to find out the home directory of a particular user..
eg,
If am the root , then my Home directory will be /
if say am just a user logging into the terminal then my home dir would change,
so accordingly i would like to know how to find it out...

I know that the shell prompt changes accordingly but how to figure it out through a command?, I mean is there any command to find out the home directory of a particular user(be it the root or an average joe!!!)
Sponsored Links
    #2  
Old Unix and Linux 04-08-2008
DukeNuke2's Unix or Linux Image
DukeNuke2 DukeNuke2 is offline Forum Staff  
Soulman
 
Join Date: Jul 2006
Last Activity: 30 June 2015, 4:33 PM EDT
Location: Berlin, Germany
Posts: 5,498
Thanks: 61
Thanked 247 Times in 240 Posts
there are many ways....


Code:
$ cd
$ pwd

$ echo $HOME

$ grep username /etc/passwd

hth,
DN2
Sponsored Links
    #3  
Old Unix and Linux 04-08-2008
wrapster wrapster is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 26 January 2011, 9:16 AM EST
Posts: 194
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,
I forgot to mention, i would like to know how to incorporate it into a script..
I mean how to give input to $HOME so that depending upon the username the $HOME gives me the home dir...

I must also mention, i will not be running as root...
    #4  
Old Unix and Linux 04-08-2008
joeyg's Unix or Linux Image
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Last Activity: 22 June 2015, 10:58 AM EDT
Location: Within two miles of a Dunkin donuts.
Posts: 2,356
Thanks: 85
Thanked 163 Times in 149 Posts
Hammer & Screwdriver One approach

>find_user="somebody"

>cat /etc/passwd | grep "$find_user" | cut -c":" -f6
Sponsored Links
    #5  
Old Unix and Linux 04-08-2008
danmero danmero is offline Forum Advisor  
 
Join Date: Nov 2007
Last Activity: 12 October 2014, 10:11 AM EDT
Location: H3X
Posts: 2,151
Thanks: 10
Thanked 118 Times in 111 Posts
awk only

Code:
awk -F: -v v="user" '{if ($1==v) print $6}' /etc/passwd


Last edited by danmero; 04-08-2008 at 12:28 PM..
Sponsored Links
    #6  
Old Unix and Linux 04-08-2008
DukeNuke2's Unix or Linux Image
DukeNuke2 DukeNuke2 is offline Forum Staff  
Soulman
 
Join Date: Jul 2006
Last Activity: 30 June 2015, 4:33 PM EDT
Location: Berlin, Germany
Posts: 5,498
Thanks: 61
Thanked 247 Times in 240 Posts
how do you authenticate your users? local files, ldap or nis? if local files, give an exampel of your "/etc/passwd".

on solaris works something like this:


Code:
# grep username /etc/passwd | cut -d ":" -f6
/export/home/username

Sponsored Links
    #7  
Old Unix and Linux 04-08-2008
wrapster wrapster is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 26 January 2011, 9:16 AM EST
Posts: 194
Thanks: 0
Thanked 0 Times in 0 Posts
I dont think awk and all will be necessary,(its for some ppl who dont know about awk )
Not yet taught ,i suppose!!!!(so will have to make do with "if and else" only....

ive just written this pls have a look!!!

for i in $*
do
cat /etc/passwd |grep $i | cut -d ":" -f 6
done

Here how to i specify a constraint stating that if no arg is passed it should return an error?
I tried with simple ,
if test -z $i ; then
echo "error"
else
//proceed...

how do i get something like this working?
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Home Directory for oracle user beayni33 Solaris 1 02-10-2011 01:06 PM
User's home directory jredx Red Hat 5 05-05-2010 09:10 AM
Restricting SFTP user to a defined directory and home directory sftpuser Solaris 1 10-16-2009 07:00 PM
Specifying FTP user Home Directory annointed3 UNIX for Dummies Questions & Answers 0 04-05-2007 09:52 PM
resrtrict user to his home directory xiamin UNIX for Dummies Questions & Answers 4 09-27-2001 06:36 AM



All times are GMT -4. The time now is 08:48 AM.