V
V
Vladislav2014-09-15 14:37:32
linux
Vladislav, 2014-09-15 14:37:32

linux. How to copy the contents of one folder to another in the terminal without creating an extra subfolder in the second?

Example. The ~/test1/ folder contains the fld1 subfolder and the text.txt file. You need to copy them to the ~/test2/ folder, in which something already lies.
If ~/test2 does not exist, then cp -a ~/test1 ~/ test2 will work correctly, but in my case (when ~/test2/ already exists), a subfolder is created with the name of the original. That is, a copy of the text file will be located in ~/test2/test1/text.txt

[email protected] ~ $ ls tes*
test1:
fld1 text.txt
test2:

[email protected] ~ $ cp -a ~/test1/ ~/test2/
[email protected] ~ $ ls tes*
test1:
fld1 text.txt
test2:
test1

[email protected] ~ $ ls ~/test2/test1/
fld1 text.txt

What is the key to suppress such strange behavior for me? cp can be replaced with rsync or something similar, Linux Mint (Debian) distribution.
Under Windows, the following similar command works correctly:
C:\>xcopy c:\temp\test1 c:\temp\test2 /i /e
C:\Temp\test1\text.txt
Скопировано файлов: 1
C:\>dir C:\Temp\test2
 Том в устройстве C имеет метку Локальный диск
 Серийный номер тома: *******

 Содержимое папки C:\Temp\test2

15.09.2014  15:24    <DIR>          .
15.09.2014  15:24    <DIR>          ..
15.09.2014  15:07    <DIR>          fld
12.08.2014  18:12               877 text.txt
1 файл   877 байт
3 папки  ***** байт свободно

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Denis, 2014-09-15
@Sabin

cp -av test1/* test2/
«test1/file» -> «test2/file»
«test1/test3» -> «test2/test3»

P
Power, 2014-09-15
@Power

cp -iaT ~/test1 ~/test2

S
serg Kro, 2014-09-15
@Karadar

cp -R ** won't work?
ls tes*
test1:
fld1 text
test2:
something fld1 text

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question