我需要一个命令(可能是cp的一个选项)来创建目标目录(如果目标目录不存在)。
例子:
cp -? file /path/to/copy/file/to/is/very/deep/there
我需要一个命令(可能是cp的一个选项)来创建目标目录(如果目标目录不存在)。
例子:
cp -? file /path/to/copy/file/to/is/very/deep/there
当前回答
我强烈建议你也这么做。 只是工作。
同样,my/location/poo .txt this/doesn /exist/yet/poo .txt
其他回答
rsync file /path/to/copy/file/to/is/very/deep/there
如果您有正确的rsync类型,这可能会起作用。
只是恢复和给出一个完整的工作解决方案,在一行。 如果您想要重命名文件,请注意,您应该包括一种方法来提供到mkdir的干净dir路径。$fdst可以是file或dir。 下一段代码在任何情况下都可以工作。
fsrc=/tmp/myfile.unk
fdst=/tmp/dir1/dir2/dir3/myfile.txt
mkdir -p $(dirname ${fdst}) && cp -p ${fsrc} ${fdst}
或者特定于bash
fsrc=/tmp/myfile.unk
fdst=/tmp/dir1/dir2/dir3/myfile.txt
mkdir -p ${fdst%/*} && cp -p ${fsrc} ${fdst}
我强烈建议你也这么做。 只是工作。
同样,my/location/poo .txt this/doesn /exist/yet/poo .txt
我尊重上面的答案,我更喜欢使用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
文件被提取到所需的目录结构中。