第8天压缩 xarges sed命令 yum配置 rpm包文件修复

seq 10 |xargs echo
1 2 3 4 5 默认跟 echo \n换成空格

[root@centos7 ~]#seq  1 10 |xargs echo

[root@centos7 ~]#seq  1 10 |xargs 
1 2 3 4 5 6 7 8 9 10
[root@centos7 ~]#seq  1 10 |xargs  echo
1 2 3 4 5 6 7 8 9 10
[root@centos7 ~]#

xargs 默认是属于把所有 前一个命令输入如果输出显示是空行则把空行空格全部压缩成为单个空格在输出

seq 10 |xargs -n 2
强制限定行参数问2

[root@centos7 ~]#seq 1 10 |xargs  -n 2
1 2
3 4
5 6
7 8
9 10

echo user{1..10} |xargs -n 1 useradd

[root@centos7 ~]#echo user{1..10} |xargs -n 1  useradd
[root@centos7 ~]#`echo "user1 user2 " |xargs -n 1  passwd  `< f1
echo {1..100000}|  xargs  > f1  用echo打印数字

xargs 按达到一定条件就换行
10万只换了5次

xargs 经常配合find 命令
find -print0 |xargs -0
find -print0 用ascii的0作为分隔符

compress 默认是f1.Z
-c 是把压缩文件输出显示
-d 解压缩
-v显示过程
comprees -d -c 123.z > 123

compress和gzip如果有后缀系统自动生成颜色
compress 和gzip使用格式都是zcat

compress
gzip
gzip --help
gunzip
只能压缩文件,先用打包工具打包并压缩

m
compress m
m.z

gzip m
m.gz
gzip -d m.gz

gunzip m.gz

gzip -c m > m1.gz 把压缩结果重定向文件

gzip 可以标准输入压缩,对一些命令执行结果
zcat m1.gz 解压缩打印屏幕

cat m | gzip >m2.gz 优势不一定是文件可以是命令执行结果,例如数据库备份
执行mysql查询之后gzip 压缩

[root@centos7 test]#find / -name "*.sh" -ls |gzip >f1.gz
lscpu |gizp >f1.gz
gzip -c f1 只是把压缩结果显示在屏幕上

zcat f1.gz

bzip2 ...file.. 后缀是.bz2 压缩比比gzip高

[root@centos7 test]#bzip2 -k f1
[root@centos7 test]#ll
total 8748
-rw-r--r-- 1 root root 38990 Mar 21 21:00 f1
-rw-r--r-- 1 root root 5304 Mar 21 21:00 f1.bz2
-k keep 保留原始文件
-d 解压缩
bunzip2
bzcat m.bz2 看源文件

[root@centos7 test]#expr bzcat f1.bz2 |wc -c / 1024
38k
先看解压缩文件有多大在去做处理

xz 如内核网站 后缀.xz 比bzip 又强大 xz比较慢 但压缩比高
-k
-d
-#
xzcat m.xz

xz--help
gzip -r 压缩文件夹里的文件
cp /etc/fstab f1
cp /etc/fstab f2
mkdir dir
[root@centos7 test]#gzip -r dir
[root@centos7 dir]#ll
total 8
-rw-r--r-- 1 root root 344 Mar 21 21:33 f1.gz
-rw-r--r-- 1 root root 344 Mar 21 21:33 f2.gz
gzip -r 压缩文件夹里的每个文件

zip可以压缩文件夹 ,window又发送到 压缩zip文件夹
[root@centos7 test]#zip -r bbb dir
adding: dir/ (stored 0%)
adding: dir/f1 (deflated 46%)
adding: dir/f2 (deflated 46%)

zip -r 压缩名字 目标文件夹

[root@centos7 test]#unzip -p bbb.zip 显示文件全部

zip -r /dir /data/test/dir /dir 压缩生产文件名 后边是压缩文件
unzip dir.zip
recurse into directories 递归压缩文件夹

cpio格式

du -sh /etc 看etc文件多大

tar (tape aRchive 磁带存档 ) 支持打包和压缩
tar -cpvf /path/file.tar file p保留权限 tar保留不了acl权限 c表示创建打包文件
f后边跟上打包生成结果

-r -f 追加
-t -f 预览

tar 不加横线bsd风格 加 -tvf unix风格
tar -xvf etc.tar
tar 把斜线路径删了变相对路径就是,自己当前目录
tar -C /mnt指定解压目录

-j bzip2 -zcvf -Jcvf
tar.bz2 tar.gz tar.xz

打包排除一些文件 -exclude
-exclude=/etc/xxx
-T, --files-from=FILE get names to extract or create from FILE
--unquote unquote filenames read with -T (default)

-X, --exclude-from=FILE exclude patterns listed in FILE

tar zcvf mybackup.tgz -T /root/includefilelist -X /root/excludefileli

指定输入文件列表,排除文件列表

