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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to find out the home directory of a user??
# 8  
Old 04-08-2008
You should avoid cat of a single file. Grep can read the file just fine, you don't need cat to feed it.

Code:
#!/bin/sh

case $# in 0) echo foo: need an argument >&2; exit 1;; esac

for i in "$@"; do
  grep "$i" /etc/passwd | cut -d: -f6
done

Pay attention to the quoting; you want to avoid throwing an error if somebody calls your script with a string with spaces in it, or (worse yet) an actual shell command which gets executed and has dire side effects (think `rm -rf $HOME` in backticks).

You should probably actually grep "^$i:" to avoid accidentally printing the wrong information because of a coincidental substring match. (True story: grep era /etc/passwd would find "System Operator" and print root's home directory on BSD.)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 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. Shell Programming and Scripting

Trying to delete a user and home directory

Good Afternoon, I'm trying userdel -r username on Solaris 9 and getting UX: userdel: ERROR: unable to find status about home directory: No such file or directory I see the user's home directory and getent passwd shows the user Anybody know what's causing it? (2 Replies)
Discussion started by: Stellaman1977
2 Replies

3. UNIX for Dummies Questions & Answers

User's home directory not being created

I am trying to create Oracle user. I will install oracle after that. But my problem is /home/oracle directory is not being created. bash-3.2# useradd -g oinstall -G dba,oper -d /home/oracle -m oracle cp: /home/oracle: Operation not applicable chown: /home/oracle: No such file or directory ... (3 Replies)
Discussion started by: hubatuwang
3 Replies

4. UNIX for Dummies Questions & Answers

Restricting a user to their home directory and below

I found this old closed thread: I can do these things, but how to I change someone's profile - where do I find the profile? I'm running Centos 5.6 ~~~~~~~~~ providing you have the password shell set to ksh, you can put this in his .profile: cd /opt/load alias -x cd=: (6 Replies)
Discussion started by: jjj0923
6 Replies

5. Solaris

Home Directory for oracle user

Hello all, I am Installing Oracle 11g on my Solaris OS. I created the below oracle user: # /usr/sbin/useradd -g oinstall -G dba oracle but when i am trying to to su - oracle it give me the below error No directory Do i have to setup a home directory for oracle user? and how can i do... (1 Reply)
Discussion started by: beayni33
1 Replies

6. Red Hat

User's home directory

Hi, By default user's home directory will be /home/$user. I want to change it to /javauser/$user. How can I do it? Thanks Jeevan. (5 Replies)
Discussion started by: jredx
5 Replies

7. 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

8. UNIX for Dummies Questions & Answers

Specifying FTP user Home Directory

Hi, I am running Solaris 10 and I am using the ftp server that comes with it. I would like to specify a specific directory as ftp user's home directory. For example, if "ftpuserx" ftps into my solaris machine, they will automatically be taken to "/space/web" directory, even though there... (0 Replies)
Discussion started by: annointed3
0 Replies

9. UNIX for Dummies Questions & Answers

user home directory problem

The home directory for me on my system is on /home/kwon. It was created using "useradd kwon" When i go to change the home directory for a user doing a usermod -d /home/test when they log on it gives them messages saying to generate new ssh keys, and it does. It gives me a thing that says... (1 Reply)
Discussion started by: BangYourWallnut
1 Replies

10. UNIX for Advanced & Expert Users

How can I forbid a user to go up his home directory

Hi everybody, How can I forbid a user to go up his home directory ? Thanks MarcoW (2 Replies)
Discussion started by: MarcoW
2 Replies
Login or Register to Ask a Question
SSS_USERADD(8)							 SSSD Manual pages						    SSS_USERADD(8)

NAME
sss_useradd - create a new user SYNOPSIS
sss_useradd [options] LOGIN DESCRIPTION
sss_useradd creates a new user account using the values specified on the command line plus the default values from the system. OPTIONS
-u,--uid UID Set the UID of the user to the value of UID. If not given, it is chosen automatically. -c,--gecos COMMENT Any text string describing the user. Often used as the field for the user's full name. -h,--home HOME_DIR The home directory of the user account. The default is to append the LOGIN name to /home and use that as the home directory. The base that is prepended before LOGIN is tunable with "user_defaults/baseDirectory" setting in sssd.conf. -s,--shell SHELL The user's login shell. The default is currently /bin/bash. The default can be changed with "user_defaults/defaultShell" setting in sssd.conf. -G,--groups GROUPS A list of existing groups this user is also a member of. -m,--create-home Create the user's home directory if it does not exist. The files and directories contained in the skeleton directory (which can be defined with the -k option or in the config file) will be copied to the home directory. -M,--no-create-home Do not create the user's home directory. Overrides configuration settings. -k,--skel SKELDIR The skeleton directory, which contains files and directories to be copied in the user's home directory, when the home directory is created by sss_useradd. Special files (block devices, character devices, named pipes and unix sockets) will not be copied. This option is only valid if the -m (or --create-home) option is specified, or creation of home directories is set to TRUE in the configuration. -Z,--selinux-user SELINUX_USER The SELinux user for the user's login. If not specified, the system default will be used. -?,--help Display help message and exit. THE LOCAL DOMAIN
In order to function correctly, a domain with "id_provider=local" must be created and the SSSD must be running. The administrator might want to use the SSSD local users instead of traditional UNIX users in cases where the group nesting (see sss_groupadd(8)) is needed. The local users are also useful for testing and development of the SSSD without having to deploy a full remote server. The sss_user* and sss_group* tools use a local LDB storage to store users and groups. SEE ALSO
sssd(8), sssd.conf(5), sssd-ldap(5), sssd-krb5(5), sssd-simple(5), sssd-ipa(5), sssd-ad(5), sssd-sudo(5),sss_cache(8), sss_debuglevel(8), sss_groupadd(8), sss_groupdel(8), sss_groupshow(8), sss_groupmod(8), sss_useradd(8), sss_userdel(8), sss_usermod(8), sss_obfuscate(8), sss_seed(8), sssd_krb5_locator_plugin(8), sss_ssh_authorizedkeys(8), sss_ssh_knownhostsproxy(8),pam_sss(8). AUTHORS
The SSSD upstream - http://fedorahosted.org/sssd SSSD
06/17/2014 SSS_USERADD(8)