linux shell命令中cp时判断文件夹是否存在解决cannot create regular file ‘…’: No such file or directory
直接使用cp命令时,如果新的路径不存在则会报错
cannot create regular file ‘…’: No such file or directory
所以要先判断文件夹是否存在,然后再使用cp
复制文件并且判断新文件夹是否存在,不存在则新建文件夹再复制
#!/bin/bash
#获取新路径的文件夹
path=$(dirname $2)
#判断将新路径的文件夹是否存在
if [ ! -d "${path}" ]; then
echo "创建目录:${path}"
mkdir -p "${path
原创
2020-07-04 11:14:04 ·
11178 阅读 ·
0 评论