bash mkdir: 无法创建目录: 没有那个文件或目录 - cifs windows 共享文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42368727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mkdir: cannot create directory: No such file or directory - cifs windows shared folder
提问by Dan Ruxton
I have a linux box here that i've set up with a cifs shared folder to my windows computer. No issues there, it works exactly as intended. However, i thought about running some bash scripts using that same directory and it seems like it's not finding my root.
我在这里有一个 linux 盒子,我已经在我的 windows 计算机上设置了一个 cifs 共享文件夹。没有问题,它完全按预期工作。但是,我想过使用同一个目录运行一些 bash 脚本,但它似乎没有找到我的根目录。
now=$(date +"%Y-%m-%d")
#or: `now=$(date +%s)` if you back up more than once a day
mkdir /__backup/"$now"
Doing this from the shared folder brings up that it cannot find directory runningthese commands:
从共享文件夹执行此操作会导致它找不到运行这些命令的目录:
echo "#!/bin/bash
now=`date "+%Y-%m-%d"`
mkdir "/__backup/$now"
"
dirname "#!/bin/bash
now=`date "+%Y-%m-%d"`
mkdir -p "/__backup/$now" # -p creates parent directories as needed (see man mkdir)
#Optional: change directory to the one you just created:
cd /__backup/$now
"
shows the address as "."
将地址显示为“.”
Does anyone have any ideas on how to get this to run?
有没有人对如何让它运行有任何想法?
回答by SIGSTACKFAULT
You are doing:
你在做:
if [ `whoami` = "root" ]; then
# You are root...
else
echo "Error: Only root can do that."
exit 1
fi
So this only works if /__backup/
exists. Do:
所以这只有在/__backup/
存在时才有效。做:
Of course, you will need root to make a directory in /
, so you might want to check for that.
当然,您需要 root 在 中创建目录/
,因此您可能需要检查一下。
You can avoid the whole problem of needing root if you create __backup
in ~
. You might also want to hide __backup
by renaming it to .backup
.
如果您__backup
在~
. 您可能还想__backup
通过将其重命名为.backup
.