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

【背景】
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
参考:
结果是必须用
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
参考:
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
参考:
搜:
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也还是很多细节做得有问题啊。
 
注:
如果想要查看,当前哪个程序打开了,占用了,要删除的文件夹,则可以去参考:
去试试
lsof==list open files==列出(当前系统)打开(的)文件
具体如何可以参考:



发表评论

电子邮件地址不会被公开。 必填项已用*标注

无觅相关文章插件,快速提升流量