linux学习笔记——打包、压缩、远程文件传输

############打包、压缩##########################

1.打包 (打包表示把一堆文件变成一个)
tar            ##打包工具
        -f        ##指定生成包的名字
        -c        ##创建包
        -v        ##显示创建过程
        -t        ##查看包中内容
        -x        ##解包
        -r        ##追加文件到包中
        -C        ##指定目录
        --delete filename  ##删除包中指定文件
        --get      filename  ##取出包中指定文件
eg:
tar -cf test.tar /etc/    ##生成包(ll -lh 查看大小,单位M)
tar -cvf test.tar         ##生成包,可以看到过程
tar -xf test.tar     ##解包到当前
tar -xvf test.tar     ##解包到当前,可以看到过程
tar -xf test.tar -C /mnt/     ##解包到/mnt/目录下
tar -tf test.tar    ##查看包中内容
tar -rf test.tar file    ##追加file文件到test.tar中
tar -f test.tar --get file    ##取出包中指定的file文件

2.压缩 (压缩通过特定的算法来减小计算机文件大小的机制)    
1)gzip
gzip test.tar          ##压缩test.tar===>test.tar.gz格式
gunzip    test.tar.gz    ##解压test.tar.gz===>test.tar
gzip -d 压缩包名称    ##解压
分步操作:tar -cf test.tar /etc/      ##先要生成包
        gzip test.tar            ##gzip再压缩
一步操作:tar -zcvf test.tar.gz /etc/    ##一次性打包压缩文件

tar -zxvf test.tar.gz         ###解压test.tar.gz===>test

2)bz2
bzip2 test.tar             ##压缩test.tar =====> test.tar.bz2格式
bunzip2 test.tar.bz2         ##解压test.tar.bz2 =====> test.tar
tar jcvf test.tar.bz2 目标文件     ##一步打包压缩文件
tar jxvf test.tar.bz2        ##解压test.tar.bz2===>test

3)xz
xz test.tar                 ##压缩test.tar =====> test.tar.xz格式
unxz test.tar.xz             ##解压test.tar.xz =====> test.tar
tar Jcvf test.tar.xz 目标文件    ##一步打包压缩文件
tar Jxvf test.tar.xz        ##解压test.tar.xz===>test

4)zip(windows和linux都支持的格式,zip压缩会保留源文件)
zip -r test.tar.zip test.tar        ###对test.tar压缩(压缩目录要加-r,不然压缩比是0%)
unzip test.tar.zip            ###解压
eg:
zip test.zip /etc/        ##压缩/etc/
zip test.tar.zip test.tar    ##压缩test.tar===>test.tar.zip格式
格式:zip 压缩文件 源文件

注:先tar打包,在使用zip压缩的文件比直接压缩目录的文件要小

######################远程文件传输#####################
scp            ##远程复制(是新建的过程)
scp     file    user@ip:/directory        ##上传文件
scp -r  dir    user@ip:/directory        ##上传目录
scp     user@ip:/filename    /direcotry    ##下载文件
scp -r    user@ip:/directory    /direcotry    ##下载目录

eg:
scp -r test/ [email protected]:/root/Desktop
##把test目录远程传输到[email protected]:/root/Desktop
scp -r [email protected]:/root/Desktop/test1 /home/westos/Desktop  
##把[email protected]:/root/Desktop/test1文件传到本地桌面

rsync            ##远程同步(rsync会打包同步,比scp快)
        -a    ##归档模式,以递归方式传输,并保持所有文件属性    
        -r    ##同步目录
        -l    ##不忽略软链接
        -H    ##保留硬链接
        -p    ##不忽略权限(permission,属性完全一致)
        -t    ##不忽略时间戳
        -g    ##不忽略属组信息
        -o    ##不忽略属主信息
        -D    ##不忽略设备文件
        -z    ##对备份的文件在传输时进行压缩处理
        -v    ##详细模式输出
        --stats        ##给出某些文件的传输状态
        --delete    ##删除目标目录中有而源目录重没有的多余文件。(下面两个靠谱)
        --delete-before    ##在同步之前作比较,删除目标目录中有而源目录重没有的多余文件。
        --delete-after    ##在同步之后,删除目标目录中有而源目录重没有的多余文件。

rsync file|direcotry user@ip:/directory
rsync user@ip:/directory(是目标) /directory

eg:rsync [email protected]:/mnt/*  /mnt    #同步172.25.8.11的/mnt目录内容到本地/mnt

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章