1.scp
##速度慢
scp file user@ip:/dir ##上传
scp user@ip:/file dir ##下载
2.rsync
##远程同步,速度快,默认会忽略:文件属性,链接文件,设备文件
-r ##同步目录
-p ##同步权限
-o ##同步文件所有人
-g ##同步文件所有组
-l ##同步链接
-D ##同步设备文件
-t ##同步文件时间戳
示例:
1.-r,-p,-o,-g
首先在/mnt/创建文件,改变权限,所有人,所有组
使用
rsync -r /mnt/ [email protected]:/mnt/ ##只同步目录
使用
rsync -rp /mnt/ [email protected]:/mnt/ ##同步文件权限
使用
rsync -rpo /mnt/ [email protected]:/mnt/ ##同步文件权限与所有人
使用
rsync -rpog /mnt/ [email protected]:/mnt/ ##同步文件权限、所有人和所有组
2.-l
给/mnt/file1建立快捷方式file
ln -s /mnt/file1 /mnt/file
链接被同步
3.-D
/dev/pts是一个字符设备
使用
rsync -r /dev/pts [email protected]:/mnt/
无法同步设备文件,因此使用
rsync -rD /dev/pts [email protected]:/mnt/
成功同步
4.-t
同步文件时间戳
两种方式的差别
3.文件的归档
tar ##归档文件(把很多个文件变成一个文件)
-c ##创建
-v ##显示过程
-f ##指定归档文件名称
tar cfv test.tar /etc/
-x ##解档
tar xf test.tar
-t ##查看归档文件内容
tar tf test.tar
-r ##添加文件到归档中
tar rf test.tar file
–get ##解档指定文件
tar f test.tar --get file
–delete ##删除归档中的指定文件
tar f test.tar --delete file
-C ##指定解档到目录
tar xf test.tar -C /mnt/
4.压缩
zip
zip -r test.tar.zip test.tar ##zip压缩
unzip test.tar.zip ##解压
gzip
gzip test.tar ##gz压缩
gunzip test.tar.gz ##解压
bzip2
bzip2 test.tar ##bz2压缩
bunzip2 test.tar.bz2 ##解压
xz
xz test.tar ##xz压缩
unxz test.tar.xz ##解压
5.归档并压缩
tar jcf etc.tar.bz2 /etc/ ##压缩
tar jxf etc.tar.bz2 ##解压
tar zcf etc.tar.gz /etc/ ##压缩
tar zxf etc.tar.gz ##解压
tar Jcf etc.tar.xz /etc/ ##压缩
tar Jxf etc.tar.xz ##解压