比较:
diff vimdiff
[root@oldboyedu ~]# cp /etc/passwd{,.ori}
备份好处:
1、恢复。
2、比较、检查。
[root@oldboyedu ~]# diff /etc/passwd{,.ori}
32c32
< #oldgirl1:x:8889:8889::/home/oldgirl1:/bin/bash
---
> oldgirl1:x:8889:8889::/home/oldgirl1:/bin/bash
[root@oldboyedu ~]# diff /etc/passwd /etc/passwd.ori
32c32
< #oldgirl1:x:8889:8889::/home/oldgirl1:/bin/bash
---
> oldgirl1:x:8889:8889::/home/oldgirl1:/bin/bash
rpm命令全称是Red Hat Package Manager(Red Hat包管理器),几乎所有的Linux发行版本都使用这种形式的命令管理、安装、更新和卸载软件。
概括地说,rpm命令有五种基本功能(不包括创建rpm包):安装、卸载、升级、查询和验证。
[root@oldboyedu ~]# mount /dev/cdrom /mnt
mount: no medium found on /dev/sr0
[root@oldboyedu ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@oldboyedu ~]# cd /mnt/
[root@oldboyedu /mnt]# ls
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
[root@oldboyedu /mnt]# cd Packages/
需要很多依赖。
[root@oldboyedu /mnt/Packages]# rpm -ivh dos2unix-6.0.3-7.el7.x86_64.rpm
Preparing... ################################# [100%]
package dos2unix-6.0.3-7.el7.x86_64 is already installed
[root@oldboyedu /mnt/Packages]# rpm -qa|grep tree
tree-1.6.0-10.el7.x86_64
[root@oldboyedu /mnt/Packages]# rpm -qa tree
tree-1.6.0-10.el7.x86_64
[root@oldboyedu ~]# 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
[root@oldboyedu ~]# rpm -qf /sbin/ifconfig
net-tools-2.0-0.24.20131004git.el7.x86_64
yum命令:帮我们在rpm安装时解决软件包依赖,
背后还是使用rpm,不需要直接使用rpm了
让安装软件更智能了。底层还是rpm在工作。
yum主要用于自动安装、升级rpm软件包,它能自动
查找并解决rpm包之间的依赖关系。
[root@oldboyedu ~]# yum grouplist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base | 3.6 kB 00:00:00
Available Environment Groups:
Minimal Install
Compute Node
Infrastructure Server
File and Print Server
[root@oldboyedu ~]# yum groupinstall "File and Print Server"
[root@oldboyedu ~]# yum list tree
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
tree.x86_64 1.6.0-10.el7 @base
[root@oldboyedu ~]# yum install tree -y
根据命令或者配置等的路径查属于哪个包
[root@oldboyedu ~]# yum provides /etc/my.cnf
[root@oldboyedu ~]# yum provides /sbin/ifconfig
Linux系统如何安装软件?
1、rpm安装
简单 快。依赖多,解决依赖困难繁琐。
2、yum安装 *****
简单快,自动解决依赖。不能选择软件版本或软件存放路径。
3、编译安装(源码编译)*****
慢 复杂 需要GCC编译器,可以自定义安装(版本、软件路径)
4、将源码制作成rpm,然后放到yum仓库,实现yum自动安装。
一次性慢 复杂,安装快,可以自定义安装(版本、软件路径)
制作RPM YUM仓库搭建
https://blog.oldboyedu.com/autodeploy-rpm/
chattr命令:
[root@oldboyedu ~]# chattr +i /etc/passwd #<==锁定文件不能删除,不能修改
[root@oldboyedu ~]# lsattr /etc/passwd
----i----------- /etc/passwd
[root@oldboyedu ~]# lsattr /etc/hosts
---------------- /etc/hosts
[root@oldboyedu ~]# cp /etc/passwd{,.ori}
[root@oldboyedu ~]# rm -f /etc/passwd
rm: cannot remove ‘/etc/passwd’: Operation not permitted
[root@oldboyedu ~]# echo ddd > /etc/passwd
-bash: /etc/passwd: Permission denied
[root@oldboyedu ~]# useradd littleboy
useradd: cannot open /etc/passwd
chattr -i /etc/passwd #<==解锁文件。
给重要文件上锁
[root@oldboyedu ~]# chattr +a oldboy.txt
[root@oldboyedu ~]# rm -f oldboy.txt
rm: cannot remove ‘oldboy.txt’: Operation not permitted
[root@oldboyedu ~]# echo dddd >>oldboy.txt
[root@oldboyedu ~]# echo dddd >>oldboy.txt