root@172.25.254.32's password: [root@westoslinux Desktop]# scp -qr 课程资料 root@172.25.254.32:/home/westos/Desktop/ (-r表示复制目录)
root@172.25.254.32's password: 复制远程主机的文件到本机的桌面上 [root@westoslinux Desktop]# scp root@172.25.254.32:/home/westos/Desktop/qwe /root/Desktop/
root@172.25.254.32's password:
qwe 100% 0 0.0KB/s 00:00 2.rsync 命令 (可以实现增量备份的工具)目的是实现本地主机和远程主机上的文件同步拷贝,也包含远程到本地两种同步方式(rsync不支持远程到远程的拷贝,scp支持,cp只能本地拷贝) rsync传输速度快于scp rsync 用法 rsync 文件 远程用户 @ 远程主机 ip : 远程主机目录 rsync 远程用户 @ 远程主机 ip : 远程主机目录 文件路径 rsync - r ## 复制目录 - l ## 复制链接 - p ## 复制权限 - t ## 复制时间戳 - o ## 复制拥有者 - g ## 复制拥有组 - D ## 复制设备文件 实验: root@westoslinux mnt]# touch /mnt/westosfile{1..5} 切换路径/mnt/ 建立5个文件 [root@westoslinux mnt]# chmod 777 /mnt/westosfile* 设置所有文件为满权限 [root@westoslinux mnt]# chown westos.westos /mnt/westosfile* 更改所有文件的用户和用户组 显示如下
[root@westoslinux mnt]# ll
total 0
-rwxrwxrwx. 1 westos westos 0 Oct 16 11:11 westosfile1
-rwxrwxrwx. 1 westos westos 0 Oct 16 11:11 westosfile2
-rwxrwxrwx. 1 westos westos 0 Oct 16 11:11 westosfile3
-rwxrwxrwx. 1 westos westos 0 Oct 16 11:11 westosfile4
-rwxrwxrwx. 1 westos westos 0 Oct 16 11:11 westosfile5 [root@westoslinux mnt]# rsync -r /mnt root@172.25.254.32:/home/westos/Desktop
root@172.25.254.32's password: 复制本机目录本身及文件到远程主机桌面中 [root@westoslinux mnt]# rsync -r /mnt/ root@172.25.254.32:/home/westos/Desktop
root@172.25.254.32's password: 复制本机目录里边的文件到远程主机桌面中 [root@westoslinux mnt]# rsync -pr /mnt/ root@172.25.254.32:/home/westos/Desktop(-p复制权限)
root@172.25.254.32's password: [root@westoslinux mnt]# rsync -por /mnt/ root@172.25.254.32:/home/westos/Desktop(-o复制拥有者)
root@172.25.254.32's password: [root@westoslinux mnt]# rsync -pogr /mnt/ root@172.25.254.32:/home/westos/Desktop(-g复制拥有组)
root@172.25.254.32's password: [root@westoslinux mnt]# rsync -pogrt /mnt/ root@172.25.254.32:/home/westos/Desktop(-t复制时间戳)
root@172.25.254.32's password:
[root@westoslinux mnt]# ll
total 0
lrwxrwxrwx. 1 root root 16 Oct 16 11:22 lee -> /mnt/westosfile1
-rwxrwxrwx. 1 westos westos 0 Oct 16 11:11 westosfile1
-rwxrwxrwx. 1 westos westos 0 Oct 16 11:11 westosfile2
-rwxrwxrwx. 1 westos westos 0 Oct 16 11:11 westosfile3
-rwxrwxrwx. 1 westos westos 0 Oct 16 11:11 westosfile4
-rwxrwxrwx. 1 westos westos 0 Oct 16 11:11 westosfile5 [root@westoslinux mnt]# ln -s /mnt/westosfile1 /mnt/lee 给westosfile1建立一个软链接到lee上 [root@westoslinux mnt]# rsync -plogrt /mnt/ root@172.25.254.32:/home/westos/Desktop(-l复制链接)
root@172.25.254.32's password:
[root@westoslinux mnt]# ll /dev/pts/设备文件
total 0
crw--w----. 1 root tty 136, 0 Oct 16 11:25 0
c---------. 1 root root 5, 2 Oct 16 08:52 ptmx
[root@westoslinux mnt]# rsync -plogrtD /dev/pts/ root@172.25.254.32:/home/westos/Desktop(-D复制设备文件)
root@172.25.254.32's password:
文件的归档压缩 1. 文件归档 tar c ## 创建 f ## 指定文件名称 x ## 解档 v ## 现实过程 t ## 查看 r ## 向归档文件中添加文件 -- get ## 解档指定文件 -- delete ## 删除指定文件 - C ## 指定解档路径 - P ##don ' t remove " / " 解压到绝对路径
[root@westoslinux mnt]# du -sh etc.tar
27M etc.tar
[root@westoslinux mnt]# du -sh /etc/
29M /etc/ 打包好的文件大小和没有打包之前的大小
压缩 不能直接对目录进行压缩 要对打包好的目录文件进行压缩
[root@westoslinux Desktop]# cd /mnt[root@westoslinux mnt]# ls
etc.tar media.tar zip zip -r mnt.tar.zip mnt.tar #zip格式压缩 unzip mnt.tar.zip #zip格式解压缩 [root@westoslinux mnt]# zip -r etc.tar.zip etc.tar 压缩etc.tar
adding: etc.tar (deflated 75%) [root@westoslinux mnt]# ls
etc.tar etc.tar.zip media.tar [root@westoslinux mnt]# du -sh etc.tar.zip 比较打包文件和压缩包的大小
6.7M etc.tar.zip [root@westoslinux mnt]# du -sh etc.tar
27M etc.tar [root@westoslinux mnt]# rm -fr etc.tar
[root@westoslinux mnt]# ls etc.tar.zip media.tar [root@westoslinux mnt]# unzip etc.tar.zip 解压
Archive: etc.tar.zip
inflating: etc.tar
[root@westoslinux mnt]# ls
etc.tar etc.tar.zip media.tar
gzip
gzip mnt.tar #gzip格式压缩
gunzip mnt.tar.gz #gzip格式解压缩
[root@westoslinux mnt]# gzip media.tar
[root@westoslinux mnt]# ls
etc.tar etc.tar.zip media.tar.gz
[root@westoslinux mnt]# du -sh media.tar.gz
6.7M media.tar.gz
[root@westoslinux mnt]# gunzip media.tar.gz
[root@westoslinux mnt]# ls
etc.tar etc.tar.zip media.tar
bzip2 mnt.tar #bzip2格式压缩 bunzip2 etc.tar.bz2 #bzip2格式解压缩 [root@westoslinux mnt]# bzip2 etc.tar
[root@westoslinux mnt]# du -sh etc.tar.bz2
5.1M etc.tar.bz2
[root@westoslinux mnt]# bunzip2 etc.tar.bz2
[root@westoslinux mnt]# ls
etc.tar etc.tar.zip media.tar
xz mnt.tar #xz格式压缩 unxz mnt.tar.xz #xz格式解压缩 [root@westoslinux mnt]# xz etc.tar
[root@westoslinux mnt]# ls
etc.tar.xz etc.tar.zip media.tar
[root@westoslinux mnt]# du -sh etc.tar.xz
4.4M etc.tar.xz
[root@westoslinux mnt]# unxz etc.tar.xz
[root@westoslinux mnt]# ls
etc.tar etc.tar.zip media.tar
3. tar + 压缩 gzip tar zcf etc.tar.gz /etc tar zxf etc.tar.gz [root@westoslinux mnt]# tar zcf media.tar.gz /media/
tar: Removing leading `/' from member names
[root@westoslinux mnt]# ls
etc.tar etc.tar.zip media.tar.gz
[root@westoslinux mnt]#
[root@westoslinux mnt]# tar zxf media.tar.gz
[root@westoslinux mnt]# ls
etc.tar etc.tar.zip media media.tar.gz bzip2 tar jcf etc.tar.bz2 /etc tar jxf etc.tar.bz2 xz tar Jcf etc.tar.xz /etc tar Jxf etc.tar.xzi



