logo
关于我们

技术分享

技术分享 linux命令4(归档文件)

linux命令4(归档文件)

2021-06-28

一、tar(归档工具)
参数及功能:

-c创建一个新的打包文件
-f指向一个归档文件
-z以gzip 形式将打包的文件压缩
-j以bzip2 形式将打包的文件压缩
-t查看归档文件内容
–delete删除etc.tar下的etc/hosts
-r向打包文件中追加新内容
-v查看详细信息
-x解压
-xz解压gzip压缩的归档文件
-C指定解压路径
–remove -files打包压缩的同时删除原文件
&&两步,前一步解压文件,后一步把源文件删除

(1)tar -cf etc.tar /etc/
/etc/: 被归档的文件

  例:[root@demo6 bak]# tar -cf bak.tar /bak/

(2)tar -czf boot.tar.gz /boot/

例:[root@demo6 bak]# tar -czf bak.tar.gz  /bak/

(3)tar -cjf  boot.tar.bz2  /tmp/

    例:[root@demo6 bak]# tar -cjf bak.tar.bz2 / bak/

(4)tar -tf etc.tar

    例:[root@demo6 bak]# tar -tf bak.tar
			bak/
			bak/file2.txt
			bak/file1.txt
			bak/file3.txt
			bak/file5.txt
			bak/file4.txt	

(5)tar --delete /etc/hosts -f etc.tar

    例:[root@demo6 bak]# tar --delete bak/file3.txt -f bak.tar
			[root@demo6 bak]# tar -tf bak.tar
			bak/
			bak/file2.txt
			bak/file1.txt
			bak/file5.txt
			bak/file4.txt

(6)tar -f etc.tar -r /root/anaconda-ks.cfg.bak

    例:[root@demo6 bak]# tar -f bak.tar -r /bak/passwd
