linux文件增删拷(touch/mkdir/cp/mv/rm)

touch或>命令建立普通文件:spa

[root@localhost test]# touch a  ---建立单个文件
[root@localhost test]# ls
a
[root@localhost test]# > b   ---建立单个文件
[root@localhost test]# ls
a  b
 
mkdir建立目录文件:
[root@localhost test]# mkdir c  --建立文件夹
[root@localhost test]# ll
total 0
-rw-r--r-- 1 root root 0 Oct  1 19:54 a
-rw-r--r-- 1 root root 0 Oct  1 19:54 b
drwxr-xr-x 2 root root 6 Oct  1 19:55 c
 
一次建立多个普通文件:
[root@localhost test]# touch d e  ---建立多个文件
[root@localhost test]# ls
a  b  c  d  e
 
选项-p递归建立多个目录文件:
[root@localhost test]# mkdir -p aa/bb  ---使用-p递归建立目录
[root@localhost test]# ll
total 0
-rw-r--r-- 1 root root  0 Oct  1 19:54 a
drwxr-xr-x 3 root root 16 Oct  1 19:57 aa
-rw-r--r-- 1 root root  0 Oct  1 19:54 b
drwxr-xr-x 2 root root  6 Oct  1 19:55 c
-rw-r--r-- 1 root root  0 Oct  1 19:55 d
-rw-r--r-- 1 root root  0 Oct  1 19:55 e
[root@localhost test]# cd aa
[root@localhost aa]# ls
bb
 
选项-R递归显示文件:
[root@localhost test]# ls -R  ----使用选项-R递归显示文件。
.:
a  aa  b  c  d  e
./aa:
bb
./aa/bb:
./c:
[root@localhost test]# mkdir -pv cc/dd  --v指verbose。详细显示递归建立。
mkdir: created directory ?.c?
mkdir: created directory ?.c/dd?
 
cp拷贝单个普通文件:
[root@localhost test]# ll
total 0
-rw-r--r-- 1 root root  0 Oct  1 19:54 a
drwxr-xr-x 3 root root 16 Oct  1 19:57 aa
-rw-r--r-- 1 root root  0 Oct  1 19:54 b
drwxr-xr-x 2 root root  6 Oct  1 19:55 c
drwxr-xr-x 3 root root 16 Oct  1 20:00 cc
-rw-r--r-- 1 root root  0 Oct  1 19:55 d
-rw-r--r-- 1 root root  0 Oct  1 19:55 e
[root@localhost test]# cp a f
[root@localhost test]# ll
total 0
-rw-r--r-- 1 root root  0 Oct  1 19:54 a
drwxr-xr-x 3 root root 16 Oct  1 19:57 aa
-rw-r--r-- 1 root root  0 Oct  1 19:54 b
drwxr-xr-x 2 root root  6 Oct  1 19:55 c
drwxr-xr-x 3 root root 16 Oct  1 20:00 cc
-rw-r--r-- 1 root root  0 Oct  1 19:55 d
-rw-r--r-- 1 root root  0 Oct  1 19:55 e
-rw-r--r-- 1 root root  0 Oct  1 20:02 f
 
cp拷贝多个普通文件:
[root@localhost test]# cp a b aa
[root@localhost test]# cd aa
[root@localhost aa]# ll
total 0
-rw-r--r-- 1 root root 0 Oct  1 20:04 a
-rw-r--r-- 1 root root 0 Oct  1 20:04 b
drwxr-xr-x 2 root root 6 Oct  1 19:57 bb
 
cp加选项-r拷贝目录文件:
[root@localhost test]# ll
total 0
-rw-r--r-- 1 root root  0 Oct  1 19:54 a
drwxr-xr-x 3 root root 34 Oct  1 20:04 aa
-rw-r--r-- 1 root root  0 Oct  1 19:54 b
drwxr-xr-x 2 root root  6 Oct  1 19:55 c
drwxr-xr-x 4 root root 26 Oct  1 20:07 cc
-rw-r--r-- 1 root root  0 Oct  1 19:55 d
-rw-r--r-- 1 root root  0 Oct  1 19:55 e
-rw-r--r-- 1 root root  0 Oct  1 20:02 f
[root@localhost test]# cp -r aa cc
[root@localhost test]# cd cc
[root@localhost cc]# ll
total 0
drwxr-xr-x 3 root root 34 Oct  1 20:07 aa
drwxr-xr-x 2 root root  6 Oct  1 20:00 dd
 
cp拷贝普通文件并重命名:
[root@localhost test]# cp a ./bb/1
[root@localhost test]# ls ./bb
1
 
mv剪切文件:
剪切文件 没有 -r 之分 , 不管是普通文件仍是目录都不用加 -r., 不用区分普通文件仍是目录文件 , 能够一次剪切多个文件 . 也有重命名的做用 .
[root@localhost test]# ls
a  aa  b  bb  c  cc  d  e  f
[root@localhost test]# mv b g
[root@localhost test]# ls
a  aa  bb  c  cc  d  e  f  g
 
rm删除文件:
[root@localhost test]# ls
a  aa  bb  c  cc  d  e  f  g
[root@localhost test]# rm -fr a
[root@localhost test]# ls
aa  bb  c  cc  d  e  f  g
[root@localhost test]# rm -fr ? ---使用统配符?表明单个字符的文件
[root@localhost test]# ls
aa  bb  cc
[root@localhost test]# rm -fr *  --使用统配符*,表明全部文件
相关文章
相关标签/搜索