Some Linux commands to view system information and commands to view installed packages

# uname -a # View kernel/OS/CPU information
# head -n 1 /etc/issue # View OS version
# cat /proc/cpuinfo # View CPU information
# hostname # View computer name
# lspci -tv # List All PCI devices
# lsusb -tv # List all USB devices
# lsmod # List loaded kernel modules
# env # View environment variables
Resources
# free -m # View memory usage and swap usage
# df -h # View each Partition usage
# du -sh <directory name> # View the size of the specified directory
# grep MemTotal /proc/meminfo # View the total amount of memory
# grep MemFree /proc/meminfo # View the amount of free memory
# uptime # View system running time, users Number, load
# cat /proc/loadavg # View system load
Disks and partitions
# mount | column -t # View the mounted partition status
# fdisk -l # View all partitions
# swapon -s # View all swap partitions
# hdparm -i /dev/hda # View disk parameters (only for IDE devices)
# dmesg | grep IDE # View IDE device detection status at startup
Network
# ifconfig # View properties of all network interfaces
# iptables -L # View firewall settings
# route -n # View routing table
# netstat -lntp # View all listening ports
# netstat - antp # View all established connections
# netstat -s # View network statistics
Process
# ps -ef # View all processes
# top # Display process status in real time
User
# w # View active users
# id <username> # View specified user Information
# last # View user login log
# cut -d: -f1 /etc/passwd # View all users in the system
# cut -d: -f1 /etc/group # View all groups in the system
# crontab -l # View the current user's scheduled tasks
services
# chkconfig --list # List all system services
# chkconfig --list | grep on # List all started system services
Programs
# rpm -qa # View all installed packages


RPM
    In the Linux operating system, there is a system package, which functions like In Windows "Add/Remove Programs", but the function is much stronger than "Add/Remove Programs", it is Red Hat Package Manager (referred to as RPM). This toolkit was first introduced by Red Hat and was later borrowed by other Linux developers. Because it saves a lot of time for Linux users, it is widely used to install and delete software under Linux. The following will introduce to you how to use it.
1. We get a new software. Before installation, we generally need to check what is in the package. Suppose this file is: Linux-1.4-6.i368.rpm, we can use this command to check:
rpm -qpi Linux-1.4-6.i368.rpm
system will list the detailed information of this package, including how many files it contains, file name, file size, creation time, compilation date and other information.
2. All the files listed above are not necessarily all installed during installation. Just like the installation methods of programs under Windows are divided into typical, complete, and custom, Linux will also let you choose the installation method. At this time, we can use the following Command to check which parts of the package will be installed in the system, so as to facilitate our selection:
rpm -qpl Linux-1.4-6.i368.rpm
3. After selecting the installation method, start the installation. We can install this software with the rpm-ivh Linux-1.4-6.i368.rpm command. During the installation process, if the system prompts that the software has been installed or cannot continue the installation for other reasons, but if we really want to execute the installation command, we can add a parameter "-replacepkgs" after -ivh:
rpm -ivh -replacepkgs Linux- 1.4-6.i368.rpm
4. Sometimes we uninstall an installed software, just execute the rpm-e <file name>; command.
5. Upgrading low-level software is a good way to improve its functions, which saves us the trouble of uninstalling and then installing new software. To upgrade a software, just execute the following command: rpm -uvh <file name>; , Note: The file name at this time must be the upgrade patch of the software to be upgraded 
6. Another method of installing software can be described as a unique feature of Linux, and it is also a manifestation of the powerful function of RMP: install software directly online through FTP site. When you find a site containing the software you need and connect to this site, execute the following command to implement online installation, such as online installation of Linux-1.4-6.i368.rpm, you can use the command:
rpm -i ftp:// ftp.pht.com/pub/linux/redhat/…-1.4-6.i368.rpm
7. In the process of using the computer, it is inevitable that there will be misoperations. If we delete several files by mistake and affect the performance of the system, how to find out which files are missing? The RPM package provides a tool to find damaged files. function, execute this command: rpm -Va, Linux will list all damaged files for you. You can fix it from the Linux installation CD.
8. There are many files in the Linux system. During use, it is inevitable to encounter files that we do not know. In Windows, we can use the "Start/Find" menu to quickly determine which folder a file belongs to. In Linux, the following This command line can help us quickly determine which package a file belongs to:
rpm -qf <file name>;
9. When each package is installed in the Linux system, the installation file will be "registered" in the RPM database, so , when we want to query the properties of an installed software, we only need to look it up in this database. Note: The query command at this time is different from the query introduced in 1 and 8. This method only works for installed packages! Command format:
rpm -parameter <file name>;

APT-GET
apt-get update - run this command after modifying /etc/apt/sources.list or /etc/apt/preferences. Also you need to run this command periodically to make sure your package list is up to date.
apt-get install packagename - installs a new package (see aptitude below)
apt-get remove packagename - uninstalls an installed package (keeps configuration files)
apt-get --purge remove packagename - uninstalls an existing package Installed packages (remove config files)
dpkg --force-all --purge packagename Some software is difficult to uninstall, and it also blocks the application of other software, you can use this, but it is a bit risky.
apt-get autoclean apt will back up the installed or uninstalled software on the hard disk, so if you need space, you can use this command to delete the software you have deleted
apt-get clean This command will restore the installed software The backup is also deleted, but this will not affect the use of the software.
apt-get upgrade -- update all installed packages
apt-get dist-upgrade -- upgrade the system to a new version
apt-cache search string -- search the package list for the string
dpkg -l package-name-pattern - List all packages matching the pattern. If you don't know the full name of the package, you can use "*package-name-pattern*".
aptitude - View installed or available packages in detail. Similar to apt-get, aptitude can be invoked from the command line, but only with certain commands - the most common are install and uninstall commands. Since aptitude knows more than apt-get, it's arguably better for installing and uninstalling.
apt-cache showpkg pkgs - Show package information.
apt-cache dumpavail - prints a list of available packages.
apt-cache show pkgs - Show package records, similar to dpkg --print-avail.
apt-cache pkgnames - prints the names of all packages in the package list.
dpkg -S file - which installed package this file belongs to.
dpkg -L package - List all files in a package.
apt-file search filename - Finds packages (not necessarily installed) containing specific files with the specified string in the filename. apt-file is a standalone package. You must first install it with apt-get install, then run apt-file update. If apt-file search filename outputs too much, you can try apt-file search filename | grep -w filename (to display only those filenames where the specified string appears as a complete word) or similar, for example: apt-file search filename | grep /bin/ (only shows files located in folders such as /bin or /usr/bin, this is helpful if you are looking for a specific executable) .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326315072&siteId=291194637