最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】mac的终端中rm无法删除文件夹

Mac系统 crifan 16348浏览 0评论

【背景】
mac的终端中,想要去删除文件夹,结果始终无法删除,加了rf还是不行:
licrifandeMacBook-Pro:ios crifan$ ls -la
total 16
drwxr-xr-x   6 crifan  staff   204  9 23 16:15 .
drwxr-xr-x   4 crifan  staff   136  9 23 16:15 ..
-rw-r--r--@  1 crifan  staff  6148  9 23 16:15 .DS_Store
drwxr-xr-x   7 crifan  staff   238  9 23 16:15 .svn
drwxr-xr-x  10 crifan  staff   340  9 23 16:15 SchoolLike
drwxr-xr-x   3 crifan  staff   102  9 23 16:15 __MACOSX
licrifandeMacBook-Pro:ios crifan$ rm SchoolLike/ -fR
rm: SchoolLike/: is a directory
rm: -fR: No such file or directory
licrifandeMacBook-Pro:ios crifan$ 





【解决过程】
1.搜:
mac 终端 删除文件夹
mac terminal 删除文件夹
mac terminal rm folder
参考:
Master the command line: Deleting files and folders | Macworld
结果是必须用
rmdir
2.结果用rmdir还是不行:
licrifandeMacBook-Pro:ios crifan$ rmdir SchoolLike/
rmdir: SchoolLike/: Directory not empty
licrifandeMacBook-Pro:ios crifan$ rmdir SchoolLike/ -f
rmdir: SchoolLike/: Directory not empty
rmdir: -f: No such file or directory
licrifandeMacBook-Pro:ios crifan$ rmdir --help
rmdir: illegal option -- -
usage: rmdir [-p] directory ...
licrifandeMacBook-Pro:ios crifan$ rm
rm           rmdir        rmic         rmid         rmiregistry 
licrifandeMacBook-Pro:ios crifan$ rm
rm           rmdir        rmic         rmid         rmiregistry 
licrifandeMacBook-Pro:ios crifan$ rmdir --help
rmdir: illegal option -- -
usage: rmdir [-p] directory ...
licrifandeMacBook-Pro:ios crifan$ man rmdir

 
去看man:
RMDIR(1)                  BSD General Commands Manual                 RMDIR(1)

NAME
     rmdir -- remove directories

SYNOPSIS
     rmdir [-p] directory ...

DESCRIPTION
     The rmdir utility removes the directory entry specified by each directory argument, provided it is empty.

     Arguments are processed in the order given.  In order to remove both a parent directory and a subdirectory
     of that parent, the subdirectory must be specified first so the parent directory is empty when rmdir tries
     to remove it.

     The following option is available:

     -p      Each directory argument is treated as a pathname of which all components will be removed, if they
             are empty, starting with the last most component.  (See rm(1) for fully non-discriminant recursive
             removal.)

     The rmdir utility exits with one of the following values:

     0       Each directory entry specified by a dir operand referred to an empty directory and was removed suc-
             cessfully.

 

3.搜:
mac terminal rm non empty folder
参考:
osx – Trying to delete directory with "rm -rf", but get message that it’s not empty – Super User
licrifandeMacBook-Pro:ios crifan$ rmdir -rf SchoolLike/
rmdir: illegal option -- r
usage: rmdir [-p] directory ...
licrifandeMacBook-Pro:ios crifan$ rmdir SchoolLike/ -p
rmdir: SchoolLike/: Directory not empty
rmdir: -p: No such file or directory
licrifandeMacBook-Pro:ios crifan$ rmdir -p SchoolLike/
rmdir: SchoolLike/: Directory not empty



4.搜:
mac os x rm directory not empty
参考:
rmdir(1) Mac OS X Manual Page
搜:
mac terminal删除文件夹
mac terminal删除目录

还是没找到有用的。



5.重启terminal后,再去删除,还是不行:

