
我有一個這樣結構的目錄,
/var/www/html/content/
|_dir1/
| |_somefile.txt
| |_anotherfile.js
| |_anotherfile.min.js
|
|_dir2/
|_somefile.txt
|_anotherfile.js
|_anotherfile.min.js
我想複製dir1
並dir2
到另一個目錄。我已嘗試使用以下命令,但它將整個content
目錄複製到新位置。我只需要裡面的目錄content
就在那裡。
cd ~/Desktop/new_location/
cp -r /var/www/html/content/. ./
更新2
兩個都,
cp -r /var/www/html/content/. ./
和
cp -r /var/www/html/content/* ./
工作正常。我錯誤地content
在content
目錄中包含了另一個目錄,使其成為/var/www/html/content/content
更新1
在新目錄的第一個答案中使用@Appleoddity 發布的命令是有效的。但在我需要複製的實際目錄上它失敗了。這可能是什麼原因?檢查所附圖片。
答案1
cp -R /var/www/html/content/* /tmp/new_location/
.
意思是「這個」目錄。
*
表示「此」目錄中的所有內容。
答案2
你的 Linux 發行版是什麼?我使用 ubuntu 16.04.3,它的工作原理是:
cp -r /var/www/html/content/* /tmp/new_location/
-r
且-R
結果相同:)