我需要一个命令(可能是cp的一个选项)来创建目标目录(如果目标目录不存在)。
例子:
cp -? file /path/to/copy/file/to/is/very/deep/there
我需要一个命令(可能是cp的一个选项)来创建目标目录(如果目标目录不存在)。
例子:
cp -? file /path/to/copy/file/to/is/very/deep/there
当前回答
install -D file -m 644 -t /path/to/copy/file/to/is/very/deep/there
其他回答
简单地没有创建脚本和简单的命令…
mkdir -p /destination-folder/ && cp file-name /destination-folder/
仅适用于macOS
rsync -R <source file path> destination_folder
对于macOS -父母cp选项不工作
这对我来说很有用
cp -vaR ./from ./to
我尊重上面的答案,我更喜欢使用rsync如下所示:
$ rsync -a directory_name /path_where_to_inject_your_directory/
例子:
$ rsync -a test /usr/local/lib/
我也有同样的问题。我的方法是把这些文件压缩成一个存档,就像这样:
tar cf你档案。tar file1 /path/to/file2路径/to/even/deeper/file3
Tar自动将文件存储在归档文件中的适当结构中。如果你跑了
Tar xf your_archive.tar
文件被提取到所需的目录结构中。