chickegg
chickegg

Reputation: 105

difference between cp

There are two parentdirs A and B with many subdirs and files. While sitting in parentdir B, typing these two commands; What is the difference between them ?

cp -r /path/to/A/* *

and

cp -r /path/to/A/* .

Upvotes: 0

Views: 395

Answers (1)

pobrelkey
pobrelkey

Reputation: 5973

You would never type the first command unless you were reckless:

* on its own expands to the name of every non-hidden file/directory in the current directory. So let's assume that /path/to/A contains two subdirectories (spoon and fork), and the current directory contains three subdirectories (foo, bar and baz). This means the shell would interpret your first command as:

cp -r /path/to/A/fork /path/to/A/spoon bar baz foo

In other words, recursively copy /path/to/A/fork, /path/to/A/spoon, bar and baz into foo (the item in the current directory that happens to come last in alphabetical order). So you'd end up with four new directories under foo: foo/fork, foo/spoon, foo/bar and foo/baz.

Your second command would mean to recursively copy /path/to/A/spoon and /path/to/A/fork into the current directory. This would create two new subdirectories (fork and spoon) in the current directory.

Upvotes: 2

Related Questions