在Ubuntu中,cp -r
(而不是copirdir
)是用于复制目录及其内容的命令。以下是如何正确使用cp -r
的步骤:
cp -r [选项] 源目录 目标目录
复制单个目录及其内容到另一个位置
cp -r /path/to/source/directory /path/to/destination/directory
这会将source/directory
及其所有子目录和文件复制到destination/directory
。
覆盖目标目录中的同名文件
默认情况下,如果目标目录中已经存在同名文件,cp -r
会提示你是否覆盖。你可以使用-f
(强制)选项来避免提示:
cp -rf /path/to/source/directory /path/to/destination/directory
保留文件属性
使用-p
选项可以保留文件的权限、时间戳和其他属性:
cp -rp /path/to/source/directory /path/to/destination/directory
递归复制并显示详细信息
使用-v
(verbose)选项可以在复制过程中显示详细信息:
cp -rv /path/to/source/directory /path/to/destination/directory
排除特定文件或目录
如果你想排除某些文件或目录,可以使用--exclude
选项:
cp -rv --exclude='*.log' /path/to/source/directory /path/to/destination/directory
通过以上步骤和示例,你应该能够在Ubuntu中正确使用cp -r
命令来复制目录及其内容。