是什么原因导致“目录不为空”?错误?
我编写了一个大部分对我有用的脚本。但是,最后的两个 rmdir
命令有时会返回 Directory notempty
错误。我该如何击败这个?我尝试添加 r
,然后添加 -rf
,这返回了 Illegal option
错误。
我是菜鸟,如果有任何帮助,我将不胜感激。下面是完整的 shell 脚本,它大部分运行得很好:
if [[ -z "${1}" ]]; then
die "FolderName Required"
fi
newDirName="DirectoryName"
newBaseDir="/Users/JSG/Desktop/DataFarm/$1/"
/bin/mkdir -p $newBaseDir/{ProtectedOrig,Data}
echo -n "---Data Folder Setup
---Data Introduction
---Data Audit/Manipulation
---Data Queries" > $newBaseDir/Data/$1_DataJournal.txt
ditto NewData/ NewDataCopy
fab deploy_data_to_s3:data=*
mv NewData/ $newBaseDir/ProtectedOrig/NewData
mv NewDataCopy/ $newBaseDir/Data/NewDataCopy
mv $newBaseDir/Data/NewDataCopy/* $newBaseDir/Data/
rmdir $newBaseDir/Data/NewDataCopy
mv $newBaseDir/ProtectedOrig/NewData/* $newBaseDir/ProtectedOrig/
rmdir $newBaseDir/ProtectedOrig/NewData
chflags -R uchg $newBaseDir/ProtectedOrig/
mkdir NewData
我缺少什么?并提前致谢!
I've written a script that is mostly working for me. However, the two rmdir
commands at the end are sometimes returning Directory not empty
errors. How do I beat this? I tried adding r
and then -rf
which returned Illegal option
errors.
I'm a rookie, and I'd be grateful for any help. Here is the full shell script, which, again, is mostly working beautifully:
if [[ -z "${1}" ]]; then
die "FolderName Required"
fi
newDirName="DirectoryName"
newBaseDir="/Users/JSG/Desktop/DataFarm/$1/"
/bin/mkdir -p $newBaseDir/{ProtectedOrig,Data}
echo -n "---Data Folder Setup
---Data Introduction
---Data Audit/Manipulation
---Data Queries" > $newBaseDir/Data/$1_DataJournal.txt
ditto NewData/ NewDataCopy
fab deploy_data_to_s3:data=*
mv NewData/ $newBaseDir/ProtectedOrig/NewData
mv NewDataCopy/ $newBaseDir/Data/NewDataCopy
mv $newBaseDir/Data/NewDataCopy/* $newBaseDir/Data/
rmdir $newBaseDir/Data/NewDataCopy
mv $newBaseDir/ProtectedOrig/NewData/* $newBaseDir/ProtectedOrig/
rmdir $newBaseDir/ProtectedOrig/NewData
chflags -R uchg $newBaseDir/ProtectedOrig/
mkdir NewData
What am I missing? And thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 rmdir 命令,您需要添加 --ignore-fail-on-non-empty 标志,这样即使文件位于其中,它也会删除目录,如下所示:
您也可以只使用
rm -r
:来自 Wikipedia Entry :
For the
rmdir
command, you need to add the--ignore-fail-on-non-empty
flag so it deletes the directory even if files are in there like so:You could also just use
rm -r
too:From the Wikipedia Entry:
检查目录中是否有以
.
开头的文件。我注意到您正在移动*
,但如果有一个名为.hello
的文件,则*
将与该文件不匹配,并且因此,当您执行 rmdir 时,该目录不会为空。Check for any files in the directory that start with
.
. I note you're moving*
, but if there's a file called, for example,.hello
, then*
will not match this file and as a result the directory will not be empty when you come to do an rmdir.