linux篇-系统指令+用户操作
测试菜鸟 -一、管道符(|)
说明:经常和grep配合使用
语法: 数据源 | grep "筛选的条件"
eg:
[root@192 ~]# cat anaconda-ks.cfg | grep "ty$"
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
二、查看指令位置(which)eg:
[root@192 ~]# which ls man cp
alias cp='cp -i'
/usr/bin/cp
alias ls='ls --color=auto'
/usr/bin/ls
/usr/bin/man
三、系统指令1、关机shutdown -h
说明:现在关闭:shutdown -h now
n分钟后关闭:shutdown -h +n
具体时间关闭:shutdown -h 12:30
init 02、重启rebootinit 63、运行程序信息(进程的查看)ps -axu (静态展现)[root@192 ~]# ps -aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.3 125500 3888 ? Ss 08:22 0:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root 2 0.0 0.0 0 0 ? S 08:22 0:00 [kthreadd]
root 4 0.0 0.0 0 0 ? S< 08:22 0:00 [kworker/0:0H]
root 5 0.0 0.0 0 0 ? S 08:22 0:00 [kworker/u256:0]
root 6 0.0 0.0 0 0 ? R 08:22 0:11 [ksoftirqd/0]
...
top (动态展现)
4、强制关闭程序kill -9 程序编号(pid)eg: kill -9 3306 关闭程序mysql
5、查看端口netstat -apunt
说明:查看所有运行程序的端口
可以确认程序是否在运行
[root@192 ~]# netstat -apunt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 906/sshd
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 910/php-fpm: master
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 939/nginx: master p
tcp 0 0 192.168.187.129:22 192.168.187.1:56412 ESTABLISHED 1192/sshd: root@not
tcp 0 36 192.168.187.129:22 192.168.187.1:50431 ESTABLISHED 46828/sshd: root@pt
tcp6 0 0 :::22 :::* LISTEN 906/sshd
tcp6 0 0 :::3306 :::* LISTEN 950/mysqld
udp 0 0 0.0.0.0:68 0.0.0.0:* 703/dhclient
udp 0 0 127.0.0.1:323 0.0.0.0:* 657/chronyd
udp6 0 0 ::1:323 :::* 657/chronyd
lsof -i:端口号
说明:前提知道程序的端口
确认该程序是否运行
eg: 查看ssh,端口号为22的程序是否在运行
[root@192 ~]# lsof -i:22
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 906 root 3u IPv4 20352 0t0 TCP *:ssh (LISTEN)
sshd 906 root 4u IPv6 20361 0t0 TCP *:ssh (LISTEN)
sshd 1192 root 3u IPv4 21052 0t0 TCP 192.168.187.129:ssh->192.168.187.1:56412 (ESTABLISHED)
sshd 46828 root 3u IPv4 3100840 0t0 TCP 192.168.187.129:ssh->192.168.187.1:50431 (ESTABLISHED)
有内容,就代表在运行,无内容,就没有在运行
6、查看日志head 文件
拓展:默认查看前10行日志
要想查询多行,用 head -行数 文件
eg:查询var 下messages文件的前4行
[root@192 ~]# head -4 /var/log/messages
Mar 13 09:19:01 localhost rsyslogd: [origin software="rsyslogd" swVersion="8.24.0-55.el7" x-pid="910" x-info="http://www.rsyslog.com"] rsyslogd was HUPed
Mar 13 09:23:07 localhost dhclient[698]: DHCPREQUEST on ens33 to 192.168.187.254 port 67 (xid=0x15008e1)
Mar 13 09:23:07 localhost dhclient[698]: DHCPACK from 192.168.187.254 (xid=0x15008e1)
Mar 13 09:23:07 localhost NetworkManager[656]: <info> [1647134587.0144] dhcp4 (ens33): address 192.168.187.129
tail -f 文件 (持续监控文件变化)eg: 模拟监控 1.txt 的变化
监控前的变化
改变1.txt 文件的内容
监控后的变化
可读(r) 可写(w) 可执行(x) 没有(-)
数字表示法: r:4 w:2 x:1 -:0
文件和目录权限构成修改用户权限(chmod)数字表示法:
chmod 数字 文件/目录
eg: chmod 561 1.txt
解析:5=4+1(4:r 1:x)
6=4+2(4:r 2:w)
1=1(1:x)
表示的是 该文件拥有者有可读可执行的权限,分组权限为可读可写,其他用户权限是可执行
对用户的操作创建用户:useradd 用户名密码:passwd 用户密码切换用户:su 用户名退出用户:exit 特别申明:本文内容来源网络,版权归原作者所有,如有侵权请立即与我们联系(cy198701067573@163.com),我们将及时处理。
下一篇: Xshell用root用户连接Linux