网站上传有限制,这样可以切割上传
split 切割小文件
split -b SIZE -d 文件名 切割文件前缀
split -b 5M -d etc.tar etc.tar
切文件列成数字
split -b 5M etc.tar etc.tar
切割文件列成字母
cat etctar* >etc2.tar


[root@centos7 test]#split -b 2000 -d f3.tar.bz  f3tarbz
-rw-r--r-- 1 root root    2000 Mar 22 08:56 f3tarbz00
-rw-r--r-- 1 root root    2000 Mar 22 08:56 f3tarbz01
-rw-r--r-- 1 root root    2000 Mar 22 08:56 f3tarbz02
-rw-r--r-- 1 root root    1180 Mar 22 08:56 f3tarbz03
[root@centos7 test]#cat f3tarbz* >f31.tar.bz
-rw-r--r-- 1 root root    7180 Mar 22 08:58 f31.tar.bz
-rw-r--r-- 1 root root    7180 Mar 22 08:44 f3.tar.bz

[root@centos7 test]#split -b 2000  f3.tar.bz  f3tarbz

看一下 initramfs-3.10.0-957.el7.x86_64.imgzip
cpio cpio本身也是打包
cd /boot .img flie 看一下
[root@centos7 boot]#cpio -tv < initramfs-3.10.0-957.el7.x86_64.img
drwxr-xr-x 3 root root 0 Mar 5 20:39 .
drwxr-xr-x 3 root root 0 Mar 5 20:39 kernel
drwxr-xr-x 3 root root 0 Mar 5 20:39 kernel/x86

cpio也是打过包的文件
cpio -o 打包过程 从内存输出到磁盘
-i 从磁盘 输入到内存 解包过程
-I 指定文件名

cp -r /etc/ /test/
find etc |cpio -ov >etc.cpio
cpio -tv< etc.cpio 预览
cpio -idv < etc.cpio 解包并且生成文件夹

ldd查询文件所依赖的库

ldd /bin/cat
linux-vdso.so.1 => (0x00007ffcfddbc000)

sed强大命令 sed可以修改文件 sed支持正则表达式 sed对后项引用很多

sed 是基于行的方式处理 流编辑器 grep也是捉行

sed pattern space
每次只读1行 <----- 文件
读一行,.然后修改,删除在打印屏幕
之后读第二行,然后处理第二行
' '这里命令和位置都是按每一行操作


[root@centos7 test]#sed  -n  -e   's@^UUID@SUPER@' -e  '/7/p' /etc/fstab

SUPER=d622b96a-4877-4e69-a04c-7fc1b6b8f106 /                       xfs     defaults        0 0
SUPER=45de8522-3568-4aac-b057-9491eb40ff58 /boot                   xfs     de

首先在模式空间对uuid进行替换并且不再屏幕上打印,之后再模式空间替换把/7/打印


[root@centos7 test]#sed  -n  -e   '/7/p' -e  's@^UUID@SUPER@' /etc/fstab
# Created by anaconda on Tue Mar  5 20:25:07 2019
UUID=d622b96a-4877-4e69-a04c-7fc1b6b8f106 /                       xfs     defaults        0 0
UUID=45de8522-3568-4aac-b057-9491eb40ff58 /boot                   xfs     defaults        0 0
首先先对模式空间的7匹配打印到屏幕上,之后后把模式空间uuid替换super不输出屏幕

[root@centos7 test]#sed  -n  -e   '/7/p' -e  's@^UUID@SUPER@p' /etc/fstab
# Created by anaconda on Tue Mar  5 20:25:07 2019
UUID=d622b96a-4877-4e69-a04c-7fc1b6b8f106 /                       xfs     defaults        0 0
SUPER=d622b96a-4877-4e69-a04c-7fc1b6b8f106 /                       xfs     defaults        0 0

首先先对模式空间的7匹配打印到屏幕上,之后后把模式空间uuid替换super输出屏幕

[root@centos7 test]#sed  -n '/7/p'  /etc/fstab |sed    's@^UUID@SUPER@'
[root@centos7 test]#sed  -n '/7/p'  /etc/fstab |sed  -n  's@^UUID@SUPER@p' 
效果一样

sed 'script' input文件
脚本
地址是过滤哪一行
命令执行替代删除
script 是空则全部行

p打印模式空间内容
sed 默认打印模式空间匹配内容

cp /etc/paswd /test/
sed '' passwd sed读入内容自动打印 读入一行显示一行
sed 'p' passwd 则显示2行 p把前边指定行打印
sed -n ' ' passwd 不打印模式空间内容

[root@centos7 test]#sed   '/^1/p'  f1
111
111
222
333

/^1/p 从模式空间找到^1的打印出来

sed '10p' passwd
#p #行号

sed支持管道

sed -n '2p' passwd 只打印第二行
sed -n '/parrern/p' 正则表达式
sed -n$!p passwd 除了最后一行其他行都打印
!取反
[root@centos7 test]#sed -n '$!p' f1
111
222
意识就是最后一行不打印其他行打印

111
222
333
[root@centos7 test]#sed  -n -e  's@^22.*@@'  -e  'w/data/test/f4'  f1
[root@centos7 test]#cat f4
111