Last login: Wed Sep 23 16:14:12 on ttys001
licrifandeMacBook-Pro:~ crifan$ cd /Users/crifan/dev/dev_root/chantyou/projects/schoolike/ios/code/ios
licrifandeMacBook-Pro:ios crifan$ pwd
/Users/crifan/dev/dev_root/chantyou/projects/schoolike/ios/code/ios
licrifandeMacBook-Pro:ios crifan$ ls ls
ls: ls: No such file or directory
licrifandeMacBook-Pro:ios crifan$ ls -la
total 16
drwxr-xr-x   6 crifan  staff   204  9 23 16:15 .
drwxr-xr-x   4 crifan  staff   136  9 23 16:15 ..
-rw-r--r--@  1 crifan  staff  6148  9 23 16:15 .DS_Store
drwxr-xr-x   7 crifan  staff   238  9 23 16:15 .svn
drwxr-xr-x  10 crifan  staff   340  9 23 16:15 SchoolLike
drwxr-xr-x   3 crifan  staff   102  9 23 16:15 __MACOSX
licrifandeMacBook-Pro:ios crifan$ rm SchoolLike/ -rf
rm: SchoolLike/: is a directory
rm: -rf: No such file or directory
licrifandeMacBook-Pro:ios crifan$ rmdir SchoolLike/
rmdir: SchoolLike/: Directory not empty
licrifandeMacBook-Pro:ios crifan$ rmdir SchoolLike/ -f
rmdir: SchoolLike/: Directory not empty
rmdir: -f: No such file or directory
licrifandeMacBook-Pro:ios crifan$

后来,好像是:
推出了iOS模拟器:
然后就可以删除文件夹了:

licrifandeMacBook-Pro:ios crifan$ rm -Rf SchoolLike/
licrifandeMacBook-Pro:ios crifan$ ls -la
total 16
drwxr-xr-x  5 crifan  staff   170  9 23 16:34 .
drwxr-xr-x  4 crifan  staff   136  9 23 16:15 ..
-rw-r--r--@ 1 crifan  staff  6148  9 23 16:15 .DS_Store
drwxr-xr-x  7 crifan  staff   238  9 23 16:15 .svn
drwxr-xr-x  3 crifan  staff   102  9 23 16:15 __MACOSX
licrifandeMacBook-Pro:ios crifan$ rm -Rf __MACOSX/
licrifandeMacBook-Pro:ios crifan$ ls -la
total 16
drwxr-xr-x  4 crifan  staff   136  9 23 16:34 .
drwxr-xr-x  4 crifan  staff   136  9 23 16:15 ..
-rw-r--r--@ 1 crifan  staff  6148  9 23 16:15 .DS_Store
drwxr-xr-x  7 crifan  staff   238  9 23 16:15 .svn
licrifandeMacBook-Pro:ios crifan$

看来估计是:

之前的,要删除的文件夹,被iOS模拟器占用了,所以被锁定了,无法删除。

停止占用文件夹的程序,文件夹即可被删除。

 



【总结】
如果当前的文件夹,被别的程序占用的话,用rm是无法删除的
->但是rm不是报错,没有说:别的程序正在使用你要删除的文件夹。
->而只是会说Directory not empty
->搞得以为是rm或rmdir无法删除非空文件夹呢。。。
->Mac中的Terminal中的对于被占用的文件删除的提示,还是做得有问题
->Mac也还是很多细节做得有问题啊。
 
注:
如果想要查看,当前哪个程序打开了,占用了,要删除的文件夹,则可以去参考:
osx – Trying to delete directory with "rm -rf", but get message that it’s not empty – Super User
去试试
lsof==list open files==列出(当前系统)打开(的)文件
具体如何可以参考:
每天一个linux命令(51):lsof命令 – peida – 博客园
3. lsof 一切皆文件 — Linux Tools Quick Tutorial
lsof(8)

转载请注明:在路上 » 【已解决】mac的终端中rm无法删除文件夹

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (2)

  1. 先说一下我这边到“场景”?
    Henny John6年前 (2019-03-14)回复
  2. :mrgreen: 我也遇到类似到问题,我的需求就是要清理废纸篓。 先说一下我这边到“场景”:我之前在Mac上装了虚拟机, 挂载到移动硬盘,然后虚拟机出现问题后,遗留在虚拟机上到废纸篓 具体目录是类似这样的 /Volumes/extradisk 1/.Trashes/废纸篓/一堆后缀为.pvm的文件夹 后来,我把这些家伙移动到根目录,这样废纸篓就干净了。 等有机会挂在windows系统的时候再清理。
    海阔天空6年前 (2019-03-07)回复
86 queries in 0.200 seconds, using 22.07MB memory