文件传输

不同系统之间的文件传输


####1.文件归档####
1.
文件归档,就是把多个文件变成一个归档文件
2.
tar    c        ##创建
    f        ##指定归档文件名称
    t        ##显示归档文件中的内容
    r        ##向归档文件中添加文件
    --get        ##取出单个文件
    --delete    ##删除单个文件
    x        ##取出归档文件中的所有内容
    -C        ##指定解档目录
    -z        ##gz格式压缩
    -j        ##bz2格式压缩

    -J        ##xz格式压缩



####2.压缩####
gz
gzip etc.tar        ##压缩成gz格式
gunzip  etc.tar.gz    ##解压gz格式压缩包
tar zcf etc.tar.gz /etc    ##把文件归档为tar并压缩成gz

tar zxf etc.tar.gz    ##解压并解档gz格式压缩包



bz2
bzip2 etc.tar        ##压缩成bz2格式
bunzip2 etc.tar.bz2    ##解压bz2格式压缩包
tar jcf etc.tar.bz2 /etc    ##把文件归档为tar并压缩成bz2

tar jxf etc.tar.bz2    ##解压并解档bz2格式压缩包



xz
xz etc.tar         ##压缩成xz格式
unxz  etc.tar.xz    ##解压xz格式压缩包
tar Jcf etc.tar.xz /etc    ##把文件归档为tar并压缩成zx
tar Jxf etc.tar.xz    ##解压并解档xz格式压缩包

zip

zip -r etc.tar.zip etc.tar    ##压缩成zip格式

unzip etc.tar.zip        ##解压zip格式压缩包




####3.系统中的文件传输####
scp    file     username@ip:/dir    ##上传

scp    username@ip:/dir/file  /dir    ##下载

(本机ip为172.25.254.113)scp file1 root@172.25.254.213:/root/Desktop

                        把自己的文件file1以超级用户的身份传给ip为172.25.254.213的用户在其/root/Desktop下存放


scp root@172.25.254.213:/root/Desktop/file2  .   把ip为172.25.254.213用户的/root/Desktop/file2文件复制到当前

scp文件的传输相对来说比较慢此时我们有一种比较快的同步传输方式rsync

rsync [参数]    file    username@ip:/dir   把自己自己机子的文件或目录同步给ip机子上的某个目录下但此时只会同步文件不会同步文件权限、所有人、所有组、时间等信息)

rsync    -r    ##同步目录
    -l    ##不忽略链接
    -p    ##不忽略文件权限
    -t    ##不忽文件时间戳
    -g    ##不忽文件所有组
    -o    ##不忽文件所有人

    -D    ##不忽略设备文件

(服务端)[root@localhost ~]# cd /mnt
[root@localhost mnt]# ls
[root@localhost mnt]# touch file{1..5}
[root@localhost mnt]# ls
file1  file2  file3  file4  file5
[root@localhost mnt]# ls -l
total 0
-rw-r--r--. 1 root root 0 Apr  6 03:10 file1
-rw-r--r--. 1 root root 0 Apr  6 03:10 file2
-rw-r--r--. 1 root root 0 Apr  6 03:10 file3
-rw-r--r--. 1 root root 0 Apr  6 03:10 file4
-rw-r--r--. 1 root root 0 Apr  6 03:10 file5
[root@localhost mnt]# chmod 777 *
[root@localhost mnt]# chown student.student *
[root@localhost mnt]# ll
total 0
-rwxrwxrwx. 1 student student 0 Apr  6 03:10 file1
-rwxrwxrwx. 1 student student 0 Apr  6 03:10 file2
-rwxrwxrwx. 1 student student 0 Apr  6 03:10 file3
-rwxrwxrwx. 1 student student 0 Apr  6 03:10 file4
-rwxrwxrwx. 1 student student 0 Apr  6 03:10 file5
[root@localhost mnt]# rsync -r /mnt/ root@172.25.254.113:/mnt   将/mnt/下的内容同步到172.25.254.113中(但此时只会同步文件不会同步文件权限、所有人、所有组、时间等信息)
root@172.25.254.113's password:
[root@localhost mnt]# mkdir test
[root@localhost mnt]# touch test/file8
[root@localhost mnt]# ls
file1  file2  file3  file4  file5  test
[root@localhost mnt]# ll
total 0
-rwxrwxrwx. 1 student student  0 Apr  6 03:10 file1
-rwxrwxrwx. 1 student student  0 Apr  6 03:10 file2
-rwxrwxrwx. 1 student student  0 Apr  6 03:10 file3
-rwxrwxrwx. 1 student student  0 Apr  6 03:10 file4
-rwxrwxrwx. 1 student student  0 Apr  6 03:10 file5
drwxr-xr-x. 2 root    root    18 Apr  6 03:13 test
[root@localhost mnt]# rsync -r /mnt/test root@172.25.254.113:/mnt
root@172.25.254.113's password: 同步/mnt/test目录在172.25.254.113/mnt中只会出现test目录
[root@localhost mnt]# rsync -rp /mnt/ root@172.25.254.113:/mnt   不忽略文件权限
root@172.25.254.113's password:
[root@localhost mnt]# rsync -rpg /mnt/ root@172.25.254.113:/mnt    不忽略文件权限以及组
root@172.25.254.113's password:
[root@localhost mnt]# rsync -rpgo /mnt/ root@172.25.254.113:/mnt  不忽略文件权限,所有组,所有人
root@172.25.254.113's password:
[root@localhost mnt]# rsync -rpgot /mnt/ root@172.25.254.113:/mnt  不忽略文件权限,所有组,所有人时间戳

