how to find out the home directory of a user?? | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

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

Shell Programming and Scripting


Tags
solaris

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 04-08-2008
DukeNuke2's Avatar
DukeNuke2 DukeNuke2 is online now Forum Staff  
Soulman
 
Join Date: Jul 2006
Last Activity: 27 November 2014, 9:11 AM EST
Location: Berlin, Germany
Posts: 5,427
Thanks: 55
Thanked 231 Times in 224 Posts
there are many ways....


Code:
$ cd
$ pwd

$ echo $HOME

$ grep username /etc/passwd

hth,
DN2
Sponsored Links
    #3  
Old 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 04-08-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Last Activity: 17 November 2014, 3:07 PM EST
Location: Out running a Marathon.
Posts: 2,337
Thanks: 73
Thanked 155 Times in 144 Posts
Hammer & Screwdriver One approach

>find_user="somebody"

>cat /etc/passwd | grep "$find_user" | cut -c":" -f6
Sponsored Links
    #5  
Old 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 117 Times in 110 Posts
awk only

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


Last edited by danmero; 04-08-2008 at 01:28 PM..
Sponsored Links
    #6  
Old 04-08-2008
DukeNuke2's Avatar
DukeNuke2 DukeNuke2 is online now Forum Staff  
Soulman
 
Join Date: Jul 2006
Last Activity: 27 November 2014, 9:11 AM EST
Location: Berlin, Germany
Posts: 5,427
Thanks: 55
Thanked 231 Times in 224 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 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 Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 02:06 PM
User's home directory jredx Red Hat 5 05-05-2010 10:10 AM
Restricting SFTP user to a defined directory and home directory sftpuser Solaris 1 10-16-2009 08:00 PM
Specifying FTP user Home Directory annointed3 UNIX for Dummies Questions & Answers 0 04-05-2007 10:52 PM
resrtrict user to his home directory xiamin UNIX for Dummies Questions & Answers 4 09-27-2001 07:36 AM



All times are GMT -4. The time now is 10:16 AM.