Home Directory Location Code

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Home Directory Location Code
# 1  
Old 10-22-2007
Data 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  
Old 10-22-2007
from a bash shell do the following

echo ~username

so if you have user fred, try

echo ~fred

# 3  
Old 10-22-2007
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  
Old 10-28-2007
thanks, but is there another way of doing it through the bash shell? Smilie
Maybe Using the Grep Command and the Cut Command to Give Me and Entire Line of Information from the etc/Passwd on the user?


Last edited by hks_turbokits; 10-28-2007 at 11:01 AM..
# 5  
Old 10-28-2007
The mechanism I have shown you is the simplest. You are welcome to make things more complex for yourself.
# 6  
Old 10-29-2007
Originally Posted by porter
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:
grep username /etc/passwd | cut -d ":" -f 6

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

# 7  
Old 10-29-2007
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
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
if [ $? -eq 0  ]


Thanks Again
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

SunOS confusing root directory and user home directory

Hello, I've just started using a Solaris machine with SunOS 5.10. After the machine is turned on, I open a Console window and at the prompt, if I execute a pwd command, it tells me I'm at my home directory (someone configured "myuser" as default user after init). ... (2 Replies)
Discussion started by: egyassun
2 Replies

2. UNIX for Dummies Questions & Answers

Find the location of particular file and directory

hi all, i am new to UNIX environment. i have a file and directory with same name, i don't know the location I want to find location of that file and directory. please suggest a solution. (5 Replies)
Discussion started by: mahesh1987
5 Replies

3. Shell Programming and Scripting

How to find a existing file location and directory location in Solaris box?

Hi This is my third past and very impressed with previous post replies Hoping the same for below query How to find a existing file location and directory location in solaris box (1 Reply)
Discussion started by: buzzme
1 Replies

4. Shell Programming and Scripting

using find to go directly into a directory location

is there any other useful command to go into a specific directory and not go into its subdirectories that operates similar to find.? (it will return the full pathname?) or is there any way to make find not go into the subdirectories of the specified directory? This is on ksh as well. (3 Replies)
Discussion started by: bjhum33
3 Replies

5. Red Hat

Get up one directory of location as variable

May i know how can i pass up one of a location to a variable in script file with command in stead of hardcode? saying in my script file: maindir = "/opt/xSystem/config" upOneDir = ????? echo $upOneDir I have to use command to pass "/opt/xSystem" to variable upOneDir. Please... (5 Replies)
Discussion started by: cielle
5 Replies

6. Solaris

Restricting SFTP user to a defined directory and home directory

Hi, I've created solaris user which has both FTP and SFTP Access. Using the "ftpaccess" configuration file options "guest-root" and "restricted-uid", i can restrict the user to a specific directory. But I'm unable to restrict the user when the user is logged in using SFTP. The aim is to... (1 Reply)
Discussion started by: sftpuser
1 Replies

7. UNIX for Dummies Questions & Answers

write a directory location

Hi, Just want to be sure that if I write a directory like: /documents/script.pl is the same as to write: /documents//script.pl Thanks in advance (1 Reply)
Discussion started by: fadista
1 Replies

8. UNIX for Dummies Questions & Answers

Copy directory from one location to other

Hi All, I am newbie for Unix. I want to copy a directory from one location to other. Can any one help me by providing the command to do following task. thanks in advance, Rakesh (2 Replies)
Discussion started by: rakeshvthu
2 Replies

9. UNIX for Dummies Questions & Answers

c++ home directory??

when i compile *.cpp files the compiler didn't find the non standart includes.If i have to put the full path of the includet files where shall i begin from root dirctory or i heve to put includet files in cpp home directory??? can i compile java files in unix(linux mandrake 7) if yes haw... (3 Replies)
Discussion started by: user666
3 Replies
Login or Register to Ask a Question