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

时间:2023-03-10 02:47:52
linux文件增删拷(touch/mkdir/cp/mv/rm)

touch或>命令创建普通文件:

[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 * 
--使用统配符*,代表所有文件