3

I accidentally added a user to my system without a home directory (I forgot to put the -d and -m flags in useradd). Rather than deleting the user and starting over I attempted to simply mkdir the home directory and copy over the files myself from /etc/skel. However, I received the following strange error:

user@host:~$ sudo cp -rv /etc/skel/* /home/newuser/
cp: cannot stat `/etc/skel/*': No such file or directory

However, the following two commands work as expected:

user@host:~$ sudo cp -rv /etc/skel/.bashrc /home/newuser/
user@host:~$ cp -rv ~/testfolder1/* /testfolder2/

Can anyone shed some light on why I received that initial error.

2 Answers 2

3

The /etc/skel directory typically contains only hidden files, that is, those whose name start with a period. The shell expansion of * does not include hidden files unless an option is set for it do so. For bash, this option is set with shopt -s dotglob.

In your case /etc/skel/* is not expanding to anything, so the shell leaves the argument as /etc/skel/*, but there is not file by that name.

5

When a glob expression (/etc/skel/*) expands to no files, then by default the expression is left in the command as a plain string. In this case it expands to no files because all the files in /etc/skel are dot files. So you were trying to copy the literal file "*" in /etc/skel, and that file does not exist.

See http://www.gnu.org/software/bash/manual/bashref.html#Filename-Expansion

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .