mkdir: cannot create directory `**': No such file or directory

简介: 在mkdir时报错的解决方案,在网上找了很多文章都没有说清楚原因。

mkdir时报错的解决方案,在网上找了很多文章都没有说清楚原因。

mkdir: cannot create directory `/home/image_path/201908/23/': No such file or directory

我的脚本很简单,在指定目录生成年月和日,如果不存在则创建。

#!/bin/bash
date_str=`date +%Y%m`
date_str1=`date +%d`
dir=/home/image_path
function run_mkcurrent_dir(){
my_dir="$dir/$date_str/$date_str1/"
if [ ! -d "$my_dir" ]; then
        echo "创建文件夹"
        mkdir -p $my_dir
else
        echo "文件夹已存在"
fi
}
run_mkcurrent_dir;

报错的原因是: mkdir创建多级目录时需要加参数 p,

这个参数的意义:- p 可以是一个路径名称。此时若路径中的某些目录尚不存在,加上此选项后,系统将自动建立好那些尚不存在的目录,即一次可以建立多个目录。

目录
相关文章
|
应用服务中间件
./configure *: No such file or directory
今天在CentOS下安装Nginx时,遇到了类似以下的问题: ./configure auto/unix: No such file or directory ./configure auto/options: No such file or directory 之前在另一台服务器上安装的时候也没有遇到此问题, 安装过程参考:CentOS6.5下Nginx1.7.4安装记录 于是网上搜索解决方案,但是搜索了很久也没有找到解决方案, 当我使用“mkdir auto/unix”之后,还是提示类似的错误,但目录名又变了。
3411 0
|
10月前
|
Shell
adb: error: cannot create file/directory ‘d:/1.png‘: No such file or directory
adb: error: cannot create file/directory ‘d:/1.png‘: No such file or directory
173 0
|
Ubuntu Shell
bash: No such file or directory
bash: No such file or directory
183 0
ftok info: No such file or directory
ftok info: No such file or directory
275 0
|
JavaScript
The file is in the program because: Imported via xxx Root file specified for compilation Vetur(1261)
The file is in the program because: Imported via xxx Root file specified for compilation Vetur(1261)
225 0
The file is in the program because: Imported via xxx Root file specified for compilation Vetur(1261)
objdump: ‘1443.14.0)‘: No such file or directory
objdump: ‘1443.14.0)‘: No such file or directory
123 0
No such file or directory
No such file or directory
349 0
No such file or directory
curses.h: No such file or directory
curses.h: No such file or directory
143 0
autoreconf: failed to run autopoint: No such file or directory
autoreconf: failed to run autopoint: No such file or directory
238 0
|
Linux
【Linux】locate: can not stat () `/var/lib/mlocate/mlocate.db‘: No such file or directory
【Linux】locate: can not stat () `/var/lib/mlocate/mlocate.db‘: No such file or directory
249 0
【Linux】locate: can not stat () `/var/lib/mlocate/mlocate.db‘: No such file or directory