--------------------------------------System Management-------------------------------------
Uname-a
Hostname Host Name
Hostnamectl
Cat/etc/redhat-release #查看系统版本
Timedatectl #查看日期时间
Timedatectl List-timezones # List all time zones
Timedatectl SET-LOCAL-RTC 1 # Adjust the hardware clock to match the local clock, 0 for UTC time
Timedatectl Set-timezone Asia/shanghai # Set the system time zone to Shanghai
Date or date "+%y-%m-%d%h:%m:%s" #查看时间
Date-s "20180508 10:00:00" #设置时间
Format:%y-%m-%d%h:%m:%s
echo "123" > Test_
date ‘+%Y-%m-%d %H:%M:%S‘
Cal #显示日期
Reboot #重启系统
Init 6 #重启系统
Init 0 #关闭系统
Poweroff #关闭系统
Shutdown-h now #关闭系统
Logout #注销系统
Login
Who #显示当前登入的用户
Last #历史登录记录
Sestatus #SELINUX Status
Getenforce #显示SELINUX状态
Setenforce 0 #临时关闭SELINUX, permanently off sed-i ' s/selinux=enforcing/selinux=disabled/'/etc/selinux/config
Ulimit-n 65535 # Set process open maximum number of files
Ntpdate cn.pool.ntp.org #需要安装, update the system time, the domestic address is: Cn.pool.ntp.org Ali ntp1~ntp7.aliyun.com 7
Crontab-e/-l/-r #计划任务e编辑l查看r删除
-
-
-
-
- Task
Timeshare Month Week
/5 executed every 5 minutes
5/15 5,20,35,50 per plus 15 minutes
23-7/1 /usr/local/etc/rc.d/lighttpd Restart
From 11 o'clock to 7 in the morning, restart Apache every hour.
4 1,10,22 /usr/local/etc/rc.d/lig/httpd Restart
The above example shows that 4:45 restarts Apache on the 1, 10, and 22nd of the month.
1 6,0/usr/local/etc/rc.d/lig/httpd restart
The above example shows that 1:10 restarts Apache every Saturday and Sunday.
18-23 */usr/local/etc/rc.d/lig/httpd restart
The above example shows that the Apache is restarted every 30 minutes from 18:00 to 23:00 every day.
Echo-e "ok! \c "#-E open escape \c no newline \ n newline, default
' .... ' #原样输出
....
#先执行中间的命令
" .... "# Variable reference
Echo-e \e[1;32m these words have color. e[0m "
Echo-e" \E[COLOR1; COLOR2M content \e[0m "
where COLOR1 and COLOR2 are foreground and background colors and are strings that you want to display in color.
COLOR1 1 Bright 2 Dark 4 underline 5 blinking 7 background
COLOR2 31 Red 32 green 33 yellow 34 Blue 35 Pink 31-38
Clear #清屏
alias new command = ' original command-options/Parameters ' # set alias
Journalctl-xe #查看日志
-------------------------------process, System Information management-----------------------------------
Ps-aux #进程状态
Ps-le #进程状态
Ps-aux | SORT-RNK 4 | Head-7 #找出当前系统内存使用量较高的进程
Ps-aux | SORT-RNK 3 | Head-7 #找出当前系统CPU使用量较高的进程
Sort-rnk 4 (k represents starting from the first position, the following number 4 is its starting position, the end position if not, then the default to the last;
n refers to the order of its values;
R refers to the reverse, here refers to the reverse comparison results, the output by default from small to large, backward from large to small. )。
You can see the%mem in the 4th position, based on the values of the%mem from the large to the small sort. 3 is the location of%CPU.
Ps-eo%mem,%cpu,comm--sort=-%mem | Head-5
Ps-aux|head-1|awk ' {print $4,$11} ';p S-aux | Sort-rnk 4 |awk ' {print $4,$11} ' | Head-5 #显示占用内存前5的进程
%MEM COMMAND
3.3/usr/bin/python
1.9/usr/bin/python
1.1/usr/lib/polkit-1/polkitd
0.9/usr/sbin/networkmanager
0.5/usr/sbin/rsyslogd
PIDOF Process name #--view process ID
Kill-9 PID #--End Process
Killall Service Name #---End all processes for this service
Pkill Service Name #结束进程
Top # Dynamic Process
Press Capital M to display up to 5 memory usage
Press upper case p to display the top 5 CPU using the previous
Top-b-N 1 |head-5
Htop #进程界面管理
Lsof abc.txt #显示开启文件abc. txt process
Vmstat 1 5 #每秒显示一次, showing 5 this
Dstat-tamp #系统性能的监控工具, yum installation required
T: #时间
A: #一个缩写合集, including CPU (-c), disk IO (-D), network traffic (-N), Swap page In/out (-G), system interrupt and Context switch (-y)
If you use BOND0 to bind two Nic, bond0 and ETH0+ETH1 will repeat the calculation, you need to split the value of half, or with the-n bond0 such a single screw out.
If you want to monitor different disks, you can-D sda,sdb,total
M: #内存
P: #进程数 (in Run, blocked, new)
Iostat-x 1 5 #安装sysstat, including SAR, SADF, Mpstat, Iostat, Pidstat and so on. To view system IO status information
x #参数, output more details
D #参数, display device (disk) Usage status
C #参数, view partial CPU status information
K #参数, some columns using block are forced to use the kilobytes unit
Free-h #显示内存
W #查看当前系统的负载
Uptime #系统运行时间和负载
--------------------------------------Service Management-------------------------------------
NTSYSV # requires installation, graphical interface service management
Chkconfig
Service
Systemctl Command Description
SYSTEMCTL Status Display System state
Systemctl List of all system services
Systemctl list-units List all services that are started
Systemctl list-unit-files List all installed services
Systemctl list-units–type=service–all List all service types
Systemctl List-units–type=target–all List all target types
Systemctl List-units--all | grep ssh finds SSH service in all system services
Systemctl List-unit-files | grep enabled to view the list of services that have been started:
Systemctl is-enabled httpd See if httpd is on, start disabled to off enabled
Systemctl is-active httpd See if httpd is running
Systemctl Mask httpd Disable the specified service
Systemctl unmask httpd activation finger Service
Systemctl enable httpd set up service boot
Systemctl Disable HTTPD Setup service disable boot start
Systemctl Start httpd Service
Systemctl Stop httpd Service
Systemctl Restart httpd Restart Service
Systemctl Status httpd View service status
Systemctl Poweroff system shutdown
Systemctl reboot Restart
--------------------------------------Network Management-------------------------------------
Ifconfig #查看IP, Install the Net-tools package
cat/etc/resolv.conf #查看NDS
netstat-rn #查看网关
IP addr Show
IP route show
Ping
Dig #DNS解释 , you need to install the bind-utils
nslookup #需要安装bind-utils
traceroute #追踪数据传输路由状况. You need to install the
Route
Route add-net 192.168.0.0 netmask 255.255.0.0 GW 192.168.1.1 #添加静态路由
Route del 192.168.0.0 netmask 25 5.255.0.0 GW 192.168.1.1 #删除
NETSTAT-TULNP #显示TCP/UDP Port connection and process name
Mail #邮件管理, installing MAILX or SendMail
Mail-s "Test" [email protected] </ETC/PASSWD # message subject test, content is passwd file content, sent to [email protected] Mailbox
echo "Test Mail" | Mail-s "Test" [email protected]
Tcpdump #抓包
D #列出可用于抓包的接口
I #指定需要抓包的接口
V or-VVVV #详细的信息
C #制定抓包的数量
XX #输出包的头部数据, will be output in 16 and ASCII two ways simultaneously
Tcpdump-c 2-q-xx-vvv-nn-i eth0 TCP DST Port 22
The value that can be given has host/net/port/portrange. For example "host Foo", "Net 128.3", "Port", "Portrange 6000-6008". The default type is host.
The values that can be given include src/dst/src or DST/SRC and DST, which are src or DST by default. For example, "src foo" represents a packet with a source host of Foo, and "DST net 128.3" represents a packet with a target network of 128.3.
"Src or DST Port 22" represents a packet with a source or destination port of 22.
ARP #查看arp
Telnet IP #连接远程主机
Wget-o renamed after download
Wget-o 123.txt http://1.1.1.1/456.txt Download 456.txt after renaming to 123.txt
Wget-c Breakpoint Continuation
SCP #Linux之间复制文件和目录
Scp-p 10060-r Local Directory [email protected] Remote host IP: Directory # remote replication use SSH 10060 port to copy Local entire folder to remote host, upload
SCP [email protected] Remote host IP: directory local directory #把远程主机的文件或目录拷贝到本地
Curl #浏览器
Curl-is www.163.com # View site version details
FTP IP #默认21口 If the other port first FTP-->open IP Port--
Ssh-p Port user name @ip #连接远程服务器
SSH [email protected] "LS-L/tmp" #查看远程目录
Lsof
Option parameters:
+d< Catalogue > #递归列出目录下被打开的文件
-U S #列出login program for name or UID s
3)-c< process name > #列出指定进程所打开的文件
-i< conditions > #列出符合条件的进程. (4, 6, protocol,: Port, @ip)
-n-n< directory > List files that use NFS
Lsof-i:80 #查看端口是否在监听
Lsof-i #显示所有链接
Lsof-itcp #显示tcp连接
Lsof-i 6 #显示IPV6流量
Lsof-u Sunjimeng |more-20 #列出某个用户打开的所有文件相关的进程信息
Iftop #网卡流量
Ss-lntup|egrep "3306|80"
Ss-lntup|egrep "Nginx|mysql"
--------------------------------------Disk Management-------------------------------------
One, partition management
Management Tools Fdisk,sfdisk,cfdisk,parted,gdisk
Fdisk-l #显示磁盘分区列表
Fdisk/dev/sdb #磁盘/DEV/SDB Partition
Subcommands: Administrative functions
P:print, showing existing partitions;
N:new, creating
D:delete, deleting
W:write, write to disk and exit
Q:quit, discard the update and exit
M: Get Help
L: The partition ID of the list
T: adjust the partition ID
Sfdisk
Cfdisk #进入图形界面
Parted #2T以上用这个命令分区
Gdisk #GPT分区表用gdisk分区, MBR with Fdisk
Second, file System management
1, File System classification
Linux file systems: ext2, Ext3, EXT4 (more common in centos6), XFS, swap
Swap: Swap partition
Disc: iso9660
Windows:fat32, NTFS
Unix:ffs, UFS, JFS2
Network File system: NFS, CIFS
Clustered file system: GFS2 (Red Hat), OCFS2 (Oracle)
Whether the log function is supported:
journaled file system: ext3, Ext4, XFS, ...
Non-journaled file system: ext2, VFAT
User space management tools: MKFS.EXT4, MKFS.XFS, Mkfs.vfat
2, creating File system formatting
MKFS.EXT4/DEV/SDB1 #把/dev/sdb1 format ext4 file system
Mkfs-t EXT4/DEV/SDB1 # Ibid.
Mkswap disk partition #创建交换分区
Three, Mount Partition
Mount/dev/sdb1/newdisk #挂载磁盘/dev/sdb1 to/newdisk under this directory
Mount/dev/cdrom/mnt/cdrom #挂载光盘, or/dev/sro
Mount-o loop-t Iso9660/home/sunky/mydisk.iso/mnt/vcdrom #挂载ISO文件
Mount/home/sunky/mydisk.iso/mnt/vcdrom #挂载ISO文件
Mount-t cifs-o username= user name, password= password, vers=2.0//ip/share/mnt/share #挂载win共享文件夹
Mount–t Ntfs-3g/dev/sdb1/mnt/usb #挂载U盘, need to install NTFS-3G,
wget https://tuxera.com/opensource/ntfs-3g_ntfsprogs-2017.3.23.tgz
Installing GCC gcc-c++ to compile and install
Compile installation execution:./configure && make && make install
Umount/dev/cdrom #卸载光盘
UMOUNT/DEV/SDB1 #卸载USB
Umount/mnt/share # Uninstalling Windows share
Swapon disk partition #挂载交换分区
Swapoff disk partition #禁用交换分区
Set boot auto mount, edit/etc/fstab file to increase mount command.
ip/shared directory Name/mount location CIFS USERNAME=SOMEONE,PASSWORD=SOMEONE,VERS=2.0,RW 0 0 Mount Windows share
/dev/hdb1/home/new ext4 default 0 0 Mount HDD
/dev/cdrom/mnt/cdrom iso9660 default 0 0 Mount Optical Drive
Df-h #查看磁盘信息, partition size shown in G
Df-th #-T Display file system
Du-h Catalog #查看目录占用空间
LSBLK # list Partitions
LSBLK-F # File System listing
Adding a new hard drive does not require a restart
ls/sys/class/scsi_host/#查看主机总线号
echo "---" >/sys/class/scsi_host/host0/scan
echo "---" >/sys/class/scsi_host/host1/scan
echo "---" >/sys/class/scsi_host/host2/scan
--------------------------------------File Directory Management-------------------------------------
One, the directory processing command
LS: List directory
Ls-l #显示详细信息
Ls-al #显示隐藏的文件
ls/var/log/| Wc-l #统计文件夹的文件数
LS *.bak | Xargs rm-rf #删除所有. bak file
WC-LC file name #统计文件的行数和字节
LL: Same as Ls-l
CD: Switch directories
PWD: Displays the current directory
mkdir: Create a new directory
mkdir Catalog 1 Catalog 2 #创建多个目录
Mkdir-p/a/b/c #创建层次目录
RmDir: Delete an empty directory
Rmdir-p/a/b/c # Delete hierarchy empty directory
RmDir Catalog #删除空目录
CP: Copying Files or directories
Cp-r Dir1 Dir2 #复制目录
RM: Remove files or directories
RM-RF Catalog #危险慎用
Rm-f file #删除文件不提示
Rm-f! (File 1| file 2| file 3) #除文件123外删除其他文件
Rm-f ls | grep -v"aa"
#aa文件除外删除其他
MV: Moving files or directories
Mv-f the source file #强制移动 the destination file, overwriting
LN: Create a file or folder link
ln source location Destination location #硬链接
Ln-s Source location #软链接 The destination location, is the shortcut,
File: Determine the category of files
File File name
Vim: Text editing
G #光标移动最后一行
GG #改变移动第一行
n< Enter > #n = number of lines, cursor moves to nth row
#数字0 move the cursor to the beginning of the current line
$ #把光标移动到当前行的结尾
X #向后删除字符
X #向前删除字符
YY #复制一行
Nyy #复制n行, the copy cursor starts down a total of n rows
P #小写p, paste to the next line of the cursor
P #大写P, paste to the previous line of the cursor
DD #删除行
NDD #删除从光标开始向下共n行
U # Roll back to previous action
D1G #删除当前行至第一行
DG #删除当前行至最后一行
D0 #删除当前光标文本至行首
d$ #删除当前光标文本至行尾
: Set Nu #显示行号
: Set Nonu #取消行号
: q! #退出, I force
: wq! #保存
Second, the file Operation command
Cat: Display file contents
Tree: Directory Structure
Touch file name #创建空白文件
Touch-t 0712250000 file1 #修改一个文件或目录的时间戳-(YYMMDDHHMM)
MORE: One page, one page to look over
Less: One page at a glance
Head: View the first few lines of a file
Head-n 10 File #查看前10行
Tail: View the following lines
Tail-n 20 File #查看后20行
Tail-f/var/log/messages #事实查看日志输出
diff: File comparison
Diff-c file 1 File 2 #比较两个文件的差异
diff--brief file 1 file 2 #比较两个文件是否相同, not identical display differ
Dd-if the file name entered
The file name of the output
BS set Fast size
Count to copy the number of fast
Example: If we can use the DD command from the command from the/dev/zero device file to remove a size of 560MB data block
Dd-if=/dev/zero of=test.file conut=1 bs=560m
Package the CD-ROM file as an ISO file
Dd-if/dev/cdrom Of=cd.iso
DD If=/dev/cdrom Of=/home/sunky/mydisk.iso
Mkisofs-r-j-v Mydisk-o/home/sunky/mydisk.iso/home/sunky/mydir
Package directories and files into ISO files
Tar
CVF files or folders that are compressed after the file name needs to be compressed #压缩文件
XVF file name. Tar #解压文件
ZXVF file name. tar.gz # unzip. tar.gz file
JXVF file name. tar.bz2 #解压. tar.bz2 file needs to be installed Yum-y install bzip2
ZXVF filename.tar.z #解压. Tar.z
RF A.tar file name #向a the. tar file appended files
TF A.tar #显示压缩包里的文件
C Destination Directory #解压到指定目录
1,. Tar with TAR–XVF decompression
2,. GZ with gzip-d or gunzip decompression
3. tar.gz and . tgz Extract with Tar–xzf
4,. bz2 with bzip2-d or with BUNZIP2 decompression
5,. tar.bz2 with TAR–XJF decompression
6,. Z Extract with Uncompress
7,. Tar. Z Extract with Tar–xzf
8,. rar with Unrar e decompression
9,. zip with unzip decompression
Zip #需要安装
Zip a.zip *.jpg #将所有. jpg files compressed into a ZIP package
Unzip a.zap-d/data/a #解压
Find
Find/-name file1 from '/' to the root file system to search for files and directories
Find/-user User1 search for files and directories belonging to user ' User1 '
Find/home/user1-name *.bin in directory '/home/user1 ' search for files with '. Bin '
Find/usr/bin-type f-atime +100 Search execution files that have not been used in the last 100 days
Find/usr/bin-type f-mtime-10 search for files created or modified within 10 days
Find/-name *.rpm-exec chmod 755 ' {} '; Search for files ending with '. RPM ' and define their permissions
Find/-xdev-name *.rpm search for files ending with '. RPM ', ignoring removable devices such as optical drives, Czech disks, etc.
Grep
Grep-v "#" source files > Filtered files # Remove comment lines from the file
Grep-v "#"/etc/zabbix/zabbix_server.conf |grep-v "^$" #去掉注释和空行
Grep-e ' abc|123 ' #匹配多个搜索内容
C #统计行数 =wc-l
N #不换行
Sed
Sed-n ' 5,10p '/etc/passwd view the contents of the middle 5 to 10 rows
Sed-i ' s/selinux=enforcing/selinux=disabled/'/etc/selinux/config
Sed '/^ *$/d file deletes blank lines in the files.
Awk
Third, file permissions
Chown-r User name: User Group name folder #修改所有者
Chown User name: User group name file
Chmod-r 775 Folder #修改权限
chmod 711 File name
Setfacl-m u:ftp:rwx "directory or file" #设置ftp用户对这个目录或文件的权限
Getfacl "directory or file" #查看权限
Chattr +i Fiel1 #锁定文件
Chattr-i file1 #解锁文件
Lsattr #查看文件扩展属性.
--------------------------------------Users and user groups to manage-------------------------------------
Groupadd group_name Create a new user group
Groupadd-g 344 group_name Specifies the ID of the new workgroup
Groupdel group_name Delete a user group
Groupmod-n new_group_name old_group_name Renaming a user group
Useradd-c "Name Surname"-G admin-d/home/user1-s/bin/bash user1 create a user who belongs to the "admin" user group
Useradd User1 create a new user
Userdel-r User1 Delete a user ('-R ' exclude home directory)
Usermod-c "User FTP"-G system-d/ftp/user1-s/bin/nologin user1 to modify users ' properties
-C Plus Comment-G specify group-G specify additional group-d Specify user Directory-u specify id-s Specify use Shell (/bin/nologin not allow login)
passwd changing passwords
passwd User1 Modify a user's password (root only allowed)
--------------------------------------software safety loading and unloading management-------------------------------------
One, source code compilation installation (classic)
./configure--prefix=/usr/local Specify directory Installation
Make clean clears the files left before
Make compilation
Make install Installation
Two, yum installation
Yum install XXX--enablerepo=yyy # xxx= software name Yyy=yum warehouse designated warehouse download software Installation
Yum Update updates all software that is already installed
Yum Install FTP installation FTP
Yum Update FTP Update FTP
Yum Remove FTP Uninstall FTP
Yum Search FTP Searches FTP
Yum repolist all Show all warehouses
Yum repolist enable available warehouses
Yum Clean all cleanup local cache common
Yum Makecache Build Cache
Three, RPM installation
RPM-IVH Installation
RPM-UVH Upgrade
RPM-E Uninstall
Rpm-qa | grep FTP to see if FTP is installed
--------------------------------------Common configuration Files-------------------------------------
/etc/redhat-release System version
/etc/fstab automatically mount files on boot
/etc/inittab setting the Run level file
/etc/hostname Host Name
/etc/syscoonfig/network-scripts/ifcfg-enoxxxxxx NIC configuration file
/etc/yum.repos.d/centos-base.repo Yum Source
/etc/passwd Password file
/etc/shadow Password Encrypted File
/etc/group User Group
/proc/cpuinfo CPU information, grep-c ' processor '/proc/cpuinfo query several CPUs
/etc/resolv.conf Configuring DNS #nameserver IP ' format
/etc/sysconfig/network hostname config file # Hostname=localhost.localdomain change to the hostname you want
/etc/services Service Port
/etc/login.defs System Password Policy file
Ass_max_days #新建用户的密码最长使用天数
Pass_min_days 0 #新建用户的密码最短使用天数
Pass_warn_age 7 #新建用户的密码到期提前提醒天数
Pass_min_len 9 #最小密码长度9
/etc/locale.conf Language Settings
Lang=zh_cn.utf8//Chinese
Lc_messages=en_us.utf8//English
Linux Base command Set