333 把模式空间222替换为空并且保存到f4

df | sed -n '/^#/p' /fstab
sed -n $p passwd 最后一行打印

sed -n '3,6p' 打印3到6
-n '3,+3p'
-n '/part1/,/part2/p'
-n '/^a/,/^s/p' passwd只要a 开头的行就找 ,只要有s才结束

打印行号是-n

root@centos7 test]#sed  '=' f1
1
111
2
222
3
333

9点到10点
grep "24/May" access_log |sed -n '/2018:09:/p'

grep "24/May" access_log |sed -n '/2018:09:3/,/2018:09:50/p'

sed 如果后行找不到就全显示

seq10 |sed '1~2p'
每次递增
'2~3p'

[root@centos7 test]#seq 10  |sed -n '2~2p'
2
4
6
8
10
[root@centos7 test]#seq 10  |sed -n '2~3p'
2
5
8

sed '2d' 删除第二行

[root@centos7 test]#cat f4
111
333[root@centos7 test]#sed  -n -e  '2d'  -e  'w/data/test/f4'  f1

删除模式空间第二行并且 ,保存模式空间内容到f4

sed '/^#/d' /etc/fstab 删除模式空间井号开头的行
a 追加字符串
sed '/^#/a-----' /etc/fstab
sed -i.bak '/^#/aalias ls=hostname' /etc/fstab 修改文件做备份 不用.bak则直接修改

