之前讲述了目录的创建和删除,现在讲一下目录的移动修改。
操作系统:
CentOS Stream 9
操作命令:
mv
移动,重命名
选项
-v显示移动过程
[root@localhost ~]# mkdir 12
[root@localhost ~]# ll
总用量 1220
drwxr-xr-x 2 root root 6 6月 1 00:04 12
-rw-------. 1 root root 1231 5月 8 15:09 anaconda-ks.cfg
drwxr-xr-x 9 502 games 186 5月 25 20:12 nginx-1.26.0
-rw-r--r-- 1 root root 1244118 4月 23 22:58 nginx-1.26.0.tar.gz
[root@localhost ~]# pwd
/root
[root@localhost ~]# mv -v 12 /top/12
已重命名 '12' -> '/top/12'
[root@localhost ~]#
[root@localhost ~]# cd /top
[root@localhost top]# ll
总用量 0
drwxr-xr-x 2 root root 6 6月 1 00:04 12
[root@localhost top]#
操作命令:
pwd
显示当前工作目录的绝对路径
[root@localhost ~]# cd /usr/local/nginx
[root@localhost nginx]# pwd
/usr/local/nginx
[root@localhost nginx]# cd sbin
[root@localhost sbin]# pwd
/usr/local/nginx/sbin
[root@localhost sbin]# cd ..
[root@localhost nginx]# cd ..
[root@localhost local]# pwd
/usr/local
[root@localhost local]#
操作命令:
cp
复制备份
将文件复制到目录
[root@localhost ~]# cp 1.txt /top/1.txt
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# cd /top/
[root@localhost top]# ll
总用量 0
-rw-r--r-- 1 root root 0 6月 1 00:41 1.txt
复制单个文件
[root@localhost ~]# ll
总用量 1220
-rw-r--r-- 1 root root 0 6月 1 00:41 1.txt
-rw-------. 1 root root 1231 5月 8 15:09 anaconda-ks.cfg
drwxr-xr-x 9 502 games 186 5月 25 20:12 nginx-1.26.0
-rw-r--r-- 1 root root 1244118 4月 23 22:58 nginx-1.26.0.tar.gz
[root@localhost ~]# cp 1.txt 2.txt
[root@localhost ~]# ll
总用量 1220
-rw-r--r-- 1 root root 0 6月 1 00:41 1.txt
-rw-r--r-- 1 root root 0 6月 1 00:44 2.txt
-rw-------. 1 root root 1231 5月 8 15:09 anaconda-ks.cfg
drwxr-xr-x 9 502 games 186 5月 25 20:12 nginx-1.26.0
-rw-r--r-- 1 root root 1244118 4月 23 22:58 nginx-1.26.0.tar.gz
[root@localhost ~]#
复制目录
选项
- -v:显示详细的操作过程。
- -a:等同于
-dpR
,保留原有文件的全部属性(包括权限、时间戳、链接等),递归复制目录。
[root@localhost ~]# cp -av /etc/passwd /top/passwd
'/etc/passwd' -> '/top/passwd'
[root@localhost ~]#