Comments: Common CentOS commands that are frequently used in our work have been carefully organized.
The following describes common CentOS commands.
I. View cpu using common CentOS commands
Copy the Code as follows:
More/proc/cpuinfo | grep "model name"
Grep "model name"/proc/cpuinfo
[Root @ localhost/] # grep "CPU"/proc/cpuinfo
Model name: Intel (R) Pentium (R) Dual CPU E2180 @ 2.00 GHz
Model name: Intel (R) Pentium (R) Dual CPU E2180 @ 2.00 GHz
If you feel more comfortable to watch
Grep "model name"/proc/cpuinfo | cut-f2-d:
Ii. view memory using common CentOS commands
Copy the Code as follows:
Grep MemTotal/proc/meminfo
Grep MemTotal/proc/meminfo | cut-f2-d:
Free-m | grep "Mem" | awk '{print $2 }'
Iii. Use common CentOS commands to check whether the cpu is 32-bit or 64-bit
View CPU bits (32 or 64)
Getconf LONG_BIT
4. Use common CentOS commands to view the current linux version
More/etc/redhat-release
Cat/etc/redhat-release
5. view the kernel version using common CentOS commands
Uname-r
Uname-
6. Use common CentOS commands to view the current time
Date. The preceding section describes how to synchronize the time.
7. View hard disks and partitions using common CentOS commands
Df-h
Fdisk-l
You can also view partitions.
Du-sh
The occupied space is displayed.
Du/etc-sh
The directory size is displayed.
8. Use common CentOS commands to view installed software packages
View the software packages installed during system installation
Cat-n/root/install. log
More/root/install. log | wc-l
Check the software packages that have been installed.
Rpm-qa
Rpm-qa | wc-l
Yum list installed | wc-l
But it is strange that the number of installation packages I query through rpm and yum is not the same. No reason is found.
9. view the keyboard layout using common CentOS commands
Cat/etc/sysconfig/keyboard
Cat/etc/sysconfig/keyboard | grep KEYTABLE | cut-f2-d =
10. Use common CentOS commands to view selinux Information
Sestatus
Sestatus | cut-f2-d:
Cat/etc/sysconfig/selinux
11: Use common CentOS commands to view ip addresses and mac addresses
Copy the Code 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 common CentOS commands to view the default language
Echo $ LANG $ LANGUAGE
Cat/etc/sysconfig/i18n
Thirteen: Use common CentOS commands to check the time zone and whether UTC time is used
Cat/etc/sysconfig/clock
14. Run common CentOS commands to view the Host Name
Hostname
Cat/etc/sysconfig/network
Modifying the host name is to modify this file, and it is recommended that you also modify the host file.
15th: Use common CentOS commands to view the startup time
Uptime
09:44:45 up 67 days, 23:32 ,...
It seems that this is indeed a problem with the network segment. I started the machine 67 days ago.
# System resource usage
Copy the Code 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 233 199 778 0 0 0 1029 13 1 86 0 0
Among the many Linux terminal commands, we should introduce them by category. Here we will first talk about the file directory class, driver mounting class, program installation class, compression and decompression class, and process control class, all Linux terminal commands are frequently used here. It should be much easier to get familiar with these commands.
I. File directory
1. Create a directory: mkdir directory name
2. Delete the empty directory: rmdir directory name
3. Delete the subdirectory unconditionally: rm-rf directory name
4. Change the current directory: cd directory name (go to the user's home directory: cd ~; Go to the upper-level Directory: cd -)
5. view your own directory: pwd
6. view the current directory size: du
7. display the directory file list: ls-l (-a: add an implicit directory)
Blue: Directory; Green: executable file; Red: compressed file; light blue: linked file; Gray: other files; Red: Wrong link file
8. Browse File: more file name. txt; less file name. txt
9. copy the file: the target file of the cp source file (-r: Contains directory)
10. find the file: (1) find (2) locate command name
11. Link: (1) create a hard link: ln to link the source file (-d: create a directory link); (2) create a symbolic link: ln-s to link the source file
Ii. Driver mounting
1. Check hard disk usage: df-T-h
2. Check the disk partition: fdisk-l
3. mount the hardware and software areas: mount-t/dev/fdx | hdax/mnt/directory name
Among them: modos -- FAT16; vfat -- FAT32; ntfs -- NTFS; optical drive -- iso9660
Supported Chinese names: mount-o iocharset = x/dev/hdax/mnt/directory name (where: x = cp936 or
Mount the optical drive: mount-t auto/dev/cdrom/mnt/cdrom
Mount the ISO file: mount-t iso9660-o loop xxx. iso/path
4. unmount: umount/mnt/directory name
Unmount all: umount-
5. Create a file system: mkfs-t/dev/hdxx. Ftype: ext2, ext3, and swap
Iii. Program Installation
1. RPM package installation: (1) install rpm-ivh somesoft. rpm
(2) reverse installation (uninstall) rpm-e somefost. rpm
(3) query rpm-q somefost or rpm-qpi somefost. rpm (where: p is not installed; Information contained in I)
(4) query the location after installation: rpm-ql somefost. rpm
(5) upgrade and install: rpm-Uvh somesoft. rpm
(6) force installation: rpm-ivh -- nodeps somesoft. rpm or rpm-ivh -- nodeps -- force somesoft. rpm
2. Install the source code package:
Read README
Basic usage
(1) configuration: extract the directory./configure
(2) Compile: extract the make
(3) installation: make install in the decompressed directory
3. Install src. rpm
Iv. compression and decompression
Tar command: tar [-cxtzjvfpPN] file and directory ....
Tar command parameters:
-C: create a parameter command for the compressed file );
-X: Unlock the parameter command of a compressed file!
-T: view the files in the tarfile!
Note that c/x/t can only exist under the parameter! Cannot exist at the same time!
Because it is impossible to simultaneously compress and decompress.
-Z: does it have the gzip attribute at the same time? That is, do I need to use gzip for compression?
-J: Does it have bzip2 attributes at the same time? That is, do I need to use bzip2 for compression?
-V: The file is displayed during compression! This is common, but it is not recommended to use it in the background execution process!
-F: use the file name. Please note that the file name should be followed immediately after f! Do not add parameters!
For example, using "tar-zcvfP tfile sfile" is an incorrect method.
"Tar-zcvPf tfile sfile" is correct!
-P: use the original attributes of the original file (the attributes will not be changed based on the user)
-P: absolute paths can be used for compression!
-N: a new date (yyyy/mm/dd) will be packed into the new file!
-Exclude FILE: do not pack the FILE during compression!
Example:
Example 1: package all the files in the/etc directory into/tmp/etc.tar
[Root @ linux ~] # Tar-cvf/tmp/etc.tar/etc <= package only, do not compress! Tar-cvf target file source file (the same as below) for example: tar-cvf a.txt.tar a.txt
[Root @ linux ~] # Tar-zcvf/tmp/etc.tar.gz/etc <= compressed with gzip
[Root @ linux ~] # Tar-jcvf/tmp/etc.tar.bz2/etc <= compressed with bzip2
# Note that the file name after parameter f is obtained by ourselves. We use. tar for identification.
# If the z parameter is added, .tar.gz or. tgz is used to represent the tar file ~ compressed by gzip ~
# If you add the j parameter, use .tar.bz2 as the file name ~
# A warning message is displayed when the preceding command is executed:
# "Tar: Removing leading '/" from member names "is a special setting for absolute paths.
Example 2: Check the files in the above/tmp/etc.tar.gz file?
[Root @ linux ~] # Tar-ztvf/tmp/etc.tar.gz
# When we use gzip to compress the files in the tar file,
# Add the z parameter! This is important!
Example 3: Decompress the/tmp/etc.tar.gz file under/usr/local/src.
[Root @ linux ~] # Cd/usr/local/src
[Root @ linux src] # tar-zxvf/tmp/etc.tar.gz
# By default, We Can uncompress files anywhere! In this example,
# First, I will transform the working directory to the/usr/local/src directory, and unlock/tmp/etc.tar.gz,
# The unlocked directory will be in/usr/local/src/etc! In addition, if you enter/usr/local/src/etc
# The file attributes in this directory may be different from those in/etc!
Example 4: Under/tmp, I only want to unbind the etc/passwd in/tmp/etc.tar.gz.
[Root @ linux ~] # Cd/tmp
[Root @ linux tmp] # tar-zxvf/tmp/etc.tar.gz etc/passwd
# I can use tar-ztvf to check the file name in the tarfile. If you only need one file,
# You can issue it in this way! Notice! The root directory in etc.tar.gz/is removed!
Example 5: Back up all the files in/etc/and save their permissions!
[Root @ linux ~] # 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: only new files in/home are backed up.
[Root @ linux ~] # Tar-N "2005/06/01"-zcvf home.tar.gz/home
Example 7: I want to back up/home,/etc, but not/home/dmtsai
[Root @ linux ~] # Tar-exclude/home/dmtsai-zcvf myfile.tar.gz/home/*/etc
Example 8: package/etc/and unpack it under/tmp without generating a file!
[Root @ linux ~] # Cd/tmp
[Root @ linux tmp] # tar-cvf-/etc | tar-xvf-
# This action is a bit like cp-r/etc/tmp ~ It is still useful!
# Note that the output file is changed to-and the input file is changed to-, and there is another file | Yes ~
# This represents standard output, standard input, and pipeline commands respectively!
5. Process Control
1. List the current process ID: ps-auxw
2. terminate processes: (1) terminate a single process: kill process ID
(2) terminate all processes of the program: Killall program name
(3) Terminate the X-Window program: xkill
3. View resource usage: (1) top (2) free (3) dmesg
4. view the 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 the desktop: switchdesk gnome | KDE |...