pan*_*zia 1078 command-line cp
我正在尝试使用终端将文件夹的内容复制到不同目录中的另一个文件夹。
有人能够为我提供实现此目的所需的命令行语法示例吗?
enz*_*tib 1609
您可以使用以下命令将文件夹的内容复制/source
到另一个现有文件夹/dest
cp -a /source/. /dest/
Run Code Online (Sandbox Code Playgroud)
该-a
选项是一个改进的递归选项,保留所有文件属性,并保留符号链接。
将.
在源路径的终点是一个特定的cp
语法,允许复制所有文件和文件夹,包括隐藏的人。
Pan*_*her 172
另一种方法是rsync
:
rsync -a source/ destination
Run Code Online (Sandbox Code Playgroud)
的优点rsync
是:
Bru*_*ira 101
比方说你有一个文件夹,名为文件夹1在您的~
,内部的folder1是1个文件调用文件1和2个文件夹叫SUB1和SUB2各自与其他文件和文件夹里面他们。
要将所有内容复制~/folder1
到~/new_folder1
您将使用
cp -r ~/folder1/. ~/new_folder1
Run Code Online (Sandbox Code Playgroud)
new_folder1
然后将包含来自folder1
.
cp
是使用终端复制的命令,-r
使其递归(因此,当前目录+当前内部的其他目录)~/folder1
是原始文件夹,~/new_folder1
是原始文件夹中文件/文件夹的目标文件夹。
Kar*_*son 26
将目录 dir_1 及其内容(文件)复制到目录dir_2 中:
cp -r ./dir_1 ./dir_2
# or
cp -r ./dir_1/ ./dir_2/
# Results in: ./dir_2/dir_1/_files_
Run Code Online (Sandbox Code Playgroud)
复制唯一的内容(文件DIR_1的)进入目录DIR_2:
cp -r ./dir_1/. ./dir_2
# or
cp -r ./dir_1/. ./dir_2/
# Results in: ./dir_2/_files_
Run Code Online (Sandbox Code Playgroud)
_files_
是位于目录中的实际文件的占位符。
Dil*_*mar 17
检查这个http://www.cyberciti.biz/faq/copy-folder-linux-command-line/有关复制文件夹的更多信息。希望这可以帮助。
cp Command
Run Code Online (Sandbox Code Playgroud)
cp
是一个用于复制文件和目录的 Linux 命令。语法如下:
cp source destination
cp dir1 dir2
cp -option source destination
cp -option1 -option2 source destination
Run Code Online (Sandbox Code Playgroud)
在此示例中,将/home/vivek/letters
文件夹及其所有文件复制到/usb/backup
目录:
cp -avr /home/vivek/letters /usb/backup
Run Code Online (Sandbox Code Playgroud)
在哪里,
-a
: 保留指定的属性,例如目录、文件模式、所有权、时间戳,如果可能的话,其他属性:上下文、链接、xattr、所有。
-v
: 解释一下是做什么的。
-r
: 递归复制目录。例子
将名为 /tmp/conf 的文件夹复制到 /tmp/backup:
$ cp -avr /tmp/conf/ /tmp/backup
Run Code Online (Sandbox Code Playgroud)
此带有标志“-R”的代码将“folder1”的所有内容完美复制到现有的“folder2”:
\ncp -R folder1/. folder2\n
Run Code Online (Sandbox Code Playgroud)\n标志“-R”也复制符号链接,但标志“-r”跳过符号链接,因此标志“-R”比标志“-r”更好。
\n-R, --dereference-recursive\n\nFor each directory operand, read and process all files in that directory, \nrecursively, following all symbolic links.\n
Run Code Online (Sandbox Code Playgroud)\n-r, --recursive\n\nFor each directory operand, read and process all files in that directory, \nrecursively. Follow symbolic links on the command line, but skip symlinks \nthat are encountered recursively. Note that if no file operand is given, \ngrep searches the working directory. This is the same as the \n\xe2\x80\x98--directories=recurse\xe2\x80\x99 option.\n
Run Code Online (Sandbox Code Playgroud)\n
我喜欢这个命令
\n\nrsync -av --progress ~/code/project-source/. ~/code/project-destination --exclude .git --exclude node_modules\n
Run Code Online (Sandbox Code Playgroud)\n\n\n\n\n下面列出了 rsync 命令中的一些常用选项:
\n