Summary of CentOS common commands

Time:2021-9-17

Next, let’s introduce these common CentOS commands.

1: Use CentOS common commands to view CPUs

Copy code

The code is as follows:

more /proc/cpuinfo | grep “model name”
grep “model name” /proc/cpuinfo
[[email protected] /]# grep “CPU” /proc/cpuinfo
model name : Intel(R) Pentium(R) Dual CPU E2180 @ 2.00GHz
model name : Intel(R) Pentium(R) Dual CPU E2180 @ 2.00GHz

If you feel you need to see more comfortable

grep “model name” /proc/cpuinfo | cut -f2 -d:

2: View memory using CentOS common commands

Copy code

The code is as follows:

grep MemTotal /proc/meminfo
grep MemTotal /proc/meminfo | cut -f2 -d:
free -m |grep “Mem” | awk ‘{print $2}’

3: Use CentOS common commands to check whether the CPU is 32-bit or 64 bit
View CPU bits (32 or 64)
getconf LONG_BIT

4: Use CentOS common commands to view the current version of Linux
more /etc/redhat-release
cat /etc/redhat-release

5: Use CentOS common commands to view the kernel version
uname -r
uname -a

6: Use CentOS common commands to view the current time
How to synchronize time has been described above in date

7: Use CentOS common commands to view hard disks and partitions
df -h
fdisk -l
You can also view partitions
du -sh
You can see the total occupied space
du /etc -sh
You can see the size of this directory

8: Use CentOS common commands to view installed packages
Check the software packages installed during system installation
cat -n /root/install.log
more /root/install.log | wc -l
Check which packages are now installed
rpm -qa
rpm -qa | wc -l
yum list installed | wc -l
However, it is strange that the number of installed packages I query through rpm and Yum is different. No reason was found.

9: Use CentOS common commands to view the keyboard layout
cat /etc/sysconfig/keyboard
cat /etc/sysconfig/keyboard | grep KEYTABLE | cut -f2 -d=

10: Use CentOS common commands to view SELinux
sestatus
sestatus | cut -f2 -d:
cat /etc/sysconfig/selinux

11: Use CentOS common commands to view IP and MAC addresses

Copy code

The code is as follows:

In the ifcfg-eth0 file, you can see Mac, gateway and other information.
ifconfig
cat /etc/sysconfig/network-scripts/ifcfg-eth0 | grep IPADDR
cat /etc/sysconfig/network-scripts/ifcfg-eth0 | grep IPADDR | cut -f2 -d=
ifconfig eth0 |grep “inet addr:” |awk ‘{print $2}’|cut -c 6-
ifconfig | grep ‘inet addr:’| grep -v ‘127.0.0.1’ | cut -d: -f2 | awk ‘{ print $1}’
View gateway
cat /etc/sysconfig/network
View DNS
cat /etc/resolv.conf

12: Use CentOS common commands to view the default language
echo $LANG $LANGUAGE
cat /etc/sysconfig/i18n

13: Use CentOS common commands to view the time zone and whether to use UTC time
cat /etc/sysconfig/clock

14: Use CentOS common commands to view host names
hostname
cat /etc/sysconfig/network
To modify the host name is to modify this file. At the same time, it is best to modify the host file.

15: Use CentOS common commands to view the startup and running time
uptime
09:44:45 up 67 days, 23:32, …
It seems that it was really a network segment problem just now. My machine was started 67 days ago.
#System resource usage

Copy code

The code is as follows:

vmstat 1 -S m
procs ———–memory———- —swap– —–io—- –system– —–cpu——
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 233 199 778 0 0 4 25 1 1 3 0 96 0 0
0 0 0 233 199 778 0 0 0 0 1029 856 13 1 86 0 0

Among the many linux terminal commands, we should introduce them by classification. First, we will talk about file directory class, driver mounting class, program installation class, compression and decompression class and process control class. All Linux terminal commands here will be often used. It should be much easier to be familiar with these commands.

1、 File directory class

1. Create directory: MKDIR directory name
2. Delete empty directory: rmdir directory name
3. Unconditionally delete subdirectories: RM – RF directory name
4. Change the current directory: CD directory name (enter the user’s home directory: Cd ~; enter the previous Directory: CD -)
5. View your directory: PWD
6. View the current directory size: Du
7. Display directory file list: LS – L (- A: add hidden directory)
Where: Blue: Directory; Green: executable file; Red: compressed file; Light blue: link file; Grey: other documents; White on red: wrong linked file
8. Browse the file: more file name. TXT; Less filename.txt
9. Copy file: CP source file destination file (- R: include directory)
10. Find file: (1) find (2) locate command name
11. Link: (1) establish hard link: ln source file link file (- D: create directory link); (2) establish symbolic link: ln – s source file link file

2、 Driver mount class