seq 10 |sed 'axyz' 默认换行显示
[root@centos7 test]#seq 3 | sed 'axyz'
1
xyz
2
xyz
3
xyz
seq 10 |sed 'a\ xyz直接在本行显示 转以符显示空格<br/>seq 10 |sed 'a\ xx\n'<br/>seq 10 |seda'''$user''''3个单引号引用变量
'ixyz' 在行前加xyz
[root@centos7 test]#name=name
[root@centos7 test]#seq 3 | sed 'a'''$name''''
1
name
2
name
3
name

[root@centos7 ~]#name=`ls`

[root@centos7 ~]#echo $name
111 222 early_cpio f1 f2 f3 f4 kernel passwd 非
命令不能在sed变量中引用```$user```  会出现大问题,会把搜索的所有文件打开
111
basher:x:1014:1016::/home/basher:/sbin/nologn
111
sh:x:1015:1017::/home/sh:/sbin/nologn
111
nologin:x:1016:1018::/home/nologin:/sbin/nologn
111
sed: can't read 非: No such file or directory

下边少了x回车的原因(\r回车)

[root@centos7 test]#seq 3 | sed 'ax\ryz'
1
yz
2
yz
3
yz

seq 10 |sed -n '3,6w seq2.log ' 把满足条件行放到f1.log文件w

[root@centos7 ~]#seq 10 | sed -n '3,6w  f1.log'
[root@centos7 ~]#cat f1.l 
3
4
5
6

seq 10 | sed 'r /etc/issue' 按行读入文件内容
``
[root@centos7 ~]#seq 2 | sed 'r /etc/issue' |less
1
\n
\t
\S
Kernel \r on an \m

2
\n
\t
\S
Kernel \r on an \m

首先把模式空间空白行分行打印 屏幕   同时第二个从模式空间找出空白行加行号分行打印

[root@centos7 ~]#sed -n -e '/^$/p' -e '/^$/=' f1

2

3

5

6


sed 是按行读取

seq 10 | sed '='  打印行行号

s@@@ 搜索替代 如vim  可以用正则表达式  
echo abc  | sed -r  's@(a).*@\1@g'  -r是扩展正则表达式

[root@centos7 ~]#echo abc |sed -r 's@^(a).*@\1@g'
a

cat /etc/default/grub | sed   '/CMD/s/(.*)"$/\1 xyz"/' 

把\1 \2分组中间加东西
[root@centos7 ~]#sed -r    '/CMD/s@(^.*)(["])$@\1 syz\2@'     /etc/default/grub 
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet syz"
这用1分组后表示
[root@centos7 ~]#sed -r    '/CMD/s@(^.*)"$@\1 syz"@'     /etc/default/grub 

echo  /aaa/bbb/ccc/  |sed -r 's@(.*/)([^/]+)/?$@\2@'

[root@centos7 ~]#echo /aaa/bbb/ccc/ |sed -r 's@(.*)/([^/]+)[/]?$@\2@'
ccc
[root@centos7 ~]#echo /aaa/bbb/ccc/ |sed -r 's@(.*)/([^/]+)[/]?$@\1@'
/aaa/bbb

ifconfig eth0 | sed -rn  '2s/.*inet//p'  |sed 's/ .*//'

先把inet 替换为空再把空格后的所有字符替换为空
ifconfig ens33 |sed -nr   '/\<inet\>/s@.*inet @@p'  |sed -r 's@ .*@@'

[root@centos7 ~]#ifconfig ens33 |sed -nr   '/\<inet\>/s@inet@@p'|sed -nr 's@^[ ]+([^ ]+).*@\1@p'

192.168.80.133

ifconfig eth0 | sed -rn  -e  '2s/.*inet//'    -e sed ''

[root@centos7 ~]#ifconfig ens33 |sed -rn -e  '2s/.*inet //'  -e '2s/ .*//p'
192.168.80.133
先在模式空间2行把.*inet 替换为空 之后在取模式空间第2行并且表现出来

ifconfig eth0  |sed -nr '2s/[^0-9]+([0-9.]+).*/\1/p'

vim sed.txt
s/root/&er/p/g

sed -f  sed.txt  passwd

网卡名不一样

net.ifnames=0
/boot/grup2/grub.cfg

sed  -n '/.*linux16/s@.*@& net.ifnames=0@p ' /boot/grup2/grub.cfg

[root@centos6 ~]#cat /etc/httpd/conf/httpd.conf 

sed '/^#/d;/^$/d'  2个命令一起做用分号隔开

-i.bak 是修改文件,并且备份一个以.bak结尾的源文件
[root@centos7 ~]#cat f1
11

22

[root@centos7 ~]#sed -i  'a\111' f1
[root@centos7 ~]#cat f1
11
111

111

111

[root@centos7 ~]#paste f1 f1.bak 
11  11
www 111
111 
www 111

www 111
111 22
www 111

模式空间 保持空间 如果模式空间处理没处理完 找个地方放保持空间放一放
待会再读回来
小p是读取模式空间内容输出到屏幕 先执行括号外 在执行括号内
P是在默认模式空间输出之前打印

[root@centos7 ~]#sed P   f1
111
111
222
222
333
333

[root@centos7 ~]#sed -n 'n;p' f1
222

-h 把模式空间覆盖 保持空间
-H 追加模式空间内容 进保持空间
g 把保持空间覆盖 模式空间
G 追加
d 删除模式空间行
D 删除模式空间第一行删了
n把下一行读进来


[root@centos7 ~]#cat f1
111
222
333
先读取下一行在
[root@centos7 ~]#sed -n 'n;p' f1
222

软件包管理

特定格式的文本文件就是源码,转换2进制才能真正执行

源码编译二进制安装
或者人家直接二进制包安装
rpm打包在1个文件中 缺陷依赖性问题 a 依赖b包 b依赖c包
红帽推出了 yum的解决依赖性的方案

红帽8.0版本centos 8.0 是dnf 管理代替yum管理

ubuntu软件管理

重点rpm yum
window格式和linux 格式不兼容
window PE 格式二进制
file /bin/cat
notepad.exe windows 不符合ABI接口标准

ABI
API 调用软件模块(如压缩功能,加密功能)
POSIX

编译语言安装步骤

源代码 ---预处理 -----编译 -----汇编 -----链接
文本文件简单处理 加行号 去注释 预处理.i文件 汇编转换.o文件
链接一些库 .a .so 通过第三方库结合起来
之后就能使用
静态编译 比如加密模块.a
A软件 链接 加密a模块
a软件 和 加密a模块链接一起
b软件 和 加密a模块链接一起
如果运行2个程序则ab都有加密a模块
动态编译动态库.so
A软件 链接 加密a
B软件
a,b软件系统运行,临时调用加密模块a
如果缺动态库则ab都不能运行

ldd /bin/cat 查看依赖库路径
ldd查询文件所依赖的库

ll /lib64/libc.so.6

重点库的作用比二进制程序更重要
如果库被移走 解决方法
mv /lib64/libc.so.6 /root
1esc 光盘插入按1次esc调出启动菜单 (工作中调bios) 在starting菜单中操作
2选3CD -ROM Drive 系统启动
3选第三个troubleshooting
4选2 Rescue a CentOS Linux system 救援 用光盘加载一个小的linux 启动时用光盘的linux 而不是硬盘输入,硬盘输入挂在/mnt/sysimage
5 选1continue
6 (chroot 改根/)不做
7df 查看根分区位置
8mv /mnt/sysimage/root/lib /mnt/sysimage/lib64
所有命令都是救援时光盘命令

作业 10 rm /lib64/libc.so.6

源码可以选择编译之后生成二进制 (想用什么功能取什么功能符合生产需求)
编译完整的二进制局限是固定在某个系统中

java2次编译过程

第一次是先中间编译的中间码 ,之后虚拟机系统转换解释执行
各个操作系统都有Java虚拟机

开发语言
c 面向操作系统 ,底层网络通信,内核,(apache)用系统级开发
c++

http2.4 .38
linux 5.0.3
解压缩 后缀.c就是c语言
tar -xvf

find linux / -name ".c" |wc -l
find linux / -name "
.c" |wc -l
cat find linux / -name "*.c" |wc -l

应用级开发
一个.c简单 但是多个.c编译很费劲
所以Debian 系统发明了package 的概念 专业公司把文件转换二进制打成包
红帽 包管理工具 rpm
debian deb文件用dpkg 管理工具
包是打包文件 ,有各种各样文件类似tar
rpm类似打包文件解压就能用

Packages 里全都是现成二进制文件

命名1软件名称 2版本号 3编译次数,打包次数 4红帽企业版5 x86 64 64位操作系统 i68632系统 noarch哪个cpu都行

ls .rpm |sed -nr 's/^..([^.]+).rpm$/\2/p' |sort |uniq -c

mount /dev/cdrom /mnt

神奇的自动挂载命令
[root@centos6 /]#ls /misc/cd
CentOS_BuildTag RELEASE-NOTES-en-US.html
EFI repodata
EULA RPM-GPG-KEY-CentOS-6
GPL RPM-GPG-KEY-CentOS-Debug-6
images RPM-GPG-KEY-CentOS-Security-6
isolinux RPM-GPG-KEY-CentOS-Testing-6
Packages TRANS.TBL

安装神奇自动挂载光盘目录autofs

1/在http://www.rpmfind.net官网找到autofs依赖安装hesiod-3.2.1-3.el7.x86_64.rpm在安装autofs

[root@centos6 Packages]#rpm -ivh /misc/cd/Packages/autofs-5.0.5-139.el6.x86_64.rpm

[root@centos7 mnt]#rpm -ivh /run/media/ckw/CentOS\ 7\ x86_64/Packages/hesiod-3.2.1-3.el7.x86_64.rpm

2把自动挂载和现在启动autofs打开
[root@centos7 mnt]#systemctl start autofs.service ;systemctl enable autofs.service

包可以分类 相关包分类
zlib - devel 开发相关
?包:分类和拆包Application-VERSION-ARCH.rpm: 主包
Application-devel-VERSION-ARCH.rpm 开发子包
Application-utils-VERSION-ARHC.rpm 其它子包
Application-libs-VERSION-ARHC.rpm 其它
lib
包之间有依赖关系 还有循环依赖 a--b--c--a
循环依赖一起装
yum 解决rpm包依赖性 yum要经过初始化配置

apt :deb
zypper suse
dnf 未来centos8 要代替yum 优点速度快

解包rpm rpm就是打包文件
rpm2cpio 包 |cpio -tv 转换rpm 变cpio

这个命令查看的 hesiod.so.0 -> libhesiod.so.0.0.0 对应库,也就是autofs对应库

rpm2cpio /run/media/ckw/CentOS\ 7\ x86_64/Packages/hesiod-3.2.1-3.el7.x86_64.rpm |cpio -tv

root@centos7 mnt]#rpm2cpio /run/media/ckw/CentOS\ 7\ x86_64/Packages/hesiod-3.2.1-3.el7.x86_64.rpm |cpio -tv
-rwxr-xr-x 1 root root 11360 Jun 10 2014 ./usr/bin/hesinfo
lrwxrwxrwx 1 root root 18 Jun 10 2014 ./usr/lib64/libhesiod.so.0 -> libhesiod.so.0.0.0

rpm包里文件
rpm属性信息,名称版本依赖包
rpm包的有些包有安装和卸载脚本

数据库/var/lib/rpm 初始化状态 各种以上信息 如果删了这个目录系统就分不清,那些包装那些没装
安装软件自动更新数据库以上数据库内容 ,哈希算法 ,初始化,
数据库可以校对rpm包源文件

mv /var/lib/rpm /data 移走则rpm查询无效

ll mariadb.
mirrors.sohu.com aliyun
www.mariadb.org

这是查看二进制文件库查看方法
[root@centos7 Packages]#ldd /bin/cat
linux-vdso.so.1 => (0x00007ffeb7bae000)
libc.so.6 => /lib64/libc.so.6 (0x00007f2df402e000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2df43fb000)

ldconfig 加载配置文件中指定的库

查看缓存本机所有库的文件名以及路径映射关系

[root@centos7 Packages]#/sbin/ldconfig -p /lib64/libc.so.6
libBrokenLocale.so.1 (libc6,x86-64, OS ABI: Linux 2.6.32) => /lib64/libBrokenLocale.so.1
libAnacondaWidgets.so.2 (libc6,x86-64) => /lib64/libAnacondaWidgets.so.2
ld-linux-x86-64.so.2 (libc6,x86-64) => /lib64/ld-linux-x86-64.so.2

配置文件:/etc/ld.so.conf, /etc/ld.so.conf.d/*.con
缓存文件:/etc/ld.so.cache
[root@centos7 Packages]#ll /etc |grep ld
-rw------- 1 root root 232 Oct 31 08:17 autofs_ldap_auth.conf
drwxr-x---. 7 root root 133 Mar 5 20:31 firewalld
-rw-r--r-- 1 root root 80058 Mar 22 17:38 ld.so.cache
-rw-r--r--. 1 root root 28 Feb 28 2013 ld.so.conf

epel 源 有些企业先把epel源都下载之后内部安装

rpmbuild 自己定制rpm包需要编写spark文件

rpm -ivh h显示进度## i安装 v显示过程

mount /dev/sr0 /mnt 临时挂载重启消失
centos 6 /misc
ls /misc/cd 命令自动挂载 直接挂载到/misc/cd
centos 7
1先装软件
rpm -ivh autofs- 5
在rpm官网解决autofs依赖关系
可能产生依赖关系
2在qq看启动

mount 命令看挂载情况
[root@centos7 cd]#mount
/dev/sr0 on /misc/cd type iso9660 (ro,nosuid,nodev,relatime,uid=1000,gid=1000,iocharset=utf8,mode=0400,dmode=0500)

umount /mnt

rpm -ivh vsftpd3-0.2 -25
[root@centos7 cd]#rpm -ivh /misc/cd/Packages/vsftpd-3.0.2-25.el7.x86_64.rpm


无意中把/usr/bin/tree 命令删了
[root@centos7 cd]#\rm -f /usr/bin/tree
1先查看一下tree里的文件
rpm2cpio /misc/cd/Packages/tree-1.6.0-10.el7.x86_64.rpm |cpio -tv
2tree转换cpio格式之后解压缩/usr/bin/tree 
[root@centos7 ~]#rpm2cpio /misc/cd/Packages/tree-1.6.0-10.el7.x86_64.rpm |cpio -id ./usr/bin/tree
3[root@centos7 ~]#mv  usr/bin/tree  /usr/bin/

vsftpd
rpm -q 包名 查询某个包 用包名 必须精准写包名才能查到
rpm -aq 显示所有包名
rpm -aq |grep vsf
rpm -aq "vsf*"

rpm -e 包名 卸载 包
rpm -q 包名 查询包全名安装版本系统信息
[root@centos7 bin]#rpm -q vsftpd
vsftpd-3.0.2-25.el7.x86_64
[root@centos7 bin]#rpm -q httpd
httpd-2.4.6-88.el7.centos.x86_64

vsftpd报警是因为缺key

--test 假装安装但不装 测试安装
[root@centos7 bin]#rpm -ivh --test /misc/cd/Packages/httpd-2.4.6-88.el7.centos.x86_64.rpm
Preparing... ################################# [100%]
package httpd-2.4.6-88.el7.centos.x86_64 is already installed

--nodeps 忽略依赖关系安装

rpm -ivh http-2.4.6
replacepkgs|replacefiles 两个文件一样强制把文件覆盖
--replacefiles ignore file conflicts between packages
忽略包之间的文件冲突覆盖
--replacepkgs reinstall if the package is already present
重新安装包文件
rpm -ivh --replacepkgs /misc/cd/Packages/tree-1.6.0-10.el7.x86_64.rpm
--nosignature: 不检查来源合法性
--nodigest:不检查包完整性

--noscripts:不执行程序包脚本
%pre: 安装前脚本 --nopre
%post: 安装后脚本 --nopost
%preun: 卸载前脚本 --nopreun
%postun: 卸载后脚本 --nopost

[root@centos7 bin]#rpm -q --scripts postfix   查询脚本信息
preinstall scriptlet (using /bin/sh):
# Add user and groups if necessary
/usr/sbin/groupadd -g 90 -r postdrop 2>/dev/null
/usr/sbin/groupadd -g 89 -r postfix 2>/dev/null
/usr/sbin/groupadd -g 12 -r mail 2>/dev/null

rpm -q tree
rpm -ql tree 查看tree依赖文件列表 也就是rpm文件里的文件
[root@centos7 bin]#rpm -ql tree
/usr/bin/tree
/usr/share/doc/tree-1.6.0
/usr/share/doc/tree-1.6.0/LICENSE
/usr/share/doc/tree-1.6.0/README
/usr/share/man/man1/tree.1.gz

\rm -f /usr/bin/tree

rpm -ivh /misc/cd/Pac/tree-1.6
rpm -ivh /misc/cd/Pac/tree-1.6 --replacepkgs 覆盖安装

rpm2cpio 文件 | 看qq如何操作

把tree删了
[root@centos7 bin]#rpm -ivh --replacepkgs  /misc/cd/Packages/tree-1.6.0-10.el7.x86_64.rpm 
无意中把/usr/bin/tree 命令删了
[root@centos7 cd]#\rm -f /usr/bin/tree
1先查看一下tree里的文件
rpm2cpio /misc/cd/Packages/tree-1.6.0-10.el7.x86_64.rpm |cpio -tv
2tree转换cpio格式之后解压缩/usr/bin/tree 
[root@centos7 ~]#rpm2cpio /misc/cd/Packages/tree-1.6.0-10.el7.x86_64.rpm |cpio -id ./usr/bin/tree
3[root@centos7 ~]#mv  usr/bin/tree  /usr/bin/
rpm权限都配好不容易出错  

--nosignature 安装软件需要检查签名看看合法来源,如果系统缺少签名,则会有这个检查
添加签名功能,把签名信息补全 ,
签名类似盖章
如猪肉盖章,盖章则安全
rpm 缺少相关签名文件则报警

--nodigest 如果看包破坏检查包的摘要
--noscript 不允许安装包脚本

rpm -U 如果有新版本就删除旧版本, 而且没有这个包就安装

rpm -U 升级版本则 旧包删除 升级慎重 (用的少)一般用新的机器重新安装
U既能安装又能升级
F 没有版本就不装 ,有新版本就成绩

--oldpackage 降级

--force 强制安装覆盖安装

内核问题,文件管理硬件管理文件系统
内核升级
用rpm内核文件升级
用安装软件升级内核

内核带版本号不会出现覆盖问题用安装方法让多个版本并存

远程安装就是把路径写上网络路径需映射文件夹使用

(1) 不要对内核做升级操作;Linux支持多内核版本并存,因此直接安装新版本内核
(2) 如果原程序包的配置文件安装后曾被修改,升级时,新版本提供的同一个配置文
件不会直接覆盖老版本的配置文件,而把新版本文件重命名(FILENAME.rpmnew)后
保留

rpm -ivh centos7.5 kernel-3.10 862 --force

rpm -ivh 包 7.5 --force 强制安装

想用新功能只能装内核
[root@centos7 Packages]#rpm -ivh kernel-3.10.0-862.el7.x86_64.rpm
rpm -e kernel-3.10 862

kernel-3.10.0-862.el7.x86_64.rpm
内核里的东西开机加载内存,所可以卸载内核,但开机则不能查到
rpm -ivh http://mirrors.sohu.com/centos/7.5.1804/os/x86_64/Packages/kernel-3.10.0-862.el7.x86_64.rpm --force

ip a 看机器联网
之后 os Page /文件 把网络连接复制

rpm -qf 文件 查询rpm数据库文件的指定包 rpm -qf /usr/bin/tree tree-1.6.0-10.el7.x86_64
rpm -q --whatprovides 文件 查询rpm数据库文件的指定包同上 rpm -q --whatprovides /lib64/libc.so.6 glibc-2.17-260.el7.x86_64

rpm -ql 包名 list 列出包文件信息 rpm -ql tree /usr/bin/tree /usr/share/doc/tree-1.6.0
rpm -qpl 包名文件光盘路或者联网路径 root@centos7 Packages]# 查询包非安装文件所有文件信息 rpm -qpl zziplib-utils-0.13.62-9.el7.x86_64.rpm

rpm -q 包名 --provides 查看包具有哪些能力就是给哪些包提供依赖

rpm -qa 包名 可以用通配符 查询已安装所有包 [root@centos7 ~]#rpm -aq kern* kernel-tools-libs-3.10.0-957.el7.x86_64

rpm -qi 包名 查询完成信息

rpm -qip 包名文件光盘路或者联网路径 查询位安装文件详细信息rpm -qip tree-1.6.0-10.el7.x86_64.rpm

如果一个包装了则这么查询
rpm -qi tree 查询详细包信息 URL 获取最新地址
http://mama.indstate.edu/users/ice/tree/
下载最新tree]

[root@centos7 ~]#rpm -qi tree
Name        : tree
Version     : 1.6.0
Release     : 10.el7
Architecture: x86_64
Install Date: Fri 22 Mar 2019 06:03:41 PM CST
Group       : Applications/File
Size        : 89505
License     : GPLv2+
Signature   : RSA/SHA256, Fri 04 Jul 2014 01:36:46 PM CST, Key ID 24c6a8a7f4a80eb5
Source RPM  : tree-1.6.0-10.el7.src.rpm
Build Date  : Tue 10 Jun 2014 03:28:53 AM CST
Build Host  : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://mama.indstate.edu/users/ice/tree/
Summary     : File system tree viewer
Description :
The tree utility recursively displays the contents of directories in a
tree-like format.  Tree is basically a UNIX port of the DOS tree
utility.

如果没装则 rpm -qip /misc/cd /P/ tree 要写文件路径 p是文件名不是包名
qpl 查询包要安装文件

rpm -qf /bin/cat 查寻文件来自那个包 ,
删文件不影响数据库则数据库依然能查
rm -f /usr/bin/tree
rpm -qf /usr/bin/tree
rpm -qi 包 看这个包信息 URL 之后看cat源码

rpm -q --whatprovides 看看文件需要的包
rpm -q --provids 看包具有那能力
rpm --whatrequires 看依赖性

rpm -qc bash 看bash包括哪些配置文件
rpm -qd 列文档

rpm --changelog bash 看每次版本更新日志
-R 反向查询 ,去看bash依赖的能力

rpm 校验 如安装包记录属性 看包校验ppt

rpm -V tree 看 tree属性是否有不同,所用的是数据库,
rpm -V tree
S.5....T. /usr/bin/tree

大小变化 哈希变,时间戳变化
包的校验
会检查包的签名就是章
安装检查包的合法性

rpm -K rpm包 查看包的完整性 报警原因缺少校验包的工具

1缺少key   先rpm -K  看一下有没有KEY

[root@centos6 Packages]#rpm -K tree-1.5.3-3.el6.x86_64.rpm 
tree-1.5.3-3.el6.x86_64.rpm: RSA sha1 ((MD5) PGP) md5 NOT OK (MISSING KEYS: (MD5) PGP#c105b9de)

2 rpm --import  光盘的KEY  安装

[root@centos6 Packages]#rpm --import /misc/cd/RPM-GPG-KEY-CentOS-6

3安装完成
[root@centos6 Packages]#rpm -K tree-1.5.3-3.el6.x86_64.rpm 
tree-1.5.3-3.el6.x86_64.rpm: rsa sha1 (md5) pgp md5 OK

4查看key
[root@centos6 Packages]#rpm -qa "gpg-*"
gpg-pubkey-c105b9de-4e0fd3a3

[root@centos7 Packages]#rpm -qa "gpg*"
gpgme-1.3.2-5.el7.x86_64
gpg-pubkey-f4a80eb5-53a7ff4b

毁坏命令tree如何查询看是否被毁备用是不是出厂

RPM-GPG 类似验钞机导入就可以检查包来源
把公钥文件导入系统中才能看包的合法性
rpm --import
rpm -qa ""
rpm -e
一旦导入包发生一点点损坏则包能查出
echo >>tree
rpm -K tree
[root@centos7 Packages]#rpm -K tree-1.6.0-10.el7.x86_64.rpm

在安装 rpm -ivh tree
则不报警

rpm 使用必须记住 安装卸载
ql qa
qi qf -e -i

centos 8 dnf

centos 7 yum 依赖一些服务器端口和配置

yum仓库必须通过共享方式发布网络,如
方式
ftp
http
https
yum仓库如mirrors.aliyun.com
客户端和服务器端在本机则不用

    OS

yum client yum server
config要写yum server path路径 repo仓库内容包含rpm包 和元数据(包的分组依赖性)
yum meta data

1先访问元数据yumserver repo,之后下载本机,yum meta data
2如果需要别的包下载到本地文件夹之后安装完成在删除
3yum install tree

1先看/etc/yum.conf 里如何配置yum
把配置文件放在 /etc/yum.repos.d 并且命名 file.repo

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

2 创建 一个backup文件夹 把.repo结尾文件放到 backup 此时仓库文件不生效了
[root@centos7 yum.repos.d]#mkdir backup
[root@centos7 yum.repos.d]#mv *.repo backup

3 配置yum源
1 [base]
2 name=aliyun base
3 baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/
4 #gpgcheck=
5 gpgkey=https://mirrors.aliyun.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7

https://mirrors.aliyun.com/centos/7/

看repo data 在哪就是哪是路径
1先看版本 cenots 7 赋值链接
2 cachedir= 下载文件夹
keepcache 0文件删除的
logfile= yum日志记录
gpgcheck= 1 1表示检查 默认检查 检查包合法性 rpm -K 1是把Key倒进去 2是不检查
in /etc/yum.repos.d/ 并且命名 file.repo 这个是config要写yum server path路径

vim base.repo
1必须写仓库编号
[base]
baseurl=路径
baseurl=路径不用写死要在centos 7 centos 6通用
gpgcheck=1 1检查为默认 0 设置为不检查
gpgkey= KEY 路径
name=aliyun base

y是安装 d是下载
key 导入也是yes
一定要知道包名
yum install httpd

建 epel.repo源
gpgcheck=0
yum repolist 列出所有yum源

[root@centos7 yum.repos.d]#yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel                                                                       | 4.7 kB  00:00:00     
(1/3): epel/group_gz                                                       |  88 kB  00:00:00     
(2/3): epel/updateinfo                                                     | 1.0 MB  00:00:00     
(3/3): epel/primary_db                                                     | 6.6 MB  00:00:00     
repo id                                        repo name                                    status
base/7/x86_64                                  aliyun base                                  10,019
epel                                           aliyun epel                                  12,985
repolist: 23,004

[root@centos7 yum.repos.d]#cat base.repo  cdrom.repo  epel.repo 
[base]
name=aliyun base
baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/
#gpgcheck=
gpgkey=https://mirrors.aliyun.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7 
enabled=0   
[cdrom]
name=cdrom
baseurl=file:///misc/cd
gpgcheck=1
gpgkey=file:///misc/cd
#enabled=0  jinyong
[epel]
name=aliyun epel
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
gpgcheck=0   
enabled=0 

yum install sl
火车

如何禁用仓库
yum repolist
enabled=0 禁用yum仓库 启用则是1

yum server 上课期间最好不用网路路径,利用光盘做yum源 找个光盘文件夹

ls /misc/cd
yum autofs
第一个开机启动
第二个立即启动
cdrombace
本地路径是file:///misc/cd

yum 缓存会影响安装

yum clean all 清空缓存

yum reinstall tree -y 重装
yum remove tree -y 卸载

rpm -q tree qq 查询脚本

重点 gz xz bz2 tar
sed 批量改文件
rpm -ql -qi -qf yum client 配置

转载于:https://blog.51cto.com/14230597/2388157

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值