命令学习·rm

使用到的代码样式功能来源于在线代码美化 (atelier-heath.light)

handso@GNU×Linux:~$ cd Documents/
handso@GNU×Linux:~/Documents$ ls
test.html

现在Documents目录下只有一个test.html

handso@GNU×Linux:~/Documents$ vi hh.html
handso@GNU×Linux:~/Documents$ ls
hh.html  test.html

新增hh.html, 现在一共有两个文件。

handso@GNU×Linux:~/Documents$ rm -i test.html hh.html 
rm: remove regular file 'test.html'? y
rm: remove regular file 'hh.html'? y
handso@GNU×Linux:~/Documents$ ls

注意1: rm加上-i后面可以跟上当前目录下的文件,中间用空格隔开,也可以跟上../Happy/Emoji.txt 这种其他目录下的文件,总之就是一个命令艹遍所有文件树。显而易见和可视化的Finder窗口化比起来是强大了两百倍吧。

注意2:-i可以 确认一下是否一定要删除,y/n 选择一下就ok。

注意3: ls后没有内容——说明命令有用,尽管没有告诉你「Baby,successful!Cheers!」

在GUN/Linux 的系统设计观念中,「无」就是正确——这意味着要求使用者对自己的行为要负责,它只会忠实的执行你的想法和命令,而不会限制你做什么。
handso@GNU×Linux:~/Documents$ mkdir test1 test2
handso@GNU×Linux:~/Documents$ ls
test1  test2
handso@GNU×Linux:~/Documents$ mkdir test1/1 test2/a
handso@GNU×Linux:~/Documents$ ls
test1  test2
handso@GNU×Linux:~/Documents$ cd test1
handso@GNU×Linux:~/Documents/test1$ ls
1
handso@GNU×Linux:~/Documents/test1$ mkdir 2
handso@GNU×Linux:~/Documents/test1$ ls
1  2
handso@GNU×Linux:~/Documents/test1$ cd 2
handso@GNU×Linux:~/Documents/test1/2$ ls
handso@GNU×Linux:~/Documents/test1/2$ vi hehehe.txt
handso@GNU×Linux:~/Documents/test1/2$ ls
hehehe.txt
handso@GNU×Linux:~/Documents/test1/2$ cd ../../
handso@GNU×Linux:~/Documents$ ls
test1  test2

以上这一大段概括起来大概是生成了这么一个东西:

handso@GNU×Linux:~/Documents$ rm -i test1
rm: cannot remove 'test1': Is a directory
handso@GNU×Linux:~/Documents$ rm -r -i test1
rm: descend into directory 'test1'? y
rm: descend into directory 'test1/2'? y
rm: remove regular file 'test1/2/hehehe.txt'? y
rm: remove directory 'test1/2'? y
rm: remove directory 'test1/1'? y
rm: remove directory 'test1'? y
handso@GNU×Linux:~/Documents$ ls
test2

rm 不带-r删除不掉test1

尝试带上-r 带上-i (确认)删除,有趣的是询问过程是否反映的就是实际在不带-i的时候的删除顺序?

附上-R(r)的 man 说明

-R           Attempt to remove the file hierarchy rooted in each file
             argument.  The -R option implies the -d option.  If the -i
             option is specified, the user is prompted for confirmation
             before each directory's contents are processed (as well as
             before the attempt is made to remove the directory).  If the
             user does not respond affirmatively, the file hierarchy
             rooted in that directory is skipped.

rm到此结束,有待更新补充。

本文遵循「 署名-非商业性使用-相同方式共享 4.0 国际 」协议
本文链接:http://tonightleftyou.info/2018/05/05/命令学习·rm/