The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
SYSLOG Source code location jockey007 UNIX for Advanced & Expert Users 3 11-06-2007 05:04 PM
Location code for pdisk Muktesh AIX 1 08-23-2007 07:36 PM
home directory nokia3100 UNIX for Dummies Questions & Answers 1 05-07-2007 03:16 PM
cd into home directory ~ here2learn UNIX for Dummies Questions & Answers 4 04-12-2005 10:20 AM
c++ home directory?? user666 UNIX for Dummies Questions & Answers 3 03-16-2002 09:49 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-22-2007
hks_turbokits hks_turbokits is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 4
Unhappy Home Directory Location Code

Hello All,
I am a teacher at a local high school, and we have put together a small computer and loaded a linux distro onto it for the students to experiment with, because 20 children share the computer, it is hard to keep track of there home directorys,

i was wondering if i could find a script for the location of the users home directory, so i could load a terminal, type in the command followed by the users name, and i could find where the users home directory is, i know i can see it in the /ect/password, but a script would be much easier

any help would be greatly appriciated
  #2 (permalink)  
Old 10-22-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
from a bash shell do the following


Code:
echo ~username

so if you have user fred, try


Code:
echo ~fred

  #3 (permalink)  
Old 10-22-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Also, you should have standard rules for managing the computer, for example, putting all home directories under "/home" or similar, so fred's home directory should be "/home/fred".
  #4 (permalink)  
Old 10-28-2007
hks_turbokits hks_turbokits is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 4
thanks, but is there another way of doing it through the bash shell?
Maybe Using the Grep Command and the Cut Command to Give Me and Entire Line of Information from the etc/Passwd on the user?

thanks

Last edited by hks_turbokits; 10-28-2007 at 09:01 AM..
  #5 (permalink)  
Old 10-28-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
The mechanism I have shown you is the simplest. You are welcome to make things more complex for yourself.
  #6 (permalink)  
Old 10-29-2007
earnstaf earnstaf is offline
Registered User
  
 

Join Date: May 2007
Posts: 113
Quote:
Originally Posted by porter View Post
The mechanism I have shown you is the simplest. You are welcome to make things more complex for yourself.
As porter said, this is more difficult and gets the same results as his suggestion, but if you really wanted to grep and cut the /etc/passwd file you could:

Code:
grep username /etc/passwd | cut -d ":" -f 6

or awk

Code:
grep username /etc/passwd | awk 'BEGIN {FS="[:]"} { print $6 }'

  #7 (permalink)  
Old 10-29-2007
hks_turbokits hks_turbokits is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 4
Almost Finished....

Thanks for your help so far guys, im almost done now, there is just one bit i need help with, i would like it to display a reply for a user who doesnt exist, such as, User Not found or similar

This is my code so far

Code:
echo "Which Users home directory to you want to locate?"
read Username
grep "^$Username" /etc/passwd | cut -d ":" -f 6

I was reading somewhere about a case or something
something about using

Code:
if [ $? -eq 0  ]



Thanks Again
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0