1. Check hard disk usage: DF – t – H
2. Check disk partition: fdisk – L
3. Mount the hard and soft optical area: Mount – t / dev / fdx|hdax / MNT / directory name
Where: modos — FAT16; vfat–FAT32; ntfs–NTFS; Optical drive — iso9660
Chinese name supported: Mount – O iocharset = x / dev / HDAX / MNT / directory name (where: x = cp936 or
Mount optical drive: Mount – t auto / dev / CDROM / MNT / CDROM
Mount ISO file: Mount – t iso9660 – O loop xxx.iso/path
4. Unmount: umount / MNT / directory name
Unmount all: umount – A
5. Establish file system: mkfs – t / dev / hdxx. Where: ftype: ext2, ext3, swap, etc

3、 Program installation class

1. RPM package installation: (1) install RPM – IVH somesoft.rpm
(2) Reverse install (uninstall) RPM – e somefost.rpm
(3) Query RPM – Q somefost or RPM – QPI somefost.rpm (where: P is not installed; I contains information)
(4) Query the post installation location: RPM – QL somefost.rpm
(5) Upgrade installation: RPM – uvh somesoft.rpm
(6) Forced installation: RPM – IVH — nodeps somesoft.rpm or RPM – IVH — nodeps — force somesoft.rpm
2. Source code package installation:
Refer to Readme
Basic Usage
(1) Configuration: unzip the directory. / configure
(2) Compile: unzip make in the directory
(3) Install: unzip the directory make install

3. Installation of src.rpm

4、 Compression and decompression class

Tar command: Tar [-cxtzjvfppn] file and directory
Tar command parameters:
-c: The parameter instruction to create a compressed file (create means);
-x: Unpack the parameter instruction of a compressed file!
-t: Check the files in tarfile!
Note that only one C / X / T can exist during parameter release! Cannot exist at the same time!
Because it is impossible to compress and decompress at the same time.
-z: Do you also have gzip attributes? That is, do you need gzip compression?
-j: Do you also have the property of bzip2? That is, do you need to use bzip2 compression?
-v: Display files during compression! This is commonly used, but not recommended for background execution!
-f: When using the file name, please note that you should receive the file name immediately after f! No more parameters!
For example, using “tar -zcvfp tfile sfile” is the wrong way to write it
“Tar -zcvpf tfile sfile” is right!
-p: Use the original attributes of the original file (the attributes will not change according to the user)
-P: You can use absolute path to compress!
-N: New than the following date (yyyy / mm / DD) will be packaged into the new file!
– exclude file: do not package file during compression!

example:
Example 1: package all the files in the entire / etc directory into / TMP / etc.tar
[ [email protected] ~]#Tar – CVF / TMP / etc.tar / etc < = = package only, no compression!   Tar – CVF target file   source file    (the same below) for example: tar – CVF a.txt.tar a.txt
[ [email protected] ~]#Tar – zcvf / TMP / etc.tar.gz / etc < = = packed, compressed in gzip
[ [email protected] ~]#Tar – jcvf / TMP / etc.tar.bz2 / etc < = = packed, compressed with bzip2
#In particular, the file name after parameter f is taken by ourselves. We are used to using. Tar as identification.
#If the Z parameter is added, the gzip compressed tar files are represented by. Tar.gz or. Tgz
#If the j parameter is added, take. Tar.bz2 as the attachment name
#When the above command is executed, a warning message will be displayed:
#”Tar: removing leading ` /” from member names “is a special setting for absolute paths.
 
Example 2: what files are there in the above / TMP / etc.tar.gz file?
[[email protected] ~]# tar -ztvf /tmp/etc.tar.gz
#Because we use gzip compression, when we want to view the files in the tar file,
#You have to add Z this parameter! This is very important!
 
Example 3: unzip the / TMP / etc.tar.gz file under / usr / local / SRC
[[email protected] ~]# cd /usr/local/src
[[email protected] src]# tar -zxvf /tmp/etc.tar.gz
#By default, we can unlock the compressed file anywhere! In this example,
#I first change the working directory to / usr / local / SRC, and unlock / TMP / etc.tar.gz,
#The unpacked directory will be in / usr / local / SRC / etc! In addition, if you enter / usr / local / SRC / etc
#You will find that the file attributes in this directory may be different from / etc /!
 
Example 4: under / tmp, I just want to unlock etc / passwd in / TMP / etc.tar.gz
[[email protected] ~]# cd /tmp
[[email protected] tmp]# tar -zxvf /tmp/etc.tar.gz etc/passwd
#I can check the file name in tarfile through tar – ztvf. If there is only one file,
#You can release it in this way! be aware! The root directory / in etc.tar.gz has been removed!
 
Example 5: back up all files in / etc / and save their permissions!
[[email protected] ~]# tar -zxvpf /tmp/etc.tar.gz /etc
#This – P attribute is very important, especially when you want to keep the attributes of the original file!
 
Example 6: in / home, only files newer than 2005 / 06 / 01 are backed up
[[email protected] ~]# tar -N “2005/06/01″ -zcvf home.tar.gz /home
 
Example 7: I want to back up / home, / etc, but not / home / dmtsai
[[email protected] ~]# tar –exclude /home/dmtsai -zcvf myfile.tar.gz /home/* /etc
 
Example 8: unpack / etc / directly under / tmp without generating files!
[[email protected] ~]# cd /tmp
[[email protected] tmp]# tar -cvf – /etc | tar -xvf –
#This action is a bit like CP – R / etc / tmp ~ it still has its purpose!
#The point to note is that when the output file becomes – and the input file becomes – there is another ~
#This represents standard output, standard input and pipeline commands respectively!
 
5、 Process control class

1. List the current process ID: PS -auxw
2. Terminate the process: (1) terminate a single process: kill the process ID number
(2) Terminate all processes of this program: killall program name
(3) Terminate X-window program: xkill
3. View resource usage: (1) top (2) free (3) dmesg
4. View environment variable value: env
5. Restart: (1) reboot (2) Ctrl Alt del (3) init 6
6. Shutdown: (1) shutdown – h now (2) halt (3) init 0
7. Switch desktop: switchdesk gnome|kde|

Recommended Today

Supervisor

Supervisor [note] Supervisor – H view supervisor command help Supervisorctl – H view supervisorctl command help Supervisorctl help view the action command of supervisorctl Supervisorctl help any action to view the use of this action 1. Introduction Supervisor is a process control system. Generally speaking, it can monitor your process. If the process exits abnormally, […]