Linux Common commands

Source: Internet
Author: User
Tags time zones locale iptables

CENTOS6 iptables Firewall

To clear the firewall rule:
Iptables-f

To turn on the firewall:
Service Iptables Start

To turn off the firewall:
Service Iptables Stop

To restart the firewall:
Service Iptables Restart

Open 80 Ports:
Iptables-i input-p TCP--dport 80-j ACCEPT

To save a firewall rule:
Service Iptables Save or Iptables-save


centos7 FIREWALLD Firewall

Open httpd Service
Firewall-cmd--add-service=http
firewall-cmd--permanent--add-service=http
Firewall-cmd--reload

FIREWALLD Firewall Open 80 port
firewall-cmd--zone=public--add-port=80/tcp--permanent #开启80端口
firewall-cmd--reload #重新载入
firewall-cmd--zone=public--query-port=80/tcp #查看80端口是否开启
firewall-cmd--zone=public--remove-port=80/tcp--permanent #删除80端口
firewall-cmd--zone=public--list-ports #查看所有打开的端口

stop, start, and restart Firewalld
stop: systemctl stop Firewalld
start: Systemctl start Firewalld
Restart : systemctl restart Firewalld

View the number of CPUs
Cat/proc/cpuinfo | grep processor

viewing individual CPU information
Cat/proc/cpuinfo

View CPU Size
cat/proc/cpuinfo |grep "model name" && cat/proc/cpuinfo |grep "Physical ID"

View Memory Conditions
free–m

View Memory Size
cat/proc/meminfo |grep memtotal or grep memtotal/proc/meminfo

Viewing free memory
grep memfree/proc/meminfo

View all swap partitions
swapon-s

view hard disk size
fdisk-l |grep Disk

To view the usage of each partition
Df-ht

View system load disks and partitions
Cat/proc/loadavg

to view the size of a specified directory
Du-sh

viewing the system version
Cat/etc/redhat-release

Displays the release number of the operating system
Uname-r

Displays the system name, the node name, the operating system's release number, the operating system version, and the machine ID number of the running system.
uname-a

to view the name of a computer
hostname

CENTOS6 Modifying host names (permanent modification)
vim/etc/sysconfig/network

Centos7 Modifying host names (permanent modification)
method One: Modify the/etc/hostname file setting host name
method Two: hostnamectl set-hostname xxx

View all PCI devices
LSPCI–TV

View all USB devices
LSUSB–TV

to view the loaded kernel modules
Lsmod

View environment variable resources
Env

View System uptime, number of users, load
Uptime

View current system time
Date

Sync Time
ntpdate-u ntp.api.bz #ntp. api.bz NTP Server (Shanghai)

View time Zones
Date-r

to view the mounted partition status
Mount | column-t

to view the properties of all network interfaces
ifconfig

View firewall Settings
iptables-l

View the routing table
Route–n

See if Port 443 is occupied
NETSTAT-TNL | grep 443

to view all established connections
NETSTAT–ANTP

View service Listening ports
netstat-atunlp | grep ssh

View service Processes
Ps-aux | grep ssh or ps-ef | grep ssh

View User login log
Last

View scheduled tasks for the current user
crontab-l

View all system Services
chkconfig--list #适用于centos6
systemctl list-unit-files #适用于centos7
systemctl--type Service #适用于centos7

View all started system services programs
chkconfig--list | grep on #适用于centos6
systemctl list-unit-files #适用于centos7

to view the current startup information for a specified service:
chkconfig--list httpd

to view all installed packages
Rpm-qa

Count the number of installed packages
Rpm-qa | wc-l

Show process status in real time
Top

View Active Users
W

View specified user information
ID User
 
#centos7 Systemctl

View service Startup Items
Systemctl list-unit-files

List all Services
Systemctl List-unit-files–type=service

How to activate the service and enable or disable the service at power-on (that is, start the Mysql.service service automatically when the system starts)
systemctl is-active Mysql.service
Systemctl Enable Mysql.service
systemctl Disable Mysql.service

systemctl status Cron.service #查看定时任务状态
 
systemctl Stop Cron.service #关闭定时任务
 
systemctl status Cron.service #查看操作情况
 
systemctl list-unit-files|grep Enable #查看当前正在运行的服务
 
systemctl Disable Postfix.service #关闭邮件服务
 
systemctl list-unit-files|grep postfix #查看邮件服务是否开启
 
systemctl Stop Firewalld.service #关闭防火墙
 
systemctl is-enable #开启的服务
 
systemctl Disable #关闭的服务

To see if the NFS service is booting up:
systemctl is-enabled Nfs.service

Use the Systemctl command to kill the service:
Systemctl Killcrond

temporarily modify SELinux:
Setenforce 0|1

To view the SELinux status:
Getenforce

permanently close selinux:
sed-i '/selinux=enforcing/selinux=disabled/g '/etc/sysconfig/selinux

viewing the system run level
RunLevel or Who-r

Linux System has 7 runlevel (runlevel)
runlevel 0: System down state, system default RunLevel cannot be set to 0, otherwise it will not start normally
runlevel 1: Single User working status, root privilege, for system maintenance, remote login Forbidden
RunLevel 2: Multi-User State (no NFS)
RunLevel 3: Full multiuser State (with NFS), enter console command line mode after login
Run Level 4: System not used, reserved
Run level 5:x11 console, login to GUI mode
RunLevel 6: The system shuts down gracefully and restarts, the default runlevel cannot be set to 6, otherwise it will not start normally
 
#centos7更改启动模式;

See which mode is currently starting:
systemctl Get-default or RunLevel

To temporarily modify the run level:
Init 3

To permanently modify the run level:

start in command line mode:
systemctl Set-default multi-user.target

start with a graphical interface:
systemctl Set-default graphical.target
reboot restart takes effect after change

CENTOS6 Changing the startup mode

start with a graphical interface
Vim/etc/inittab
Id:5:initdefault:

start with command line
Id:3:initdefault:

view defined values for the current PS1
Set | grep PS1

To Modify the command prompt color
Vim ~/.BASHRC
ps1= "\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[36;40m\]\w\[\e[0m\]]\\$"

View system Support languages
locale

view current system language
Echo $LANG $LANGUAGE

To Modify the system language:
Change to English
Vim/etc/profile
lang= "en_US. UTF-8 "
export PATH USER LOGNAME MAIL HOSTNAME histsize INPUTRC LANG

Change to Chinese
Vim/etc/profile
lang= "ZH_CN. UTF-8 "
export PATH USER LOGNAME MAIL HOSTNAME histsize INPUTRC LANG

Centos7 Modifying Character Set methods

method One: Edit the character set configuration file
/etc/locale.conf

method Two: The command line modifies the character set
localectl Set-locale lang=zh_cn. UTF-8
localectl Status
CENTOS6 Modifying Character Set methods
/etc/sysconfig/i18n

view the DNS resolution process
Dig +trace www.baidu.com

Route tracking
traceroute www.qq.com

View Nginx Script location
which Nginx

The which instruction searches for the location of a system command in the path specified by the path variable, and returns the first search result.
To view the Nginx configuration file path

Whereis Nginx

find a file under the current path

Find nginx*

find files under the root directory
Find/nginx

Clear History
history-c


Linux Common commands

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.