Linux常用基本命令( rmdir, rm, mv )
Posted ghostwu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux常用基本命令( rmdir, rm, mv )相关的知识,希望对你有一定的参考价值。
1,rmdir,一个很鸡肋的命令,只能删除空目录
[email protected]:~/linux/cp$ ls 1.txt 2.txt a a2 a3 [email protected]:~/linux/cp$ rmdir a rmdir: failed to remove ‘a‘: Directory not empty [email protected]:~/linux/cp$ mkdir b [email protected]:~/linux/cp$ ls 1.txt 2.txt a a2 a3 b [email protected]:~/linux/cp$ rmdir b [email protected]:~/linux/cp$ ls 1.txt 2.txt a a2 a3
2,mv: 移动文件或者重命名
把1.txt重命名为11.txt
[email protected]:~/linux/cp$ ls 1.txt 2.txt a a2 a3 [email protected]:~/linux/cp$ mv 1.txt 11.txt [email protected]:~/linux/cp$ ls 11.txt 2.txt a a2 a3
把11.txt移动到b目录
[email protected]:~/linux/cp$ ls 11.txt 2.txt a a2 a3 [email protected]:~/linux/cp$ mkdir b [email protected]:~/linux/cp$ ls 11.txt 2.txt a a2 a3 b [email protected]:~/linux/cp$ mv 11.txt b [email protected]:~/linux/cp$ ls 2.txt a a2 a3 b [email protected]:~/linux/cp$ tree b b └── 11.txt
-f:如果目标文件存在,不会询问直接覆盖
[email protected]:~/linux/cp$ ls 22.txt 2.txt a a2 a3 b [email protected]:~/linux/cp$ ls b 11.txt [email protected]:~/linux/cp$ mv -f 2.txt b/11.txt [email protected]:~/linux/cp$ ls 22.txt a a2 a3 b
-i: 如果目标文件存在,询问是否覆盖
[email protected]:~/linux/cp$ ls 22.txt 2.txt a a2 a3 b [email protected]:~/linux/cp$ ls b 11.txt [email protected]:~/linux/cp$ mv -i 2.txt b/11.txt mv: overwrite ‘b/11.txt‘? n [email protected]:~/linux/cp$ ls 22.txt 2.txt a a2 a3 b [email protected]:~/linux/cp$ mv -i 2.txt b/11.txt mv: overwrite ‘b/11.txt‘? y [email protected]:~/linux/cp$ ls 22.txt a a2 a3 b
-n: 不覆盖已经存在的文件
[email protected]:~/linux/cp$ ls 22.txt a a2 a3 b [email protected]:~/linux/cp$ ls b 11.txt [email protected]:~/linux/cp$ mv -n 22.txt b/11.txt [email protected]:~/linux/cp$ ls 22.txt a a2 a3 b
-u: 当文件不存在,或者源文件比目标文件新的时候,才移动
[email protected]:~/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 [email protected]:~/linux/cp$ ls -l b total 0 -rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:30 11.txt [email protected]:~/linux/cp$ mv -u 22.txt b/11.txt [email protected]:~/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 [email protected]:~/linux/cp$ ls b 11.txt [email protected]:~/linux/cp$ ls -l b total 0 -rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:30 11.txt [email protected]:~/linux/cp$ touch 22.txt [email protected]:~/linux/cp$ ls -l 22.txt -rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:37 22.txt [email protected]:~/linux/cp$ mv -u 22.txt b/11.txt [email protected]:~/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 [email protected]:~/linux/cp$ ls -l b total 0 -rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:37 11.txt
[email protected]:~/linux/cp$ ls a a2 a3 b [email protected]:~/linux/cp$ touch a.txt [email protected]:~/linux/cp$ ls a a2 a3 a.txt b [email protected]:~/linux/cp$ ls -l b total 0 -rw-rw-r-- 1 ghostwu ghostwu 0 5月 6 18:37 11.txt [email protected]:~/linux/cp$ mv a.txt b [email protected]:~/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 [email protected]:~/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: 删除文件
-i: 带提示
-f:强制删除
-r:递归删除
[email protected]:~/linux/cp$ ls a a2 a3 b [email protected]:~/linux/cp$ touch {a..f}.txt [email protected]:~/linux/cp$ ls a a2 a3 a.txt b b.txt c.txt d.txt e.txt f.txt [email protected]:~/linux/cp$ rm a.txt [email protected]:~/linux/cp$ ls a a2 a3 b b.txt c.txt d.txt e.txt f.txt [email protected]:~/linux/cp$ rm -i b.txt rm: remove regular empty file ‘b.txt‘? n [email protected]:~/linux/cp$ ls a a2 a3 b b.txt c.txt d.txt e.txt f.txt [email protected]:~/linux/cp$ rm -i b.txt rm: remove regular empty file ‘b.txt‘? y [email protected]:~/linux/cp$ ls a a2 a3 b c.txt d.txt e.txt f.txt [email protected]:~/linux/cp$ rm -f c.txt [email protected]:~/linux/cp$ ls a a2 a3 b d.txt e.txt f.txt
[email protected]:~/linux/cp$ ls a3 d.txt e.txt f.txt [email protected]:~/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 [email protected]:~/linux/cp$ rm -r a3 [email protected]:~/linux/cp$ ls d.txt e.txt f.txt
以上是关于Linux常用基本命令( rmdir, rm, mv )的主要内容,如果未能解决你的问题,请参考以下文章