root@172.25.254.113's password:

(客户端)[root@localhost ~]# cd /mnt

[root@localhost mnt]# ls
[root@localhost mnt]# ls
file1  file2  file3  file4  file5
[root@localhost mnt]# ll   此时只同步了文件
total 0
-rwxr-xr-x 1 root root 0 Apr  6 03:12 file1
-rwxr-xr-x 1 root root 0 Apr  6 03:12 file2
-rwxr-xr-x 1 root root 0 Apr  6 03:12 file3
-rwxr-xr-x 1 root root 0 Apr  6 03:12 file4
-rwxr-xr-x 1 root root 0 Apr  6 03:12 file5
[root@localhost mnt]# rm -fr *
[root@localhost mnt]# ls
test
[root@localhost mnt]# ll
total 0
drwxr-xr-x 2 root root 18 Apr  6 03:14 test
[root@localhost mnt]# ls /mnt/test
file8
[root@localhost mnt]# ls -ld test
drwxr-xr-x 2 root root 18 Apr  6 03:14 test
[root@localhost mnt]# rm -fr *
[root@localhost mnt]# ll
total 0
drwxr-xr-x 2 root root 18 Apr  6 03:17 test
[root@localhost mnt]# rm -fr *
[root@localhost mnt]# ll
total 0
[root@localhost mnt]# ll   此时同步了文件权限
total 0
-rwxrwxrwx 1 root root  0 Apr  6 03:18 file1
-rwxrwxrwx 1 root root  0 Apr  6 03:18 file2
-rwxrwxrwx 1 root root  0 Apr  6 03:18 file3
-rwxrwxrwx 1 root root  0 Apr  6 03:18 file4
-rwxrwxrwx 1 root root  0 Apr  6 03:18 file5
drwxr-xr-x 2 root root 18 Apr  6 03:18 test
[root@localhost mnt]# rm -fr *
[root@localhost mnt]# ll   此时同步了所有组
total 0
-rwxrwxrwx 1 root student  0 Apr  6 03:18 file1
-rwxrwxrwx 1 root student  0 Apr  6 03:18 file2
-rwxrwxrwx 1 root student  0 Apr  6 03:18 file3
-rwxrwxrwx 1 root student  0 Apr  6 03:18 file4
-rwxrwxrwx 1 root student  0 Apr  6 03:18 file5
drwxr-xr-x 2 root root    18 Apr  6 03:18 test
[root@localhost mnt]# rm -fr *
[root@localhost mnt]# ll   此时同步了所有人
total 0
-rwxrwxrwx 1 student student  0 Apr  6 03:19 file1
-rwxrwxrwx 1 student student  0 Apr  6 03:19 file2
-rwxrwxrwx 1 student student  0 Apr  6 03:19 file3
-rwxrwxrwx 1 student student  0 Apr  6 03:19 file4
-rwxrwxrwx 1 student student  0 Apr  6 03:19 file5
drwxr-xr-x 2 root    root    18 Apr  6 03:19 test
[root@localhost mnt]# rm -fr *
[root@localhost mnt]# ll   此时同步了时间戳
total 0
-rwxrwxrwx 1 student student  0 Apr  6 03:10 file1
-rwxrwxrwx 1 student student  0 Apr  6 03:10 file2
-rwxrwxrwx 1 student student  0 Apr  6 03:10 file3
-rwxrwxrwx 1 student student  0 Apr  6 03:10 file4
-rwxrwxrwx 1 student student  0 Apr  6 03:10 file5
drwxr-xr-x 2 root    root    18 Apr  6 03:13 test
[root@localhost mnt]# rm -fr *
(服务端)[root@localhost mnt]# ll
total 0
-rwxrwxrwx. 1 student student  0 Apr  6 03:10 file1
-rwxrwxrwx. 1 student student  0 Apr  6 03:10 file2
-rwxrwxrwx. 1 student student  0 Apr  6 03:10 file3
-rwxrwxrwx. 1 student student  0 Apr  6 03:10 file4
-rwxrwxrwx. 1 student student  0 Apr  6 03:10 file5
drwxr-xr-x. 2 root    root    18 Apr  6 03:13 test
[root@localhost mnt]# ln -s /mnt/file1 /mnt/westos
[root@localhost mnt]# ll
total 0
-rwxrwxrwx. 1 student student  0 Apr  6 03:10 file1
-rwxrwxrwx. 1 student student  0 Apr  6 03:10 file2
-rwxrwxrwx. 1 student student  0 Apr  6 03:10 file3
-rwxrwxrwx. 1 student student  0 Apr  6 03:10 file4
-rwxrwxrwx. 1 student student  0 Apr  6 03:10 file5
drwxr-xr-x. 2 root    root    18 Apr  6 03:13 test
lrwxrwxrwx. 1 root    root    10 Apr  6 03:40 westos -> /mnt/file1
[root@localhost mnt]# rsync -r /mnt root@172.25.254.113:/mnt
root@172.25.254.113's password:
skipping non-regular file "mnt/westos"
[root@localhost mnt]# rsync -rl /mnt root@172.25.254.113:/mnt    链接
root@172.25.254.113's password:
[root@localhost mnt]# ll /dev/pts
total 0
crw--w----. 1 root tty  136, 0 Apr  6 02:50 0
crw--w----. 1 root tty  136, 1 Apr  6 03:44 1
c---------. 1 root root   5, 2 Apr  5 22:06 ptmx
[root@localhost mnt]# rsync -r /dev/pts root@172.25.254.113:/mnt
root@172.25.254.113's password:
skipping non-regular file "pts/0"
skipping non-regular file "pts/1"
skipping non-regular file "pts/ptmx"
[root@localhost mnt]# rsync -rD /dev/pts root@172.25.254.113:/mnt     设备
root@172.25.254.113's password:
[root@localhost mnt]# ll
total 0
-rwxrwxrwx. 1 student student  0 Apr  6 03:10 file1
-rwxrwxrwx. 1 student student  0 Apr  6 03:10 file2
-rwxrwxrwx. 1 student student  0 Apr  6 03:10 file3
-rwxrwxrwx. 1 student student  0 Apr  6 03:10 file4
-rwxrwxrwx. 1 student student  0 Apr  6 03:10 file5
drwxr-xr-x. 2 root    root    18 Apr  6 03:13 test
lrwxrwxrwx. 1 root    root    10 Apr  6 03:40 westos -> /mnt/file1
[root@localhost mnt]# rm -fr *
(客户端)[root@localhost mnt]# ll
total 0
drwxr-xr-x 3 root root 77 Apr  6 03:42 mnt
[root@localhost mnt]# ll mnt
total 0
-rwxr-xr-x 1 root root  0 Apr  6 03:42 file1
-rwxr-xr-x 1 root root  0 Apr  6 03:42 file2
-rwxr-xr-x 1 root root  0 Apr  6 03:42 file3
-rwxr-xr-x 1 root root  0 Apr  6 03:42 file4
-rwxr-xr-x 1 root root  0 Apr  6 03:42 file5
drwxr-xr-x 2 root root 18 Apr  6 03:42 test
[root@localhost mnt]# rm -fr *
[root@localhost mnt]# ll
total 0
[root@localhost mnt]# ll /mnt
total 0
drwxr-xr-x 3 root root 90 Apr  6 03:43 mnt
[root@localhost mnt]# ll mnt
total 0
-rwxr-xr-x 1 root root  0 Apr  6 03:43 file1
-rwxr-xr-x 1 root root  0 Apr  6 03:43 file2
-rwxr-xr-x 1 root root  0 Apr  6 03:43 file3
-rwxr-xr-x 1 root root  0 Apr  6 03:43 file4
-rwxr-xr-x 1 root root  0 Apr  6 03:43 file5
drwxr-xr-x 2 root root 18 Apr  6 03:43 test
lrwxrwxrwx 1 root root 10 Apr  6 03:43 westos -> /mnt/file1
[root@localhost mnt]# rm -fr *
[root@localhost mnt]# ll
total 0
[root@localhost mnt]# ll
total 0
drwxr-xr-x 2 root root 6 Apr  6 03:45 pts
[root@localhost mnt]# ll pts
total 0
[root@localhost mnt]# rm -fr *
[root@localhost mnt]# ll
total 0
[root@localhost mnt]# ll pts
total 0
crw------- 1 root root 136, 0 Apr  6 03:46 0
crw------- 1 root root 136, 1 Apr  6 03:46 1
c--------- 1 root root   5, 2 Apr  6 03:46 ptmx













  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值