Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to understand the significance of the dot in bash and how it differs from an asterisk. Can someone please elaborate? For example, what's the difference between cp -ar /foo/. /foo2/ and cp -pr /foo/* /foo2/

share|improve this question
up vote 9 down vote accepted

The dot (.) is just the . directory inside a directory which is the same as the directory itself (ls -la /foo will show it to you). So if you copy foo/. elsewhere, you effectively copy all the tree below foo without copying foo itself (you're copying it into foo2/. which is the same as foo2).

/foo/* is expanded by the shell to the list of non-hidden files and directories in /foo, so it would copy the same directory structure under /foo into /foo2 as well, except for the dotfiles/dotdirs. Effectively, cp will receive (potentially) many arguments. If the list is too big, it may even cause the execution of cp to fail.

share|improve this answer
Sorry but I'm getting confused. So by nature, the asterisk makes the command recursive? In other words cp -r /foo/* does the same thing as cp /foo/* ? – Mike B Jan 21 '13 at 21:28
@MikeB, no, the shell only expands the list of files in the /foo directory. It doesn't alter the behavior of cp. Use set -x or echo cp -pr /foo/* /foo2 to see what's going on. It's important to realise that it's the shell that expands the wildcards. cp doesn't see the star. – Stéphane Chazelas Jan 21 '13 at 21:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.