One, sed (Stream EDitor) 1. Introduction to SED
- definition : The stream editor, which handles rows, also known as the row editor. Two spaces are exposed to the process, one is pattern space and the other is space-preserving
- pattern Space : When the text is processed with SED, the row being processed is stored in a temporary buffer, which is the pattern space
- Keep space : for processed rows There are other processing, the processed rows are temporarily stored in another temporary buffer, that is, to maintain space
- function : Mainly used to automatically edit one or more files, simplify the repeated operation of the file, write the conversion program, such as 2.sed usage
Common options
-n 不输出模式空间内容到屏幕 -e 多项编辑 -f filename 从指定文件中读取编辑脚本 -r 支持使用扩展正则表达式 -i.bak 修改内容并且备份
Address command
地址定界:1.不给地址:对全文进行处理 2. 单地址 #:第#行 /pattern/:能匹配到/pattern/的行 3. 地址范围 #,*:第#行到第*行 #,+#:第#行开始,向后数#行 /pat1/,/pat2/:能匹配到1模式的行到能匹配到2模式的行 #,/pat1/:第#行到能匹配到1模式的行 4. 步进 1~2p 奇数行 2~2p 偶数行
Edit command
d 删除模式空间匹配的行 p 输出当前模式空间内容,追加到默认输出之后 a text 在指定行后面追加文本 (可以使用\n进行多行追加) i text 在指定行前面插入文本 c text 替换指定行 w filename 保存模式匹配的行至filename r filename 读取filename的文本至模式空间中匹配到的行后 = 为模式空间中的行打印行号 ! 模式空间中匹配行取反处理
Find replacements
s///:查找替换,支持使用其它分隔符, [email protected]@@, s### 替换标记 g 行内全局替换 p 显示替换成功的行 w filename 将替换成功的行保存至文件中
3. Advanced usage P 打印模式空间开端至\n内容,并追加到默认输出之前 h 把模式空间中的内容覆盖至保持空间中 H 把模式空间中的内容追加至保持空间中 g 从保持空间取出数据覆盖至模式空间 G 从保持空间取出内容追加至模式空间 x 把模式空间中的内容与保持空间中的内容进行互换 n 读取匹配到的行的下一行覆盖至模式空间 N 读取匹配到的行的下一行追加至模式空间 d 删除模式空间中的行 D 如果模式空间包含换行符,则删除第一个换行符的行的内容, 并不会读取新的输入行
Second, package Management 1. Package Manager
- Part of a binary application
binary files, library files, configuration files, Help files
- Package Manager:
Debian: Deb file, dpkg Package Manager
redhat: RPM file, RPM Package Manager
rpm: Redhat Package Manager
RPM package Manager2. Packages naming
- RPM Package Naming method:
name-version-release.arch.rpm
Version (release number): Major.minor.release
Release (minor version number): Release. OS
Common arch:
x86:i386, i486, i586, i686
x86_64: x64, x86_64, AMD64
PowerPC: PPC
platform agnostic: Noarch
It's usually noarch,x86_64,i386 . 3. Package ToolsBetween packages: There may be dependencies, or even cyclic dependencies
- To resolve the dependency package management tool:
YUM:RPM Package Manager Front-end tools
Apt-get:deb Package Manager Front End Tool
RPM front-end management tools on Zypper:suse
Dnf:fedora + RPM Package Manager front-end management tools 4. library files
- Manage and view native-mounted library files
Ldconfig Loading library files
/sbin/ldconfig-p: Displays all available library file names and file path mappings that have been cached by this computer
Configuration files:/etc/ld.so.conf,/etc/ld.so.conf.d/*.conf
Cache files:/ETC/LD.SO.CACHE5.RPM package Management
Installation
rpm -i -i 以下的选项 [install-options] -v 显示详细的安装信息 -vv 非常详细的显示安装信息 -h 显示安装进度条 rpm -ivh - - test 测试安装,但不真正执行安装,即dry run模式 - - nodeps 忽略依赖关系 - - replacepkgs 新安装的包部分文件跟旧安装包有冲突,替换就安装包的文件 - - replacefiles 新安装的包部分文件跟旧安装包有冲突,不替换就安装包的文件 - - nosignature 不检查来源合法性 - - nodigest 不检查包完整性 - - noscripts 不执行程序包脚本 - - nopre 安装前的脚本(安装软件之前需要运行的脚本) - - nopost 安装后的脚本(运行软件需要的脚本) - - nopreun 卸载前的脚本(与安装的同理) - - nopostun 卸载后的脚本
Upgrade
rpm -U [install-options] 安装有旧版程序包,则“升级”,如果不存在旧版程序包,则“安装” rpm -F [install-options] 安装有旧版程序包,则“升级”,如果不存在旧版程序包,则不执行升级操作 - - oldpackage 降级,指定的安装包比已经安装的旧 - - force 强制安装
Attention:
(1) Do not upgrade the kernel, Linux support multi-core version coexist, directly install the new version of the kernel can be
(2) If the original package configuration file has been modified after installation, upgrade, the new version provided by the same profile does not directly overwrite the old version of the configuration file, and the new version of the file renamed (filename.rpmnew) retained
Inquire
Rpm-q with-Q with [select-options]-a all package-f view specified The file is installed by which package to build-P rpmfile for the package files that have not been installed to do the query operation--Whatprovides CAPABILITY The specified CAPABILITY is provided by which package-whatrequires CAPABILITY: Queries the specified CAPABILITY by which package is dependent on the CAP Ability: Capacity name, software provided capabilities [Query-options]--changelog query RPM package Chang Elog log Records-C query program configuration file-d Query program documentation -I query program Information-l View all files that are generated after the specified package is installed --Scripts package comes with a script--provides lists the capability provided by the specified package -R queries the specified package depends on the capability Rpm2cpio package file |CPIO–ITV Preview package file Rpm2cpio package file |cpio– ID "*.conf" releases the in-package file
Unloading
Check
rpm -V [select-options] [verify-options] [verify-options] S file Size differs 文件大小比较 M Mode differs (includes permissions and file type) 模式比较,包括权限和文件类型 5 digest (formerly MD5 sum) differs md5值比较
md5是单向加密。相当于文件的特征码,只要文件有一丝改变,md5码就会发生变化
D Device major/minor number mismatch to match the primary and secondary version numbers L Readlink (2) path mismatch U User ownership differs owner comparison Compare T MTime differs modification time of G group ownership differs-affiliated group P capabilities differ
- Public key, private key encryption
symmetric encryption : encryption, decryption using the same key, speed performance is fast, unsafe, can not exist for a long time
Asymmetric encryption : Keys are paired, safe, slow performance, need to be calculated
Publickey: Open owner
private key (secret key) : cannot be exposed
Import the required public key
rpm -K checksig rpmfile 检查包的完整性和签名 rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
CentOS 7 Release CD offers: Rpm-gpg-key-centos-7
rpm -qa “gpg-pubkey*”
Database
Database rebuild
rpm - - initdb - - rebuilddb
Initdb: Initialization
New if no database exists beforehand, otherwise, no action is taken
rebuilddb: Rebuilding the database index directory for an installed header
Linux Learning (v)-SED, package management