1.文件的复制
[root@localhost ~]# cp file /mnt/
[root@localhost ~]# ls /mntfile
2复制一个文件的同时并改名为file1
[root@localhost ~]# cp file /mnt/file1
[root@localhost ~]# ls /mnt
file file1
3.将文件从服务端传送到真机上
root@localhost Desktop]# scp wen kiosk@id:/home/kiosk/Desktop
kiosk@id's password:
wen 100% 0 0.0KB/s 00:00
如果要传送的文件的内容非常大时,采用scp 大大的降低了传送的效率,我们可以从下面的信息看出,需要耗费一部分时间。
root@localhost Desktop]# scp /etc/* kiosk@id:/home/kiosk/Desktop
kiosk@id's password:
/etc/abrt: not a regular file
adjtime 100% 16 0.0KB/s 00:00
aliases 100% 1518 1.5KB/s 00:00
aliases.db 100% 12KB 12.0KB/s 00:00
/etc/alsa: not a regular file
/etc/alternatives: not a regular file
anacrontab 100% 541 0.5KB/s 00:00
asound.conf 100% 55 0.1KB/s 00:00
...........................
此时可以采用rsync命令来进行同步传送
scp file username@ip:/dir ##上传
scp username@ip:/dir/file /dir ##下载
rsync [参数] file username@ip:/dir
rsync -r ##同步目录
-l ##不忽略链接
-p ##不忽略文件权限
-t ##不忽文件时间戳
-g ##不忽文件所有组
-o ##不忽文件所有人
-D ##不忽略设备文件
root@localhost Desktop]# rsync -g file root@id:/root/Desktop #同步组
root@id's password:
ot@localhost Desktop]# ll
total 0
-r--r--r--. 1 root student 0 Apr 12 08:46 file
root@localhost Desktop]# rsync -og file root@id:/root/Desktop #同步用户和组
root@id's password:
ot@localhost Desktop]# ll
total 4
-r--r--r--. 1 student student 0 Apr 12 08:51 file
-rw-r--r--. 1 root root 83 Apr 12 08:50 w
[root@localhost Desktop]# rsync -got file root@id:/root/Desktop #同步传送文件不忽略文件所属用户和组及其时间
root@id's password:
[root@localhost Desktop]# ll
总用量 4
-r--r--r--. 1 student student 0 4月 11 23:17 file
-rw-r--r--. 1 root root 217 4月 12 08:53 w
[root@localhost Desktop]# chmod 777 file
[root@localhost Desktop]# ll file
-rwxrwxrwx 1 student student 0 4月 11 23:17 file
[root@localhost Desktop]# rsync -pgot file root@172.25.254.225:/root/Desktop #同步文件所属用户和组及其时间和文件权限
root@172.25.254.225's password:
[root@localhost Desktop]# ll file
-rwxrwxrwx. 1 student student 0 4月 11 23:17 file
4、(1)打包 tar
文件归档,就是把多个文件变成一个归档文件
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格式压缩包
root@localhost Desktop]# tar cf etc.tar /etc/
tar: Removing leading `/' from member names
[root@localhost Desktop]# gzip etc.tar
[root@localhost Desktop]# gunzip etc.tar.gz
[root@localhost Desktop]# du -sh etc.tar.gz
du: cannot access ‘etc.tar.gz’: No such file or directory
[root@localhost Desktop]# du -sh etc.tar
30M etc.tar
[root@localhost Desktop]# tar zcf etc.tar.gz /etc
tar: Removing leading `/' from member names
[root@localhost Desktop]# tar zxf tar.gz
tar (child): tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
ot@localhost Desktop]# du -sh etc.tar
30M etc.tar
[root@localhost Desktop]# du -sh etc.tar.gz
8.4M etc.tar.gz
[root@localhost Desktop]# tar cf etc.tar /etc/
tar: Removing leading `/' from member names
[root@localhost Desktop]# bzip2 etc.tar
[root@localhost Desktop]# du -sh etc.tar
du: cannot access ‘etc.tar’: No such file or directory
[root@localhost Desktop]# du -sh etc.tar.bz2
14M etc.tar.bz2
[root@localhost Desktop]# bunzip2 etc.tar.bz2
[root@localhost Desktop]# du -sh etc.tar
30M etc.tar
[root@localhost Desktop]# tar jcf etc.tar.bz2 /etc
tar: Removing leading `/' from member names
-[root@localhost Desktop]# du sh etc.tar.bz2
15M etc.tar.bz2
[root@localhost Desktop]# tar jxf etc.tar.bz2
[root@localhost Desktop]# du -sh etc.tar.bz2
15M etc.tar.bz2
[root@localhost Desktop]# du -sh etc
34M etc
[root@localhost Desktop]# xz etc.tar
[root@localhost Desktop]# unxz etc.tar.xz
[root@localhost Desktop]# du -sh etc.tar
30M etc.tar
[root@localhost Desktop]# du -sh etc.tar.xz
du: cannot access ‘etc.tar.xz’: No such file or directory
[root@localhost Desktop]# xz etc.tar
[root@localhost Desktop]# du -sh etc.tar.xz
7.6M etc.tar.xz
[root@localhost Desktop]# tar Jcf etc.tar.xz /etc
tar: Removing leading `/' from member names
[root@localhost Desktop]# du -ah etc.tar.xz
5.7M etc.tar.xz
[root@localhost Desktop]# tar Jxf etc.tar.xz
[root@localhost Desktop]# du -sh etc.tar.xz
5.7M etc.tar.xz