1. CD mount
1) You need to perform the following steps first:
yum -y install autofs[root@centos7 ~]# rpm -q autofs
autofs-5.0.7-116.el7_9.x86_64
2) Then perform the following steps:
[root@centos7 ~]# systemctl enable --now autofs
Created symlink from /etc/systemd/system/multi-user.target.wants/autofs.service to /usr/lib/systemd/system/autofs.service.
3) Step 3: go to the cd of misc and check it with df:
[root@centos7 ~]# ls /misc [root@centos7 ~]# cd /misc/cd [root@centos7 cd]# pwd /misc/cd [root@centos7 cd]# 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@centos7 cd]# df Filesystem 1K-blocks Used Available Use% Mounted on devtmpfs 915780 0 915780 0% /dev tmpfs 931512 0 931512 0% /dev/shm tmpfs 931512 10688 920824 2% /run tmpfs 931512 0 931512 0% /sys/fs/cgroup /dev/sda2 52403200 5030532 47372668 10% / /dev/sda3 31441920 395068 31046852 2% /data /dev/sda1 1038336 184100 854236 18% /boot tmpfs 186304 36 186268 1% /run/user/0 /dev/sr0 9961428 9961428 0 100% /misc/cd
You can see that sro is associated with / misc/cd.
4) To see which file is the largest in this directory, use this command:
[root@centos7 cd]# du -sh * 512 CentOS_BuildTag 8.4M EFI 512 EULA 18K GPL 68M images 60M isolinux 498M LiveOS 9.0G Packages 29M repodata 2.0K RPM-GPG-KEY-CentOS-7 2.0K RPM-GPG-KEY-CentOS-Testing-7 3.0K TRANS.TBL
5) Then we enter the Packages directory in the baseOs directory (centOS8), and centOS7 directly enters Packages:
[root@centos7 cd]# cd Packages
[root@centos7 Packages]#
You will find that this is where the rpm package is placed
2. How do I check whether my system is 64 bit or 32-bit
[root@centos7 Packages]# arch
x86_64
3. I want to count x86_64 and i686:
The first method:
[root@centos7 Packages]# ls *.rpm | rev | cut -d. -f2 | rev | sort | uniq -c 2268 i686 3154 noarch 4650 x86_64
The second method:
[root@centos7 Packages]# ls *.rpm | sed -rn 's/.*\.([^.]+)\.rpm$/\1/p' | sort |uniq -c 2268 i686 3154 noarch 4650 x86_64
4.rpm2cpio, this command is to convert the rpm file into CPIO stream, and then you can see the contents of the file.
[root@centos7 Packages]# rpm2cpio xfsprogs-4.5.0-22.el7.i686.rpm | cpio -tv lrwxrwxrwx 1 root root 18 Oct 1 2020 ./usr/lib/libhandle.so.1 -> libhandle.so.1.0.3 -rwxr-xr-x 1 root root 14916 Oct 1 2020 ./usr/lib/libhandle.so.1.0.3 -rwxr-xr-x 1 root root 433 Oct 1 2020 ./usr/sbin/fsck.xfs -rwxr-xr-x 1 root root 408216 Oct 1 2020 ./usr/sbin/mkfs.xfs -rwxr-xr-x 1 root root 1380 Oct 1 2020 ./usr/sbin/xfs_admin -rwxr-xr-x 1 root root 638 Oct 1 2020 ./usr/sbin/xfs_bmap -rwxr-xr-x 1 root root 383548 Oct 1 2020 ./usr/sbin/xfs_copy -rwxr-xr-x 1 root root 621644 Oct 1 2020 ./usr/sbin/xfs_db -rwxr-xr-x 1 root root 10724 Oct 1 2020 ./usr/sbin/xfs_estimate -rwxr-xr-x 1 root root 767 Oct 1 2020 ./usr/sbin/xfs_freeze -rwxr-xr-x 1 root root 31664 Oct 1 2020 ./usr/sbin/xfs_fsr -rwxr-xr-x 1 root root 367044 Oct 1 2020 ./usr/sbin/xfs_growfs -rwxr-xr-x 1 root root 472 Oct 1 2020 ./usr/sbin/xfs_info -rwxr-xr-x 1 root root 132484 Oct 1 2020 ./usr/sbin/xfs_io -rwxr-xr-x 1 root root 400304 Oct 1 2020 ./usr/sbin/xfs_logprint -rwxr-xr-x 1 root root 350260 Oct 1 2020 ./usr/sbin/xfs_mdrestore -rwxr-xr-x 1 root root 747 Oct 1 2020 ./usr/sbin/xfs_metadump -rwxr-xr-x 1 root root 1007 Oct 1 2020 ./usr/sbin/xfs_mkfile -rwxr-xr-x 1 root root 650 Oct 1 2020 ./usr/sbin/xfs_ncheck -rwxr-xr-x 1 root root 90136 Oct 1 2020 ./usr/sbin/xfs_quota -rwxr-xr-x 1 root root 641100 Oct 1 2020 ./usr/sbin/xfs_repair -rwxr-xr-x 1 root root 14876 Oct 1 2020 ./usr/sbin/xfs_rtcp drwxr-xr-x 2 root root 0 Oct 1 2020 ./usr/share/doc/xfsprogs-4.5.0 -rw-r--r-- 1 root root 76633 Mar 15 2016 ./usr/share/doc/xfsprogs-4.5.0/CHANGES -rw-r--r-- 1 root root 63071 Dec 31 2009 ./usr/share/doc/xfsprogs-4.5.0/COPYING -rw-r--r-- 1 root root 2032 Dec 31 2009 ./usr/share/doc/xfsprogs-4.5.0/CREDITS -rw-r--r-- 1 root root 362 Oct 1 2020 ./usr/share/doc/xfsprogs-4.5.0/README -rw-r--r-- 1 root root 333016 Oct 1 2020 ./usr/share/locale/de/LC_MESSAGES/xfsprogs.mo -rw-r--r-- 1 root root 343651 Oct 1 2020 ./usr/share/locale/pl/LC_MESSAGES/xfsprogs.mo -rw-r--r-- 1 root root 371 Oct 1 2020 ./usr/share/man/man5/projects.5.gz -rw-r--r-- 1 root root 376 Oct 1 2020 ./usr/share/man/man5/projid.5.gz -rw-r--r-- 1 root root 4766 Oct 1 2020 ./usr/share/man/man5/xfs.5.gz -rw-r--r-- 1 root root 371 Oct 1 2020 ./usr/share/man/man8/fsck.xfs.8.gz -rw-r--r-- 1 root root 8011 Oct 1 2020 ./usr/share/man/man8/mkfs.xfs.8.gz -rw-r--r-- 1 root root 1429 Oct 1 2020 ./usr/share/man/man8/xfs_admin.8.gz -rw-r--r-- 1 root root 1066 Oct 1 2020 ./usr/share/man/man8/xfs_bmap.8.gz -rw-r--r-- 1 root root 1807 Oct 1 2020 ./usr/share/man/man8/xfs_copy.8.gz -rw-r--r-- 1 root root 13121 Oct 1 2020 ./usr/share/man/man8/xfs_db.8.gz -rw-r--r-- 1 root root 839 Oct 1 2020 ./usr/share/man/man8/xfs_estimate.8.gz -rw-r--r-- 1 root root 1005 Oct 1 2020 ./usr/share/man/man8/xfs_freeze.8.gz -rw-r--r-- 1 root root 2230 Oct 1 2020 ./usr/share/man/man8/xfs_fsr.8.gz -rw-r--r-- 1 root root 1996 Oct 1 2020 ./usr/share/man/man8/xfs_growfs.8.gz lrwxrwxrwx 1 root root 15 Oct 1 2020 ./usr/share/man/man8/xfs_info.8.gz -> xfs_growfs.8.gz -rw-r--r-- 1 root root 6741 Oct 1 2020 ./usr/share/man/man8/xfs_io.8.gz -rw-r--r-- 1 root root 1251 Oct 1 2020 ./usr/share/man/man8/xfs_logprint.8.gz -rw-r--r-- 1 root root 606 Oct 1 2020 ./usr/share/man/man8/xfs_mdrestore.8.gz -rw-r--r-- 1 root root 1842 Oct 1 2020 ./usr/share/man/man8/xfs_metadump.8.gz -rw-r--r-- 1 root root 462 Oct 1 2020 ./usr/share/man/man8/xfs_mkfile.8.gz -rw-r--r-- 1 root root 872 Oct 1 2020 ./usr/share/man/man8/xfs_ncheck.8.gz -rw-r--r-- 1 root root 6862 Oct 1 2020 ./usr/share/man/man8/xfs_quota.8.gz -rw-r--r-- 1 root root 5425 Oct 1 2020 ./usr/share/man/man8/xfs_repair.8.gz -rw-r--r-- 1 root root 635 Oct 1 2020 ./usr/share/man/man8/xfs_rtcp.8.gz 8519 blocks
5. Next, how do we use this package? We need to use a tool called package manager. Red hat uses the rpm command
6.rpm itself is also a binary program
[root@centos7 Packages]# type rpm rpm is hashed (/usr/bin/rpm) [root@centos7 Packages]# file /usr/bin/rpm /usr/bin/rpm: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=96ecb31da995195563a0ed95d906fb3c0415e866, strippe
7. Package management related documents
1) Package file composition (unique to each package)
Files in package
Metadata, such as package name, version, dependency, description, etc
There may be scripts that run when the package is installed or uninstalled
2) Database (public): / var/lib/rpm
Package name and version
Dependency
Function description
File path and check code information generated after package installation
8. How do we know if this package has scripts?
[root@centos7 Packages]# rpm -qp --scripts httpd-2.4.6-95.el7.centos.x86_64.rpm preinstall scriptlet (using /bin/sh): # Add the "apache" group and user /usr/sbin/groupadd -g 48 -r apache 2> /dev/null || : /usr/sbin/useradd -c "Apache" -u 48 -g apache \ -s /sbin/nologin -r -d /usr/share/httpd apache 2> /dev/null || : postinstall scriptlet (using /bin/sh): if [ $1 -eq 1 ] ; then # Initial installation systemctl preset httpd.service htcacheclean.service >/dev/null 2>&1 || : fi preuninstall scriptlet (using /bin/sh): if [ $1 -eq 0 ] ; then # Package removal, not upgrade systemctl --no-reload disable httpd.service htcacheclean.service > /dev/null 2>&1 || : systemctl stop httpd.service htcacheclean.service > /dev/null 2>&1 || : fi postuninstall scriptlet (using /bin/sh): systemctl daemon-reload >/dev/null 2>&1 || : # Trigger for conversion from SysV, per guidelines at: # https://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Systemd posttrans scriptlet (using /bin/sh): test -f /etc/sysconfig/httpd-disable-posttrans || \ /bin/systemctl try-restart httpd.service htcacheclean.service >/dev/null 2>&1 || :
9. In addition, after we install the management package, it has a public data. As long as we install the software package, it will put the public information in the database, called / var/lib/rpm
[root@centos7 Packages]# ls /var/lib/rpm Basenames __db.001 __db.003 Group Name Packages Requirename Sigmd5 Conflictname __db.002 Dirnames Installtid Obsoletename Providename Sha1header Triggername
This file is very important. As long as we install the software package, he will put each installed package and the list of files contained in the package in this folder and record it
In the future, we can use this database to know the packages installed in the system, including those files, including attributes
10. If you want to know whether a software is installed or not, you can use this command to check:
[root@centos7 Packages]# rpm -q vsftpd package vsftpd is not installed [root@centos7 Packages]# echo $? 1
It can be used in conjunction with the script. If the returned result is non-zero, it indicates that it is not installed
11. Install any rpm package:
[root@centos7 Packages]# rpm -ivh vsftpd-3.0.2-28.el7.x86_64.rpm Preparing... ################################# [100%] Updating / installing... 1:vsftpd-3.0.2-28.el7 ################################# [100%]
In fact, I don't need to write vh to make the installation process more intuitive, but it's recommended to write it in order to see it
Reconfirm whether it is installed:
[root@centos7 Packages]# rpm -p vsftpd RPM version 4.11.3 Copyright (C) 1998-2002 - Red Hat, Inc. This program may be freely redistributed under the terms of the GNU GPL Usage: rpm [-aKfgpqVcdLilsiv?] [-a|--all] [-f|--file] [-g|--group] [-p|--package] [--pkgid] [--hdrid] [--triggeredby] [--whatrequires] [--whatprovides] [--nomanifest] [-c|--configfiles] [-d|--docfiles] [-L|--licensefiles] [--dump] [-l|--list] [--queryformat=QUERYFORMAT] [-s|--state] [--nofiledigest] [--nofiles] [--nodeps] [--noscript] [--allfiles] [--allmatches] [--badreloc] [-e|--erase <package>+] [--excludedocs] [--excludepath=<path>] [--force] [-F|--freshen <packagefile>+] [-h|--hash] [--ignorearch] [--ignoreos] [--ignoresize] [-i|--install] [--justdb] [--nodeps] [--nofiledigest] [--nocontexts] [--noorder] [--noscripts] [--notriggers] [--nocollections] [--oldpackage] [--percent] [--prefix=<dir>] [--relocate=<old>=<new>] [--replacefiles] [--replacepkgs] [--test] [-U|--upgrade <packagefile>+] [--reinstall=<packagefile>+] [-D|--define 'MACRO EXPR'] [--undefine=MACRO] [-E|--eval 'EXPR'] [--macros=<FILE:...>] [--noplugins] [--nodigest] [--nosignature] [--rcfile=<FILE:...>] [-r|--root ROOT] [--dbpath=DIRECTORY] [--querytags] [--showrc] [--quiet] [-v|--verbose] [--version] [-?|--help] [--usage] [--scripts] [--setperms] [--setugids] [--setcaps] [--restore] [--conflicts] [--obsoletes] [--provides] [--requires] [--info] [--changelog] [--xml] [--triggers] [--last] [--dupes] [--filesbypkg] [--fileclass] [--filecolor] [--fscontext] [--fileprovide] [--filerequire] [--filecaps]
12. Of course, you need to go back to uninstall if you can install:
[root@centos7 Packages]# rpm -e vsftpd [root@centos7 Packages]# rpm -q vsftpd package vsftpd is not installed
Note that when uninstalling, just write the name of the software. There is no need to write the file name. When we install, we need to write the file name and path!
13. I'd like to know where all the files in the package go. Here's a way:
[root@centos7 Packages]# 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
ql can query a loaded package, the files it contains and the directory under which it is located.
14. In addition, we can check the package information with qi:
[root@centos7 Packages]# 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@centos7 Packages]# rpm -qi tree Name : tree Version : 1.6.0 Release : 10.el7 Architecture: x86_64 Install Date: Fri 07 Jan 2022 01:47:08 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.
15.-qf: in contrast to ql, it looks at the files on the disk from that package
[root@centos7 Packages]# rpm -qf /etc/issue centos-release-7-9.2009.0.el7.centos.x86_64
16. We can also check:
1) - qc view only the configuration file of the package
[root@centos7 Packages]# rpm -qc vsftpd /etc/logrotate.d/vsftpd /etc/pam.d/vsftpd /etc/vsftpd/ftpusers /etc/vsftpd/user_list /etc/vsftpd/vsftpd.conf
2) - qd: just look at the document
[root@centos7 Packages]# rpm -qd vsftpd /usr/share/doc/vsftpd-3.0.2/AUDIT /usr/share/doc/vsftpd-3.0.2/BENCHMARKS /usr/share/doc/vsftpd-3.0.2/BUGS /usr/share/doc/vsftpd-3.0.2/COPYING /usr/share/doc/vsftpd-3.0.2/Changelog /usr/share/doc/vsftpd-3.0.2/EXAMPLE/INTERNET_SITE/README /usr/share/doc/vsftpd-3.0.2/EXAMPLE/INTERNET_SITE/README.configuration /usr/share/doc/vsftpd-3.0.2/EXAMPLE/INTERNET_SITE/vsftpd.conf /usr/share/doc/vsftpd-3.0.2/EXAMPLE/INTERNET_SITE/vsftpd.xinetd /usr/share/doc/vsftpd-3.0.2/EXAMPLE/INTERNET_SITE_NOINETD/README /usr/share/doc/vsftpd-3.0.2/EXAMPLE/INTERNET_SITE_NOINETD/README.configuration /usr/share/doc/vsftpd-3.0.2/EXAMPLE/INTERNET_SITE_NOINETD/vsftpd.conf /usr/share/doc/vsftpd-3.0.2/EXAMPLE/PER_IP_CONFIG/README /usr/share/doc/vsftpd-3.0.2/EXAMPLE/PER_IP_CONFIG/README.configuration /usr/share/doc/vsftpd-3.0.2/EXAMPLE/PER_IP_CONFIG/hosts.allow /usr/share/doc/vsftpd-3.0.2/EXAMPLE/README /usr/share/doc/vsftpd-3.0.2/EXAMPLE/VIRTUAL_HOSTS/README /usr/share/doc/vsftpd-3.0.2/EXAMPLE/VIRTUAL_USERS/README /usr/share/doc/vsftpd-3.0.2/EXAMPLE/VIRTUAL_USERS/README.configuration /usr/share/doc/vsftpd-3.0.2/EXAMPLE/VIRTUAL_USERS/logins.txt /usr/share/doc/vsftpd-3.0.2/EXAMPLE/VIRTUAL_USERS/vsftpd.conf /usr/share/doc/vsftpd-3.0.2/EXAMPLE/VIRTUAL_USERS/vsftpd.pam /usr/share/doc/vsftpd-3.0.2/EXAMPLE/VIRTUAL_USERS_2/README /usr/share/doc/vsftpd-3.0.2/FAQ /usr/share/doc/vsftpd-3.0.2/INSTALL /usr/share/doc/vsftpd-3.0.2/LICENSE /usr/share/doc/vsftpd-3.0.2/README /usr/share/doc/vsftpd-3.0.2/README.security /usr/share/doc/vsftpd-3.0.2/REWARD /usr/share/doc/vsftpd-3.0.2/SECURITY/DESIGN /usr/share/doc/vsftpd-3.0.2/SECURITY/IMPLEMENTATION /usr/share/doc/vsftpd-3.0.2/SECURITY/OVERVIEW /usr/share/doc/vsftpd-3.0.2/SECURITY/TRUST /usr/share/doc/vsftpd-3.0.2/SIZE /usr/share/doc/vsftpd-3.0.2/SPEED /usr/share/doc/vsftpd-3.0.2/TODO /usr/share/doc/vsftpd-3.0.2/TUNING /usr/share/doc/vsftpd-3.0.2/vsftpd.xinetd /usr/share/man/man5/vsftpd.conf.5.gz /usr/share/man/man8/vsftpd.8.gz
17. Overall, rpm: -i: install, - e: uninstall, - q: query
There are so many mainstream applications of rpm. In fact, we don't need to install and uninstall because there is a dependency problem between installation and uninstall