Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I note a strange behavior of mv/cp on Linux. The directories A and A/. should be equivalent but as arguments for the source they seem to behave differently. Is that a bug? Of course you could ask why should I use A/. instead of A as source but sometimes one wants "." as source and the same strange things happen... Maybe someone knows an answer.

Let's start with

$ mkdir A A/A1 B

and now

variant 1)

$ cp -r A B
$ ls B
A

All right.

variant 2)

$ cp -r A/. B
$ ls B
A1

Why "A1" and not "A"?

variant 3)

$ mv A B
$ ls B
A

All right.

variant 4)

$ mv -i A/. B
mv: overwrite `B/.'? y
mv: cannot move `A/.' to `B/.': Device or resource busy

strange...

share|improve this question
    
@SachinDivekar You have mkdir -p aliased. –  Daniel Beck Dec 6 '11 at 12:15
    
@DanielBeck sorry my bad. forgot -p –  Sachin Divekar Dec 6 '11 at 12:26
    
on the other note, no need to mkdir A A/A1 B you can just do mkdir -p A/A1 B it will create A and A/A1 automatically. –  Sachin Divekar Dec 6 '11 at 12:26
add comment

1 Answer

"A" and "A/." are both directory entries that point to the same thing, but they are themselves different things. "A" is an entry in the current directory, and "A/." is an entry named "." in the A directory. Think of it as operating on a box from the outside, vs. operating on the box from the inside.

Specifically,

cp -r A B

Copies A into B.

cp -r A/. B

Goes into the directory A and copies the contents of the current directory (i.e. ./A1) into B.

mv A B

Moves the directory entry named "A" from the current directory into B.

mv -i A/. B

Tries to move the directory entry "." out of A into B. However, there's already an entry named "." in B. In general, you can't move "." (that's like trying to move the box from the inside).

share|improve this answer
add comment

Your Answer

 
discard

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.