tar: Removing leading `/' from member names
[root@demo6 bak]# tar -tf bak.tar
bak/
bak/file2.txt
bak/file1.txt
bak/file5.txt
bak/file4.txt
bak/passwd

(7)tar -tvf etc.tar |grep hosts

(8)tar  -xzf  boot.tar.gz

    例:[root@demo6 bak]# tar -xzf bak.tar.gz
		[root@demo6 bak]# ls
		bak      bak.tar.bz2  file1.txt  file3.txt  file5.txt
		bak.tar  bak.tar.gz   file2.txt  file4.txt  passwd

(9)tar xjf boot.tar.bz2

    例:[root@demo6 bak]# tar xjf bak.tar.bz2
		[root@demo6 bak]# ls
		bak      bak.tar.bz2  file1.txt  file3.txt  file5.txt
		bak.tar  bak.tar.gz   file2.txt  file4.txt  passwd

(10) tar xjf boot.tar.bz2 -C test/

    例:[root@demo6 bak]# tar xjf bak.tar.bz2 -C /abc/

(11)tar -czf test.tar.gz file* --remove-files

   例:[root@demo6 abc]# ls
bak    file10      file2  file4  file6  file8  test0
file1  file{1-10}  file3  file5  file7  file9
[root@demo6 abc]#
[root@demo6 abc]#
[root@demo6 abc]# tar -czf test.tar.gz file* --remove-files
[root@demo6 abc]# ls
bak  test0  test.tar.gz

(12)tar xzvf test.tar.gz && rm -rf  test.tar.gz

    例:[root@demo6 abc]# ls
			bak  test0  test.tar.gz
			[root@demo6 abc]# tar xzvf test.tar.gz&& rm -rf test.tar.gz
			file1
			file10
			file{1-10}
			file2
			file3
			file4
			file5
			file6
			file7
			file8
			file9
			[root@demo6 abc]# ls
			bak    file10      file2  file4  file6  file8  test0
			file1  file{1-10}  file3  file5  file7  file9

二、cpio

参数及功能:

-t看归档内容
-F指定归档文件
-ocopy-out 模式
-A追加新文件
-icopy-in模式,提取
-d需要时自动创建目录
-v显示详细信息
-pcopy-pass模式

(1)find ./ -depth |cpio -ov -F tree1.cpio
把当前文件归档到了tree1.cpio,tree.cpio里面有本身

    [root@demo6 Lucille]# find ./ -depth |cpio -ov -F tree1.cpio
	./file1.txt
	./file2.txt
	./file3.txt
	./file5.txt
	./file0.txt
	./file10.txt
	./file4.txt
	./file8.txt
	./file9.txt
	./file7.txt
	./file6.txt
	./
	1 block

(2)find ./ -depth |cpio -ov -F /tmp/tree1.cpio
把当前的文件归档到/tmp/目录下

    [root@demo6 Lucille]# find ./ -depth |cpio -ov -F /tmp/tree1.cpio
	./file1.txt
	./file2.txt
	./tree1.cpio
	./file3.txt
	./file5.txt
	./file0.txt
	./file10.txt
	./file4.txt
	./file8.txt
	./file9.txt
	./file7.txt
	./file6.txt
	./
	2 blocks
	[root@demo6 Lucille]# cd /tmp
	[root@demo6 tmp]# ls
	log  tree1.cpio  yum.log  yum_save_tx-2019-07-31-11-1362zRF1.yumtx

(3)find ./ -depth -print0|cpio  --null -ov -F /tmp/tree1.cpio
–null : 解析空字符

			[root@demo6 Lucille]# find ./ -depth -print0|cpio  --null -ov -F /tmp/tree1.cpio
			./file1.txt
			./file2.txt
			./tree1.cpio
			./file3.txt
			./file5.txt
			./file0.txt
			./file10.txt
			./file4.txt
			./file8.txt
			./file9.txt
			./file7.txt
			./file6.txt
			./
			2 blocks

(4)cpio -t -F tree.cpio或者cpio -t < tree.cpio
查看tree.cpio下的归档内容

    [root@demo6 Lucille]# cpio -t -F tree1.cpio
	file1.txt
	file2.txt
	file3.txt
	file5.txt
	file0.txt
	file10.txt
	file4.txt
	file8.txt
	file9.txt
	file7.txt
	file6.txt
	./
	1 block
    [root@demo6 Lucille]# cpio -t < tree1.cpio
	file1.txt
	file2.txt
	file3.txt
	file5.txt
	file0.txt
	file10.txt
	file4.txt
	file8.txt
	file9.txt
	file7.txt
	file6.txt
	./
	1 block

(5)cpio -t -F /tmp/home1.cpio /root/*
查看home1.cpio 归档文件里的/root/下的内容(没有隐藏文件)

[root@demo6 Lucille]# cpio -t -F /tmp/tree1.cpio /root/*
2 blocks

(6)cpio -t -F /tmp/home1.cpio /root/.*
查看home1.cpio 归档文件里的/root/下的内容(全为隐藏文件)

    [root@demo6 Lucille]# cpio -t -F /tmp/tree1.cpio /root/.*
    2 blocks

(7)cpio -t -F /tmp/home1.cpio  /root/{.}
查看home1.cpio 归档文件里的/root/下的所有文件

    [root@demo6 Lucille]# cpio -t -F /tmp/tree1.cpio /root/{.*,*}
    2 blocks

(8)ls /root/test.txt |cpio -oA -F /tmp/home1.cpio
向归档文件中追加文件

    [root@demo6 tmp]# ls
	log  tree1.cpio  yum.log  yum_save_tx-2019-07-31-11-1362zRF1.yumtx
	[root@demo6 tmp]# ls /tmp/yum.log | cpio -oA -F /tmp/tree1.cpio
	2 blocks
	[root@demo6 tmp]# cpio -t -F tree.cpio
	cpio: Cannot open tree.cpio: No such file or directory
	[root@demo6 tmp]# cpio -t -F tree1.cpio
	file1.txt
	file2.txt
	tree1.cpio
	file3.txt
	file5.txt
	file0.txt
	file10.txt
	file4.txt
	file8.txt
	file9.txt
	file7.txt
	file6.txt
	./
	/tmp/yum.log
	3 blocks

(9)find /boot -depth -print0 |cpio -oA -F /tmp/home1.cpio
添加新目录

    [root@demo6 tmp]# ls
	log  tree1.cpio  yum.log  yum_save_tx-2019-07-31-11-1362zRF1.yumtx
	[root@demo6 tmp]# find /tmp/log -depth -print0 |cpio -oA /tmp/tree1.cpio
	cpio: Too many arguments
	[root@demo6 tmp]# cpio -t -F tree1.cpio
	file1.txt
	file2.txt
	tree1.cpio
	file3.txt
	file5.txt
	file0.txt
	file10.txt
	file4.txt
	file8.txt
	file9.txt
	file7.txt
	file6.txt
	./
	/tmp/yum.log
	3 blocks

(10)cpio -idv -F /tmp/home1.cpio
提取文件

    [root@demo6 tmp]# cpio -idv -F /tmp/tree1.cpio
	file1.txt
	file2.txt
	cpio: tree1.cpio not created: newer or same age version exists
	tree1.cpio
	file3.txt
	file5.txt
	file0.txt
	file10.txt
	file4.txt
	file8.txt
	file9.txt
	file7.txt
	file6.txt
	.
	cpio: /tmp/yum.log not created: newer or same age version exists
	/tmp/yum.log
	3 blocks

(10)find ~ -depth -print0 |cpio --null -pvd /tmp/abc
复制~下文件到/tmp/abc/root/

    [root@demo6 tmp]# find ~ -depth -print0 | cpio --null -pvd /tmp/abc
	/tmp/abc/root/test5/name
	/tmp/abc/root/test5
	/tmp/abc/root/.bash_profile
	/tmp/abc/root/fle1.xz
	/tmp/abc/root/test.zip
	/tmp/abc/root/test6
	/tmp/abc/root/test3.txt
	/tmp/abc/root/.lesshst
	/tmp/abc/root/anaconda-ks.cfg
	/tmp/abc/root/file3.zip
	/tmp/abc/root/test2.txt
	/tmp/abc/root/Lucille/file1.txt
	/tmp/abc/root/Lucille/file2.txt
	/tmp/abc/root/Lucille/tree1.cpio
	/tmp/abc/root/Lucille/file3.txt
	/tmp/abc/root/Lucille/file5.txt
	/tmp/abc/root/Lucille/file0.txt
	/tmp/abc/root/Lucille/file10.txt
	/tmp/abc/root/Lucille/file4.txt
	/tmp/abc/root/Lucille/file8.txt
	/tmp/abc/root/Lucille/file9.txt
	/tmp/abc/root/Lucille/file7.txt
	/tmp/abc/root/Lucille/file6.txt
	/tmp/abc/root/Lucille
	/tmp/abc/root/test1.txt
	/tmp/abc/root/erro
	/tmp/abc/root/.bash_logout
	/tmp/abc/root/.cshrc
	/tmp/abc/root/time.sh
	/tmp/abc/root/file3
	/tmp/abc/root/.bash_history
	/tmp/abc/root/app/index.html.gz
	/tmp/abc/root/app
	/tmp/abc/root/.tcshrc
	/tmp/abc/root/eername
	/tmp/abc/root/install.log
	/tmp/abc/root/test
	/tmp/abc/root/abc
	/tmp/abc/root/ceu
	/tmp/abc/root/TEST.zip
	/tmp/abc/root/err
	/tmp/abc/root/file1.gz
	/tmp/abc/root/test4.txt
	/tmp/abc/root/test5.txt
	/tmp/abc/root/.bashrc
	/tmp/abc/root/install.log.syslog
	/tmp/abc/root/time=date"+"%H.log
	/tmp/abc/root/test0.txt
	/tmp/abc/root/tes.bz2
	/tmp/abc/root/TEST
	/tmp/abc/root
	45 blocks

三、yum

参数及功能:

yum clean alll清除缓存,
yum makecache生成新的缓存
yum repolist enabled查看启用的仓库
yum repolist all查看所有的仓库


例:安装网易163yum源
(1)备份·

    [root@demo6 yum.repos.d]# mkdir repo_bak1
	[root@demo6 yum.repos.d]# mv *.repo repo_bak1/
	[root@demo6 yum.repos.d]# ls
	bak  repo_bak  repo_bak1  touch	
	

(2)下载新的CentOS6.8.repo放到/etc/yum.repos.d/

    [root@demo6 yum.repos.d]# cp /readme /etc/yum.repos.d/
	[root@demo6 yum.repos.d]# ls
	bak  readme  repo_bak  repo_bak1  touch

(3)之后运行yum clean all清除缓存,运行 yum makecache 生成新的缓存

linux命令4(归档文件)

(4)安装EPEL源
linux命令4(归档文件)
(5)再次运行yum clean all 清除缓存,运行 yum makecache 生成新的缓存

四、rpm(RPM软件管理程序)
(1)-i:安装

    rpm -ivh zip-3.0-11.el7.x86_64.rpm   安装。

(2)-e:卸载
–nodeps:不检查依赖

     例: rpm -e libestr(文件名)

(3)-U:升级或安装
-F:升级

    例:rpm -U libestr-0.1.9-2.e17.x86_64.rpm

(4)查询

rpm -qa查询所有已经安装的包
rpm -qf查询当前文件属于那个包
rpm -qi zip查看详细描述
rpm -ql zip查询软件安装的详细信息
rpm -qR zip查看依赖

五:源码包安装
源码包:自己定制化安装
“代码”---------》机器码(二进制0,1)编译器
yum gcc gcc-c++

建立/检查系统环境
编译
安装:
例:apache的具体安装过程:

linux命令4(归档文件)

2、安装编译器
yum install gcc gcc-c++
linux命令4(归档文件)
3、建立/检查安装环境
./configure --prefix=/usr/local/httpd/

linux命令4(归档文件)

Error: ARP-util not found 类似于这样的错误,缺少依赖。安装依赖。
yum install apr-devel   提示缺少apr ,但实际已安装;此时应该是缺少开发包
echo $?:编译后检查编译结果,结果为0,表示成功;结果非零,编译不成功。

linux命令4(归档文件)

4、编译
make :
echo $?
5、安装
make install
echo $?
6、启动
/data/httpd/bin/apachect1 start   “安装目录下的路径”

查看进程
ps -ef  |grep httpd
linux命令4(归档文件)
源码安装:三部曲
(1)建立/检查安装环境
(2)编译
(3)安装

云祺备份软件,云祺容灾备份系统,虚拟机备份,数据库备份,文件备份,实时备份,勒索软件,美国,图书馆
  • 标签:
  • 容灾备份

您可能感兴趣的新闻 换一批

现在下载,可享30天免费试用

立即下载