1,rmdir,一个很鸡肋的命令,只能删除空目录
ghostwu@dev:~/linux/cp$ ls1.txt 2.txt a a2 a3ghostwu@dev:~/linux/cp$ rmdir armdir: failed to remove 'a': Directory not emptyghostwu@dev:~/linux/cp$ mkdir bghostwu@dev:~/linux/cp$ ls1.txt 2.txt a a2 a3 bghostwu@dev:~/linux/cp$ rmdir bghostwu@dev:~/linux/cp$ ls1.txt 2.txt a a2 a3
2,mv: 移动文件或者重命名
把1.txt重命名为11.txt
ghostwu@dev:~/linux/cp$ ls1.txt 2.txt a a2 a3ghostwu@dev:~/linux/cp$ mv 1.txt 11.txtghostwu@dev:~/linux/cp$ ls11.txt 2.txt a a2 a3
把11.txt移动到b目录
ghostwu@dev:~/linux/cp$ ls11.txt 2.txt a a2 a3ghostwu@dev:~/linux/cp$ mkdir bghostwu@dev:~/linux/cp$ ls11.txt 2.txt a a2 a3 bghostwu@dev:~/linux/cp$ mv 11.txt bghostwu@dev:~/linux/cp$ ls2.txt a a2 a3 bghostwu@dev:~/linux/cp$ tree bb└── 11.txt
-f:如果目标文件存在,不会询问直接覆盖
ghostwu@dev:~/linux/cp$ ls22.txt 2.txt a a2 a3 bghostwu@dev:~/linux/cp$ ls b11.txtghostwu@dev:~/linux/cp$ mv -f 2.txt b/11.txt ghostwu@dev:~/linux/cp$ ls22.txt a a2 a3 b
-i: 如果目标文件存在,询问是否覆盖
ghostwu@dev:~/linux/cp$ ls22.txt 2.txt a a2 a3 bghostwu@dev:~/linux/cp$ ls b11.txtghostwu@dev:~/linux/cp$ mv -i 2.txt b/11.txtmv: overwrite 'b/11.txt'? nghostwu@dev:~/linux/cp$ ls22.txt 2.txt a a2 a3 bghostwu@dev:~/linux/cp$ mv -i 2.txt b/11.txt mv: overwrite 'b/11.txt'? yghostwu@dev:~/linux/cp$ ls22.txt a a2 a3 b
-n: 不覆盖已经存在的文件
ghostwu@dev:~/linux/cp$ ls22.txt a a2 a3 bghostwu@dev:~/linux/cp$ ls b11.txtghostwu@dev:~/linux/cp$ mv -n 22.txt b/11.txtghostwu@dev:~/linux/cp$ ls22.txt a a2 a3 b
-u: 当文件不存在,或者源文件比目标文件新的时候,才移动
ghostwu@dev:~/linux/cp$ ls -ltotal 16-rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:28 22.txtdrwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:06 adrwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:07 a2drwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:06 a3drwxrwxr-x 2 ghostwu ghostwu 4096 5月 6 18:31 bghostwu@dev:~/linux/cp$ ls -l btotal 0-rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:30 11.txtghostwu@dev:~/linux/cp$ mv -u 22.txt b/11.txtghostwu@dev:~/linux/cp$ ls -ltotal 16-rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:28 22.txtdrwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:06 adrwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:07 a2drwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:06 a3drwxrwxr-x 2 ghostwu ghostwu 4096 5月 6 18:31 bghostwu@dev:~/linux/cp$ ls b11.txtghostwu@dev:~/linux/cp$ ls -l btotal 0-rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:30 11.txtghostwu@dev:~/linux/cp$ touch 22.txtghostwu@dev:~/linux/cp$ ls -l 22.txt-rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:37 22.txtghostwu@dev:~/linux/cp$ mv -u 22.txt b/11.txtghostwu@dev:~/linux/cp$ ls -ltotal 16drwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:06 adrwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:07 a2drwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:06 a3drwxrwxr-x 2 ghostwu ghostwu 4096 5月 6 18:37 bghostwu@dev:~/linux/cp$ ls -l btotal 0-rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:37 11.txt
ghostwu@dev:~/linux/cp$ lsa a2 a3 bghostwu@dev:~/linux/cp$ touch a.txtghostwu@dev:~/linux/cp$ lsa a2 a3 a.txt bghostwu@dev:~/linux/cp$ ls -l btotal 0-rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:37 11.txtghostwu@dev:~/linux/cp$ mv a.txt bghostwu@dev:~/linux/cp$ ls -ltotal 16drwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:06 adrwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:07 a2drwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:06 a3drwxrwxr-x 2 ghostwu ghostwu 4096 5月 6 18:38 bghostwu@dev:~/linux/cp$ ls -l btotal 0-rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:37 11.txt-rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:38 a.txt
rm: 删除文件
-i: 带提示
-f:强制删除
-r:递归删除
ghostwu@dev:~/linux/cp$ lsa a2 a3 bghostwu@dev:~/linux/cp$ touch {a..f}.txtghostwu@dev:~/linux/cp$ lsa a2 a3 a.txt b b.txt c.txt d.txt e.txt f.txtghostwu@dev:~/linux/cp$ rm a.txt ghostwu@dev:~/linux/cp$ lsa a2 a3 b b.txt c.txt d.txt e.txt f.txtghostwu@dev:~/linux/cp$ rm -i b.txtrm: remove regular empty file 'b.txt'? nghostwu@dev:~/linux/cp$ lsa a2 a3 b b.txt c.txt d.txt e.txt f.txtghostwu@dev:~/linux/cp$ rm -i b.txt rm: remove regular empty file 'b.txt'? yghostwu@dev:~/linux/cp$ lsa a2 a3 b c.txt d.txt e.txt f.txtghostwu@dev:~/linux/cp$ rm -f c.txt ghostwu@dev:~/linux/cp$ lsa a2 a3 b d.txt e.txt f.txt
ghostwu@dev:~/linux/cp$ lsa3 d.txt e.txt f.txtghostwu@dev:~/linux/cp$ tree a3a3├── b│ ├── 1.txt│ ├── 2.txt│ ├── 3.txt│ ├── 4.txt│ └── 5.txt├── c│ ├── 1.txt│ ├── 2.txt│ ├── 3.txt│ ├── 4.txt│ └── 5.txt└── d ├── 1.txt ├── 2.txt ├── 3.txt ├── 4.txt └── 5.txt3 directories, 15 filesghostwu@dev:~/linux/cp$ rm -r a3ghostwu@dev:~/linux/cp$ lsd.txt e.txt f.txt