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”之后,还是提示类似的错误,但目录名又变了。
3066 0
|
5月前
|
Python
ERROR: file or directory not found: xx.py
​ 1、问题出现原因 在vscode中已导入pytest框架,做自动化demo小测试,运行Python文件一直出现如题错误,截图如下: ERROR: file or directory not found: xx.py  2、解决办法 1)直接把该文件移到当前主目录下,放在PYTHON-STUDY下 2)VSCode中右键tuopan.py文件,选择[在集成终端中打开],或者通过CD命令进入到tuopan.py文件所在目录 然后输入以下命令即可: 注:上述命令不是换行,在d:/前有空格 ,第一行信息为python所在安装路径,空格后的换行为运行的python文件的所在路径  
71 0
|
9月前
ftok info: No such file or directory
ftok info: No such file or directory
102 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)
123 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
80 0
curses.h: No such file or directory
curses.h: No such file or directory
99 0
autoreconf: failed to run autopoint: No such file or directory
autoreconf: failed to run autopoint: No such file or directory
135 0
|
存储
AUX_SOURCE_DIRECTORY
AUX_SOURCE_DIRECTORY
117 0
|
分布式计算 安全 Hadoop
hdfs mkdir报错Cannot create directory /usr. Name node is in safe mode.
hdfs mkdir报错Cannot create directory /usr. Name node is in safe mode.
242 0
No such file or directory
No such file or directory
213 0
No such file or directory