1,rmdir,一個很雞肋的命令,只能刪除空目錄linux
ghostwu@dev:~/linux/cp$ ls 1.txt 2.txt a a2 a3 ghostwu@dev:~/linux/cp$ rmdir a rmdir: failed to remove 'a': Directory not empty ghostwu@dev:~/linux/cp$ mkdir b ghostwu@dev:~/linux/cp$ ls 1.txt 2.txt a a2 a3 b ghostwu@dev:~/linux/cp$ rmdir b ghostwu@dev:~/linux/cp$ ls 1.txt 2.txt a a2 a3
2,mv: 移動文件或者重命名spa
把1.txt重命名爲11.txtcode
ghostwu@dev:~/linux/cp$ ls 1.txt 2.txt a a2 a3 ghostwu@dev:~/linux/cp$ mv 1.txt 11.txt ghostwu@dev:~/linux/cp$ ls 11.txt 2.txt a a2 a3
把11.txt移動到b目錄blog
ghostwu@dev:~/linux/cp$ ls 11.txt 2.txt a a2 a3 ghostwu@dev:~/linux/cp$ mkdir b ghostwu@dev:~/linux/cp$ ls 11.txt 2.txt a a2 a3 b ghostwu@dev:~/linux/cp$ mv 11.txt b ghostwu@dev:~/linux/cp$ ls 2.txt a a2 a3 b ghostwu@dev:~/linux/cp$ tree b b └── 11.txt
-f:若是目標文件存在,不會詢問直接覆蓋遞歸
ghostwu@dev:~/linux/cp$ ls 22.txt 2.txt a a2 a3 b ghostwu@dev:~/linux/cp$ ls b 11.txt ghostwu@dev:~/linux/cp$ mv -f 2.txt b/11.txt ghostwu@dev:~/linux/cp$ ls 22.txt a a2 a3 b
-i: 若是目標文件存在,詢問是否覆蓋rem
ghostwu@dev:~/linux/cp$ ls 22.txt 2.txt a a2 a3 b ghostwu@dev:~/linux/cp$ ls b 11.txt ghostwu@dev:~/linux/cp$ mv -i 2.txt b/11.txt mv: overwrite 'b/11.txt'? n ghostwu@dev:~/linux/cp$ ls 22.txt 2.txt a a2 a3 b ghostwu@dev:~/linux/cp$ mv -i 2.txt b/11.txt mv: overwrite 'b/11.txt'? y ghostwu@dev:~/linux/cp$ ls 22.txt a a2 a3 b
-n: 不覆蓋已經存在的文件it
ghostwu@dev:~/linux/cp$ ls 22.txt a a2 a3 b ghostwu@dev:~/linux/cp$ ls b 11.txt ghostwu@dev:~/linux/cp$ mv -n 22.txt b/11.txt ghostwu@dev:~/linux/cp$ ls 22.txt a a2 a3 b
-u: 當文件不存在,或者源文件比目標文件新的時候,才移動class
ghostwu@dev:~/linux/cp$ ls -l total 16 -rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:28 22.txt drwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:06 a drwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:07 a2 drwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:06 a3 drwxrwxr-x 2 ghostwu ghostwu 4096 5月 6 18:31 b ghostwu@dev:~/linux/cp$ ls -l b total 0 -rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:30 11.txt ghostwu@dev:~/linux/cp$ mv -u 22.txt b/11.txt ghostwu@dev:~/linux/cp$ ls -l total 16 -rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:28 22.txt drwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:06 a drwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:07 a2 drwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:06 a3 drwxrwxr-x 2 ghostwu ghostwu 4096 5月 6 18:31 b ghostwu@dev:~/linux/cp$ ls b 11.txt ghostwu@dev:~/linux/cp$ ls -l b total 0 -rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:30 11.txt ghostwu@dev:~/linux/cp$ touch 22.txt ghostwu@dev:~/linux/cp$ ls -l 22.txt -rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:37 22.txt ghostwu@dev:~/linux/cp$ mv -u 22.txt b/11.txt ghostwu@dev:~/linux/cp$ ls -l total 16 drwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:06 a drwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:07 a2 drwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:06 a3 drwxrwxr-x 2 ghostwu ghostwu 4096 5月 6 18:37 b ghostwu@dev:~/linux/cp$ ls -l b total 0 -rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:37 11.txt
ghostwu@dev:~/linux/cp$ ls a a2 a3 b ghostwu@dev:~/linux/cp$ touch a.txt ghostwu@dev:~/linux/cp$ ls a a2 a3 a.txt b ghostwu@dev:~/linux/cp$ ls -l b total 0 -rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:37 11.txt ghostwu@dev:~/linux/cp$ mv a.txt b ghostwu@dev:~/linux/cp$ ls -l total 16 drwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:06 a drwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:07 a2 drwxrwxr-x 3 ghostwu ghostwu 4096 5月 6 18:06 a3 drwxrwxr-x 2 ghostwu ghostwu 4096 5月 6 18:38 b ghostwu@dev:~/linux/cp$ ls -l b total 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: 刪除文件file
-i: 帶提示命名
-f:強制刪除
-r:遞歸刪除
ghostwu@dev:~/linux/cp$ ls a a2 a3 b ghostwu@dev:~/linux/cp$ touch {a..f}.txt ghostwu@dev:~/linux/cp$ ls a a2 a3 a.txt b b.txt c.txt d.txt e.txt f.txt ghostwu@dev:~/linux/cp$ rm a.txt ghostwu@dev:~/linux/cp$ ls a a2 a3 b b.txt c.txt d.txt e.txt f.txt ghostwu@dev:~/linux/cp$ rm -i b.txt rm: remove regular empty file 'b.txt'? n ghostwu@dev:~/linux/cp$ ls a a2 a3 b b.txt c.txt d.txt e.txt f.txt ghostwu@dev:~/linux/cp$ rm -i b.txt rm: remove regular empty file 'b.txt'? y ghostwu@dev:~/linux/cp$ ls a a2 a3 b c.txt d.txt e.txt f.txt ghostwu@dev:~/linux/cp$ rm -f c.txt ghostwu@dev:~/linux/cp$ ls a a2 a3 b d.txt e.txt f.txt
ghostwu@dev:~/linux/cp$ ls a3 d.txt e.txt f.txt ghostwu@dev:~/linux/cp$ tree a3 a3 ├── 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.txt 3 directories, 15 files ghostwu@dev:~/linux/cp$ rm -r a3 ghostwu@dev:~/linux/cp$ ls d.txt e.txt f.txt