是什么原因导致“目录不为空”?错误?

发布于 2024-12-09 06:17:31 字数 1020 浏览 0 评论 0原文

我编写了一个大部分对我有用的脚本。但是,最后的两个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

桃酥萝莉 2024-12-16 06:17:31

对于 rmdir 命令,您需要添加 --ignore-fail-on-non-empty 标志,这样即使文件位于其中,它也会删除目录,如下所示:

rmdir --ignore-fail-on-non-empty $newBaseDir/Data/NewDataCopy

您也可以只使用 rm -r

rm -r $newBaseDir/Data/NewDataCopy

来自 Wikipedia Entry :

在 UNIX 中,如果目录不为空,rmdir 将不会删除该目录。递归删除目录及其所有内容的正确方法是使用 rm 命令。

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:

rmdir --ignore-fail-on-non-empty $newBaseDir/Data/NewDataCopy

You could also just use rm -r too:

rm -r $newBaseDir/Data/NewDataCopy

From the Wikipedia Entry:

rmdir will not remove a directory if it is not empty in UNIX. The correct way to remove a directory and all its contents recursively is with the rm command.

温折酒 2024-12-16 06:17:31

检查目录中是否有以 . 开头的文件。我注意到您正在移动 *,但如果有一个名为 .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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文