Liunx system management common commands, tips and notes
Source: Internet
Author: User
This article mainly introduces common commands and notes for Liunx system management, including common commands, iptables shielding IP segments, and quick file clearing techniques, for more information about hardware devices and system information, see section 1. linux.
1. system
Copy codeThe code is as follows:
# Uname-a # View kernel/operating system/CPU information
# Head-n 1/etc/issue # view the operating system version
# Cat/proc/cpuinfo # View CPU information
# Hostname # view the computer name
# Lspci-TV # List all PCI devices
# Lsusb-TV # List all USB devices
# Lsmod # List loaded kernel modules
# Env # View environment variables
2. common resource query commands
Copy codeThe code is as follows:
# Free-m # View memory usage and swap zone usage
# Df-h # view the usage of each partition
# Du-sh <目录名> # View the size of a specified directory
# Grep MemTotal/proc/meminfo # View total memory
# Grep MemFree/proc/meminfo # view the amount of idle memory
# Uptime # View system running time, number of users, and load
# Cat/proc/loadavg # View system load
2. common commands for disks and partitions
Copy codeThe code is as follows: # mount | column-t # view the status of the mounted partition
# Fdisk-l # View all partitions
# Swapon-s # View all swap partitions
# Hdparm-I/dev/hda # View disk parameters (only applicable to IDE devices)
# Dmesg | grep IDE # view the IDE device detection status at startup
4. common network management commands
Copy codeThe code is as follows:
# Ifconfig # view the attributes of all network interfaces
# Iptables-L # View firewall settings
# Route-n # view the route table
# Netstat-lntp # View all listening ports
# Netstat-antp # View all established connections
# Netstat-s # View network statistics
5. common process-related commands
Copy codeThe code is as follows:
# Ps-ef # View all processes
# Top # Display process status in real time
6. common user commands
Copy codeThe code is as follows:
# W # View active users
# Id <用户名> # Viewing specified user information
# Last # View user logon logs
# 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 scheduled tasks of the current user
6. services
Copy codeThe code is as follows:
# Chkconfig-list # list all System Services
# Chkconfig-list | grep on # list all started System Services
7. programs and software
Copy codeThe code is as follows:
# Rpm-qa # View all installed software packages
II. use iptables in linux to shield IP segments:
Shield a single IP address
Copy codeThe code is as follows: iptables-I INPUT-s 124.115.0.199-j DROP
Blocked IP segments
Copy codeThe code is as follows: iptables-I INPUT-s 124.115.0.0/16-j DROP
Iptables-I INPUT-s 124.115.3.0/16-j DROP
Iptables-I INPUT-s 124.115.4.0/16-j DROP
Shield the entire IP segment
Copy codeThe code is as follows: iptables-I INPUT-s 124.115.0.0/8-j DROP
Block several IP segments
Copy codeThe code is as follows: iptables-I INPUT-s 61.37.80.0/24-j DROP
Iptables-I INPUT-s 61.37.81.0/24-j DROP
Do not forget to save it after execution, and restart the iptables service. The above is how to use iptables in Linux to block IP segments.
Unseal
Copy codeThe code is as follows:
Iptables-d input-s 14.153.250.80/24-j DROP
Iptables-d input-s 14.153.250.80-j DROP
Prohibit all IP addresses from accessing a port
Copy codeThe code is as follows:
Iptables-I INPUT-p TCP-dport 80-j DROP
3. several methods to quickly clear file content:
Copy codeThe code is as follows: $:> filename # Where: a placeholder does not produce any output.
$> Filename
$ Echo ""> filename
$ Echo/dev/null> filename
$ Echo> filename
$ Cat/dev/null> filename
In some cases, you need to clear the file content without deleting the file. For example, log file (log.txt );
In linux, the command is: true> log.txt
Test results:
Copy codeThe code is as follows: touch log.txt creates a new log.txt file
Vi log.txt → # Edit a file
Enter anything at will
: Wq! Press enter → # save and exit;
Cat log.txt → # view the file content;
True> log.txt → # view the content in the file;
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.