First, the server hardware configuration
1, view hard disk and partition condition
# fdisk-l
2. View the usage of partition space
You can view each partition size, used, available, percent used, mount status
1) default Unit is K
# DF
2) More readable display, such as Unit m, G, etc.
# df-h
3. View memory Information
1) Use the free command
The default unit is K, which can be displayed by combining the parameters-B, K,-M, respectively
# free
# Free-b
# free-k
# free-m
2) View the/proc/meminfo file for more detailed memory information than the free command
# Cat/proc/meminfo
4. CPU Information
1) query CPU basic information
# More/proc/cpuinfo
# More/proc/cpuinfo | grep "Model Name" | Sort | Uniq
Model Name:intel (R) Xeon (r) CPU E7330 @ 2.40GHz
2) How many CPUs are queried (the same physical ID is the same CPU)
# More/proc/cpuinfo | grep "Physical ID" | Sort | Uniq
Physical id:0
Physical Id:1
3) Query the number of individual CPU cores
# More/proc/cpuinfo | grep "CPU Cores" | Sort | Uniq
CPU Cores:6
4) Query the number of individual CPU threads (logical processor)
# More/proc/cpuinfo | grep siblings | Sort | Uniq
Siblings:12
Second, System Information
1. View System Information
1) View kernel name
# uname
Equivalent
# uname-s
2) View complete system information, including kernel name, hostname, kernel version, processor architecture, etc.
# uname-a
2. View Redhat Release Release information
# More/etc/redhat-release
3. View Host Name
# hostname
# Uname-n
Hostname The corresponding configuration file is/etc/sysconfig/network, if hostname in the configuration file is empty, (none), localhost, or localhost.localdomain, it will try to base the actual IP from/ Find the hostname of the mapping in etc/hosts, use the hostname if it exists, or use the original hostname.
Third, network configuration
1. View the status of the network service, start, stop, or restart the network service
# Service Network Status|start|stop|restart
2, display, set up network equipment
1) View the network interface information that is enabled
# ifconfig
2) View all network interface configurations
# ifconfig-a
3) View Eth0 network interface Configuration
# ifconfig Eth0
4) Enable Eth0 network interface
# ifconfig eth0 up
# ifup Eth0
5) Turn off the Eth0 network interface
# ifconfig eth0 Down
# Ifdown Eth0
6) Real-time (temporary) modification of eth0 IP address
# ifconfig eth0 IP Address
7) Real-time (temporary) modification of eth0 IP address, subnet mask
# ifconfig eth0 IP address netmask subnet mask
Real-time manual modification of some network interface parameters, can be implemented using ifconfig, if it is to be directly in the configuration file, that is, in the/etc/sysconfig/network-scripts inside the IFCFG-ETHX and other files set parameters to start, That would have to be done by Ifdown or ifup.
Ifconfig is a command.
Ifup, Ifdown, is a script that searches directly into the/etc/sysconfig/network-scripts directory for a corresponding configuration file, such as Ifup eth0, which will find the contents of the Ifcfg-eth0 file and set it up.
However, since these two programs are primarily search settings files (ifcfg-ethx) to start and shut down, make sure that the ifcfg-ethx is actually in the correct directory before use, or it will fail to start. In addition, if you set the ifconfig eth0 or modify the network interface, you will no longer be able to shut down in the Ifdown eth0 way. Because Ifdown will analyze and compare the current network parameters and ifcfg-eth0 whether the match, if not, will give up this operation. Therefore, after you have modified with ifconfig, you should ifconfig eth0 down to be able to close the interface.
3. Check the network card configuration file
Network Interface Profile directory:/etc/sysconfig/network-scripts, where Ifcfg-eth0 is the default first network interface, if there are multiple network interfaces in the machine, then the name and so on Ifcfg-eth1, ifcfg-eth2 ...
# More/etc/sysconfig/network-scripts/ifcfg-eth0
Iv. System service Configuration
1. View the running status of all system services
# service--status-all
2. View service status, start, stop, or restart the service
# Service Name Status|start|stop|restart
3. Query and update the operating level information of the system service
1) View the list of system services and the runlevel of each service
# chkconfig--list
2) Add service
# chkconfig--add Service Name
3) Delete Service
# chkconfig--del Service Name
4) Turn on, off, or reset at a running level
# chkconfig--level 2345 name <on|off|reset>
V. Display network, process status
1. Display Network status
1) View the sockets in the monitor
# netstat-l
2) View the TCP Transport protocol connection condition
# NETSTAT-T
3) View the UDP transport protocol connection condition
# Netstat-u
4) View all sockets in the current connection
# netstat-a
5) Display the network connection status, display the IP address without using the domain name
# Netstat-n
6) View the TCP port in the listener
# NETSTAT-TNLP
7) View UDP ports in the listener
# NETSTAT-UNLP
8) Pagination Display results
# Netstat-anp|more
9) See if the port is being used
# NETSTAT-NLP | grep Port number
2. Real-time monitoring of CPU, memory, process and other usage
# Top
Enter uppercase P: Sort by CPU usage in descending order
Enter uppercase M: Sort by memory usage in descending order
3. Process Management
1) View All processes
# PS-EF
# Ps-aux
2) Show all processes in the process tree format
# PS-EJH
3) filtering process via grep
such as finding a tomcat process can generally be written like this
# Ps-ef|grep Tomcat
4) Close the process
Close process
# Kill Process Number
Force shutdown process
# kill-9 Process Number
Six, disk operation
1. CD command
Switch directories
1) switch to the specified directory
# Cd/var/log
2) switch to the current user's master/home directory
# CD ~
3) switch to the top level directory
# CD:
4) Return to the most recently accessed directory, this is often used, do not need to enter the directory yourself
# CD-
2. PWD command
Displays the current working directory
# pwd
3. ls command
Listing Directory Contents
1) List the files and subdirectories of the current directory
# ls
2) List the files and subdirectories of the specified directory
# ls Dir
3) List the files and subdirectories of the current directory, including hidden files
# ls-a
4) List the files and subdirectories of the current directory for more information
# ls-l
5) Lists the details of the files and subdirectories of the current directory and displays them in a better-readable format
# LS-LH
6) Sort by modified time in descending order
# LS-LT
7) Sort by modified time in ascending order
# LS-LRT
Vii. File and directory management
1. Directory Management
1) Create a directory
# mkdir Dir
2) Delete Directory
# rm-r Dir
Delete Directory does not prompt
# RM-RF Dir
Delete all files and directories under the directory
# RM-RF dir/*
3) Rename, move directory
If Newdir does not exist, Olddir is renamed to Newdir and Olddir is moved to Newdir directory if newdir exists
# MV Olddir Newdir
4) Copy Directory
If NewDir2 does not exist, a copy of Newdir is copied as NewDir2, and if NewDir2 already exists, a copy of the Newdir is moved to the NEWDIR2 directory
# cp-r Newdir NewDir2
2. Document Management
1) Create an empty file
# Touch File.txt
# > File.txt
2) Delete files
# RM File.txt
Delete files without prompting
# rm-f File.txt
3) Renaming files
# mv File.txt File5.txt
4) Moving files
# mv File.txt Newdir
Move multiple files or directories to the specified directory, moving a.txt, B.txt, C.txt, Olddir to the Newdir directory
# mv A.txt B.txt c.txt olddir/newdir/
5) Copying files
# CP Old.txt New.txt
Copy files and directories under the Newdir directory to the TARGETDIR directory
# cp-r newdir/* targetdir/
3. Find command
Find a file or directory
1) Look for all files or subdirectories that are prefixed with file in the current directory
# Find-name file\*
2) Find the file and output the results to the Filelist.txt file
# find-name file\*-fprint filelist.txt
3) List of documents that have changed within the last two days of the catalogue
# find/home-mtime 2
4) Look for files or directories in the Dir directory that are prefixed with file and search for up to 1 levels of subdirectories.
# find dir/-name file\*-maxdepth 2
4. File command
Identify the type of file or directory
1) View the types of files and directories under the/home/jsam directory
# file/home/jsam/*
2) View the type of the specified file or directory
# file filename
5. du command
Displays the size of the file or directory.
1) Displays the disk space occupied by all subdirectories under the current directory
# du
2) Displays the disk space occupied by all subdirectories in the current directory. Display size in bytes, K, M, and more readable ways
# Du-b
# du-k
# du-m
# du-h
3) Displays the disk space occupied by all subdirectories in the current directory. Show up to 2 levels of subdirectories only
# du--max-depth=2
4) Displays the disk space occupied by all subdirectories in the current directory. When the directory size is displayed, it does not include the size of its subdirectories, that is, the size of the directory excludes the size of the subdirectories.
# du-s
5) Displays the disk space occupied by the current directory
# du-s
# Du-sh
6) Displays the disk space occupied by all subdirectories and files in the current directory
# du-a
7) List the largest 10 files in the current directory
# Du-s * | Sort-n | Tail
Note: Do not use Du-sh, although-H will make readability better, but the unit may not be unified
6. Sort command
Sorts the contents of the text file.
1) Sort the contents of the file in the default way display
# sort File.txt
2) Reverse-order the contents of the file in the default way
# sort-r File.txt
3) Review the process and sort by default according to the second column
# Ps-aux | Sort-k 2
4) View process, sort by memory utilization in ascending order
# Ps-aux | Sort-nk 4
7. grep command
Used to find strings that meet the criteria in a file, or to filter the standard input stream.
1) in the current directory, look for a file that includes a "Java" string from a file with the extension log
# grep Java *.log
2) Find the file containing the "Java" string for all files in the current directory and subdirectories
# grep-r Java *
3) See if the port is being used
# NETSTAT-NLP | grep Port number
4) filtering process via grep
such as finding a tomcat process can generally be written like this
# Ps-ef | grep Tomcat
5) View the language type in the environment variable, ignoring the case
# Set | Grep-i Lang
8. Tail command
The final part of the output file content
1) Display the last contents of the file (default is the last 10 lines)
# tail File.txt
2) Display the last 20 lines of the file
# tail-n File.txt
3) Real-time monitoring log files
# tail-f Logs/catalina.out
9. Cat commands
1) View the contents of the file
This command displays the entire file content at once
# cat File.txt
2) give only the line number that is not empty (-B,--number-nonblank)
# cat-b File.txt
3) Give all line numbers (-N,--number)
# cat-n File.txt
4) There is a continuous number of blank lines, leaving only one blank line (-S,--squeeze-blank)
# cat-s File.txt
5) Merge Files A, B is C
# Cat A B >> c
6) Clear the file
# Cat/dev/null > G.txt
7) Create a file from the keyboard input content
Input and enter, and then CTRL + C to save the contents of the file
# cat > File.txt
10. More Commands
Pagination Displays the contents of the file, one screen at a time, and the command does not support backward/up-flipping.
# more Catalina.out
After executing the more command, a series of commands and actions are supported:
1) ctrl+f
Show next full screen
2) I space
If I is specified, the following line I is displayed, otherwise, the next full screen is displayed.
3) I enter
If I is specified, the following line of I is displayed; otherwise, the next line is displayed.
4) v
Edit changes to the current line start/usr/bin/vi
5)/pattern
Search for pattern from the beginning of the cursor to the end of the file, click the N key to find the next
11. Less command
The command is similar to the more command, but supports backward/up-flipping.
# less Catalina.out
When the Find command is executed, only the current string matching the search criteria is displayed.
# less-g Catalina.out
When a find command is executed, all strings matching the find criteria are not displayed in white
# less-g Catalina.out
Ignore case when performing a Find command
# less-i Catalina.out
Display the contents of the file and indicate the line number of each line
# less-n Catalina.out
Import data into the less command through a pipeline to read its contents and finally save it as a file
# Set | Less-o outputfile.txt
Show percentages
# less-m Catalina.out
Display percentage, current row, and total number of rows
# less-m Catalina.out
After the less command is executed, a series of commands and actions are supported:
1) ctrl+f
Show next full screen
2) I space
If I is specified, the following line I is displayed, otherwise, the next full screen is displayed.
3) I enter
If I is specified, the following line of I is displayed; otherwise, the next line is displayed. Supports upper and lower rows
4) v
Edit changes to the current line start/usr/bin/vi
5)/pattern
Search for pattern from the beginning of the cursor to the end of the file, lowercase n to find the next place
6)? pattern
Search for pattern from the beginning of the cursor to the file header, lowercase n finds the next, upper case N finds the next one in the opposite direction
12. VI Command
A powerful Linux file editing command.
1) command to enter VI
Opens or creates a new file and places the cursor at the beginning of the first
# VI Filename.txt
Open the file and place the cursor at the beginning of the last line
# VI + filename.txt
2) Move Cursor class command
H: Move the cursor to the top row of the screen
M: Move the cursor to the middle line of the screen
L: The cursor moves to the last line of the screen
0: (note is the number 0) cursor moves to the beginning of the current line
$: Cursor moves to the end of the current line
3) Screen Tumbling Class command
CTRL+F: Flip a screen to the end of a file
Ctrl+b: Turn one screen at the top of the file
4) Insert Text Class command
I: Before the cursor
I: At the beginning of the current
A: After the cursor
A: At the end of the current line
O: A new line below the current line
O: New row above the current line
5) Delete command
D0: Delete to the beginning of the line
d$: Delete to end of line
NDD: Deletes the current line and its subsequent n-1 rows
DD: Delete When moving forward
6) Search and Replace commands
/pattern: Searches for pattern at the end of the file from the beginning of the cursor
? pattern: Searches for pattern from the beginning of the cursor to the top of the file
N: Repeat the last search command in the same direction
N: Repeats the last search command in the opposite direction
: S/P1/P2: Replaces the first P1 in the current row with a P2
: s/p1/p2/g: Replaces all P1 in the current row with P2
: n1,n2s/p1/p2/g: All P1 in line N1 to N2 are replaced with P2
: g/p1/s//p2/g: Replace all P1 in the file with P2
7) Option settings
Number: Displays the line numbers of the current line
: Set Nu (set number): Displays the line numbers of all rows. or edit the file ~/.vimrc, add set Nu, so that the VI command to open the file, will automatically display the line number
: Set Nonu (set Nonumber): Hides line numbers for all rows
8) Save, exit and other commands
: w: Save current file
: x: Save current file and exit
: Q: Exit VI
: q!: Do not save file and Exit VI
: e!: Reload Content
VIII. User Management
1. User Management
Add user
# Useradd User Name
Delete User
# Userdel User Name
Modify the current user's password
# passwd
Modify the password of the specified user, only the root user can specify the user name
# passwd User Name
2. User group Management
To add a user group
# Groupadd User Group name
Delete a user group
# Groupdel User Group name
3. View user Information
View the user's UID, GID, and user group to which they belong
# ID
# ID User Name
View user Information
# Finger User Name
# MORE/ETC/PASSWD | grep User Name
4. Switch users
Switch user's environment variables without switching users
SU User name
Switch users and switch user's environment variables
Su-user name
5. Viewing logged-in user information
View the currently logged in user name
# WhoAmI
View all users who are currently logged on to the system
# WHO
View details of all users of the currently logged on system
# W
Nine, compression decompression
1. Tar command
File packaging, decompression command, can be combined with a variety of algorithms packaged after compression
1) package All files and directories in the current directory as My.tar
# TAR-CF My.tar.
2) package directory/home/jsam and display the command execution process (-V)
# TAR-CVF Jsam.tar/home/jsam
3) package the directory log and check that the backup file is correct (-W)
# TAR-CVWF Log.tar Log
4) package The directory log and compress it with the gzip command
# TAR-CZVF log.tar.gz Log
5) Unzip the TAR package
# TAR-XVF Foo.tar
6) Unzip the GZIP compression pack
# TAR-XZF Foo.tar.gz
7) Create BZIP2 compression Package
# TAR-CJF foo.tar.bz2 bar/
8) Unzip the BZIP2 compressed package and store the extracted content in the bar directory, the bar directory must already exist
# TAR-XJF Foo.tar.bz2-c bar/
9) Extract the index.html file from the gzip package
# TAR-XZF foo.tar.gz index.html
2. zip command
Zip package Compression command
1) Compress all files and subdirectories in the current directory
# zip-r First.zip *
3. Unzip command
Zip Package decompression command. A war project package that can decompress Java
1) Unzip the file directly to the current directory
# Unzip First.zip
2) Extract the index.html file from the ZIP package
# Unzip First.zip index.html
3) unzip the zip package into the dir directory
# Unzip first.zip-d dir
4. bzip2 command
BZIP2 package compression, decompression command
1) Compress files
# bzip2 file.20130126
# bzip2-z file.20130126
Results: file.20130126 compressed to file.20130126.bz2, and delete the source files, before and after the file modification time is unchanged
2) Unzip the file
# bzip2-d FILE.20130126.BZ2
Result: FILE.20130126.BZ2 is reduced to file.20130126, and the source file is deleted, the modified time of the file is unchanged before and after the decompression.
X. Permissions settings
1. chmod command
Change permissions for a file or directory.
Description
U: Owner of file or directory
G: The group to which the file or directory belongs
O: Other users
R: Read access, number code "4"
W: Write permission, number code is "2"
X: Execute permission, number code is "1"
-: No permission, number code is "0"
Read, write, and execute the number code can be added to form a combination of permissions, such as 6, 5, 3, 7 for reading and writing, read execution, write execution, read and write execution permissions
1) Add Write permission to the group to which the file belongs
# chmod G+w filename.txt
2) Increase the execution rights of all users to the file
# chmod +x filename.txt
3) Remove all user execution rights to the file
# chmod A-x filename.txt
4) Set the file owner read and Write permissions, the group read and write permissions, other people reading permissions
# chmod 664 filename.txt
5) Set the file owner read and write execute permission, the group read Execute permission, other people do not have any permissions
# chmod u=rwx,g=rx,o=-filename.txt
2. Chown command
Change the owner or owning group of the file or directory.
1) The owner of the change file is User1 and the owning group is group1
# chown User1.group1 filename.txt
2) Change the owner and owning group of all files and subdirectories under the Dir directory
# chown-r User1.group1 dir
3) Change the file owner
# chown Zhanjia A.C Change the owner of the file A.C to Zhanjia
3. CHGRP command
Change the owning group for the file or directory.
1) Change the file group to Jsam
# chgrp Jsam tomcat6.0.35.tar.gz
2) Change the owning group of all files and subdirectories under Dir directory
# chgrp-r Jsam dir/
Xi. File Transfer
1. FTP command
1) FTP Login server
# FTP host Address
2) Download the file
Download individual files
Ftp> get File.txt
Download multiple Files
Ftp> mget *.txt
ftp> mget file1.txt File2.txt
3) Uploading Files
Upload a single file
Ftp> put File.txt
Uploading Multiple files
Ftp> mput *.txt
ftp> mput file1.txt File2.txt
4) Mget, Mput, mdelete and other batch processing operation prompt switch setting
ftp> prompt On|off
5) Delete remote files
Delete remote Files
ftp> Delete file.txt
Delete multiple remote files
ftp> Mdelete file1.txt File2.txt
6) Remote Directory Management
To create a directory remotely
ftp> mkdir dir
Delete remote Directory
ftp> rmdir dir
Renaming a remote file or directory
ftp> rename src dest
7) Execute the specified command on the local side (client Linux). This command is useful to view the local side without exiting FTP
Syntax:!< command >
Ftp>!ls
Ftp>!dir
8) Other Commands
Help < commands >,? < command;: Help command, do not specify < command > list all available action commands
ASCII, ASC: Sets the mode of transmitting data to ASCII mode for transferring text files
Binary, Bin: Sets the mode of transmitting data to binary mode for transferring program files
LS, CD, PWD: General usage is the same as the Linux command
User < username: Log in to the FTP server with the specified user ID and password
Bye: exiting FTP
2. SCP command
Remote file Security Copy command. The data transfer uses SSH and uses the same authentication method as SSH, providing the same security guarantee.
Syntax: SCP [Options] [[[Email Protected]]host1:]file1 [...] [[Email Protected]]host2:]file2
General usage: SCP [optional] source file/directory destination file/directory
1) Download the file
Download the remote file to the current directory
SCP [email protected]:/opt/server/apache-tomcat-6.0.35.tar.gz.
To download a remote file as a local file/root/tomcat6.0.35.tar.gz
SCP [Email protected]:/opt/server/apache-tomcat-6.0.35.tar.gz/root/tomcat6.0.35.tar.gz
2) Uploading Files
Uploading local files to the remote directory
SCP tomcat6.0.35.tar.gz [Email protected]:/opt/
3) Download catalogue
Download the remote directory to the current directory
scp-r [email protected]:/opt/server.
Download/opt/server as/root/client if/root/client does not exist, or download/opt/server to a subdirectory of/root/client if present
scp-r [Email protected]:/opt/server/root/client
4) You can synchronize the files and directories of both servers by specifying the source and destination IP
SCP [email protected]:/root/tomcat6.0.35.tar.gz [Email protected]:/opt/software/
3. wget command
Download files from the Internet.
Download Www.iteye.com Home
# wget Www.iteye.com
Download file
# wget Http://www.fayea.com/apache-mirror/tomcat/tomcat-6/v6.0.36/bin/apache-tomcat-6.0.36.zip
Breakpoint Continuation
# wget-c Http://www.fayea.com/apache-mirror/tomcat/tomcat-6/v6.0.36/bin/apache-tomcat-6.0.36.zip
Background download, generate log Files Wget-log
# Wget-b Http://www.fayea.com/apache-mirror/tomcat/tomcat-6/v6.0.36/bin/apache-tomcat-6.0.36.zip
12. Other Commands
1. WC command
Calculates the number of words. You can calculate the number of bytes, words, characters, or lines of a file.
1) Calculate the number of file lines
# wc-l Messages.txt
2) Calculate the number of bytes in the file
# wc-c Messages.txt
3) Calculate the number of files by the way of pipeline
# ls | Wc-l
2. RPM command
RPM Package Management Commands
1) Install RPM package
# RPM-IVH gcc.rpm
2) Upgrade RPM package
# RPM-UVH gcc.rpm
3) Unload RPM package
# rpm-e GCC
4) Query the installed RPM package
# RPM-QA
3. Find History commands
1) History command
Show executed commands
# History
Execute a command with number 158
#!158
2) Reverse lookup of executed commands via Ctrl+r
Combination key Ctrl+r, enter to query the string, and then repeat the combination of key ctrl+r for reverse lookup.
CTRL + C: Cancel find
ESC: End lookup, get the found command
Enter: Directly execute the found command
4. md5sum command
MD5 message digest for computed files
# md5sum Filename.txt
5. Set command
Querying or setting environment variables
1) Querying the current environment variables
# set
6. Mount command
Mount File System
1) Mount the/DEV/HDB1 to the/MNT/HDB1
# MOUNT/DEV/HDB1/MNT/HDB1
2) mount the/DEV/HDB1 to/MNT/HDB1 and specify that the Vfat file system be loaded
# mount-t VFAT/DEV/HDB1/MNT/HDB1
7. Umount command
Uninstalling the file system
1) Uninstalling the file system
# UMOUNT/DEV/HDB1
8. Nohup command
Run the command without hanging up, combined with & enables the user to exit the terminal or log off after the program has been running in the background.
# Nohup./start.sh &
9. Date command
Displays or sets the system time and date.
1) Displays the date and time of the current system
# date
# date "+%y-%m-%d%h:%m:%s"
2) Set the time and date of the system
# date-s "2013-2-10 12:59:00"
# date-s "2013/2/10"
# date-s "2014-3-12"
# date-s "12:59:00"
10. SSH command
SSH Telnet
# SSH user name @ip address
11. Ping command
Detection of the host, usually used to detect the host network function is normal, the network between the two hosts is not a pass
1) continue to detect IP until the user actively ends
# ping 192.168.0.100
2) Send 5 ping packets for detection
# ping-c 5 192.168.0.100
12. Telnet command
Telnet command
1) Login Host
# telnet 192.168.0.100
2) Check if TCP port 8080 is listening
# telnet 192.168.0.100 8080
Programmer Prerequisites: Linux Routine maintenance commands