Title

Linux系统的常用命令

centos7的目录结构

(windows是以分CDEF盘的形式,linux所有的都是文件,都在根目录下,万物皆文件)

bin  ---- 命令,二进制文件的存放目录
boot ----- 系统引导程序+系统的内核
dev   ---- 设备 硬盘,光驱
etc   ---- 存储系统或者服务的配置文件
home ---- 普通用的家目录,贫民窟
lib ----- 库文件存放目录
lib64 ---- 库文件的存放目录(64位系统)
media ---- linux识别的设备,比如u盘等,挂这个目录
mnt ----- 临时的挂载点目录
opt ----- 第三方的软件安装在整理
proc ----- 虚拟目录,显示内存中的信息(进场,内核的信息)
root ----- root的家目录 相当于皇宫
run ----- 放的启动的东西
sbin --- 超级命令,只用root用户才能用的命令
srv   ----- service的缩写,存放的是一些启动后需要的数据
sys ------ 虚拟目录,内存信息
tmp ----- 临时文件的存放位置
usr ---- 存放用户的程序
var ----- 存放经常变化的文件,比如日志等

文件系统常用命令

1 pwd 显示当前所在的路径
解释:pwd =  print working directory 显示当前所在的目录
[root@localhost run]# pwd
/run
[root@localhost network-scripts]# pwd
/etc/sysconfig/network-scripts
2 cd 切换目录结构
解释: cd ---> change directory 改变目录信息
##注意点 /目录 表示绝对路径   ; 目录 表示相对路径

#绝对路径的方式
[root@localhost run]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@localhost network-scripts]# cd /etc
[root@localhost etc]# cd /etc
[root@localhost etc]# cd /home
[root@localhost home]# pwd
/home

#相对路径的方式
[root@localhost home]# cd /etc
[root@localhost etc]# cd sysconfig/
[root@localhost sysconfig]# pwd
/etc/sysconfig

# 快速回到进入自己的家目录
[root@localhost sysconfig]# cd ~
[root@localhost ~]# pwd
/root
[root@localhost ~]# cd /root
[root@localhost ~]# pwd
/root
[root@localhost ~]#
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cd
[root@localhost ~]#


# 快速回到自己进过的目录
[root@localhost ~]# cd /etc/sysconfig/
[root@localhost sysconfig]# cd /bin
[root@localhost bin]# pwd
/bin
[root@localhost bin]# cd -
/etc/sysconfig
[root@localhost sysconfig]# pwd
/etc/sysconfig
[root@localhost sysconfig]#

#返回当前路径的上一级目录

[root@localhost lib]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@localhost network-scripts]# cd ../
[root@localhost sysconfig]# pwd
/etc/sysconfig
[root@localhost sysconfig]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cd ../../
[root@localhost etc]# pwd
/etc
[root@localhost etc]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cd ../../../../../../../../../
[root@localhost /]# pwd
/
3 mkdir创建目录信息
mkdir ---> make directory

[root@localhost /]# cd /oldboy
-bash: cd: /oldboy: No such file or directory
[root@localhost /]# mkdir /oldboy
[root@localhost /]# cd /oldboy/
[root@localhost oldboy]# pwd
/oldboy

#用-p参数创建多级目录
[root@localhost oldboy]# mkdir /oldboy/olddog/jason
mkdir: cannot create directory /oldboy/olddog/jason’: No such file or directory
[root@localhost oldboy]# mkdir /oldboy/olddog
[root@localhost oldboy]# mkdir /oldboy/olddog/jason
[root@localhost oldboy]# cd /oldboy/olddog/jason/
[root@localhost jason]# pwd
/oldboy/olddog/jason
[root@localhost jason]# cd /
[root@localhost /]# mkdir -p /oldboy/oldgirl/tank
[root@localhost /]# cd /oldboy/oldgirl/tank/
[root@localhost tank]# pwd
/oldboy/oldgirl/tank

#我们在创建目录的时候最好是用绝对路径
4 touch 创建文件
[root@localhost tank]# cd /oldboy/
[root@localhost oldboy]# pwd
/oldboy
[root@localhost oldboy]# touch oldboy.txt
[root@localhost oldboy]# ls
oldboy.txt  olddog  oldgirl
[root@localhost oldboy]# touch /oldboy/olddog/jj
[root@localhost oldboy]# ls /oldboy/olddog/
jason  jj
#在linux里面不会通过后缀名来区分文件的类型,但是我们约定,你什么样的文件,就用什么后缀名,免得搞不清楚
5 ls 检查文件或者文件目录是否存在,并列出目录底下的文件
ls ----> list

[root@localhost /]# cd oldboy/
[root@localhost oldboy]# ls
oldboy.txt  olddog  oldgirl
[root@localhost oldboy]# ls ol
ls: cannot access ol: No such file or directory
[root@localhost oldboy]# ls =l
ls: cannot access =l: No such file or directory

[root@localhost oldboy]# ls -l
total 0
-rw-r--r--. 1 root root  0 Mar 24 18:09 oldboy.txt
drwxr-xr-x. 3 root root 29 Mar 24 18:10 olddog
drwxr-xr-x. 3 root root 18 Mar 24 18:06 oldgirl

[root@localhost oldboy]# ls -ltr
total 0
drwxr-xr-x. 3 root root 18 Mar 24 18:06 oldgirl
-rw-r--r--. 1 root root  0 Mar 24 18:09 oldboy.txt
drwxr-xr-x. 3 root root 29 Mar 24 18:10 olddog

[root@localhost oldboy]# ls -lt
total 0
drwxr-xr-x. 3 root root 29 Mar 24 18:10 olddog
-rw-r--r--. 1 root root  0 Mar 24 18:09 oldboy.txt
drwxr-xr-x. 3 root root 18 Mar 24 18:06 oldgirl

# ls -l 默认是创建时间最新到最老排序(不确定,是按时间还是按照文件名排序)
# ls -lt 创建时间最新到最老排序
# ls -ltr 创建时间最老到最新排序
6 cat 查看文件信息的命令
# cat 是查看文件信息  vi  是在该文件内书写内容
[root@localhost oldboy]# vi oldboy.txt  
[root@localhost oldboy]# cat /oldboy/oldboy.txt
123
[root@localhost oldboy]# cat oldgirl.txt
456
#查看多个文件的文件信息
[root@localhost oldboy]# cat oldboy.txt oldgirl.txt
123
456

# 将文件中的内容读取出来,放入到另一个文件中
[root@localhost oldboy]# cat oldboy.txt oldgirl.txt > jason.txt
[root@localhost oldboy]# cat jason.txt
123
456
7 echo 将信息进行输出
# 直接输出信息
[root@localhost oldboy]# echo "hello world"
hello world

# 将echo的内容写入到文件 ,> 是覆盖写入,>> 是追加写入
[root@localhost oldboy]# echo "hello world" > lxx.txt
[root@localhost oldboy]# ls
jason.txt  lxx.txt  oldboy.txt  olddog  oldgirl  oldgirl.txt
[root@localhost oldboy]# cat lxx.txt
hello world
[root@localhost oldboy]# echo "hello world" > lxx.txt
[root@localhost oldboy]# cat lxx.txt
hello world
[root@localhost oldboy]# echo "hello world" >> lxx.txt
[root@localhost oldboy]# cat lxx.txt
hello world
hello world
8 cp复制
# cp  --->cope
语法格式: cp 参数(可选) 要复制的信息   复制到什么位置

# 复制文件。在复制文件的时候,要复制的文件不要加/,比如下面复制的就是hosts这个文件的内容,一般是只能复制目录的时候加/
[root@localhost oldboy]# cp /etc/hosts /oldboy/
[root@localhost oldboy]# ls
hosts  jason.txt  lxx.txt  oldboy.txt  olddog  oldgirl  oldgirl.txt
[root@localhost oldboy]# cat hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@localhost oldboy]# cp /etc/hosts /oldboy/
# 表示是否覆盖,手动填上y即可
cp: overwrite /oldboy/hosts’? y

# 复制文件夹,直接复制不行,需要加-r,并且文件夹需要前后都加/
[root@localhost sysconfig]# cp /etc/sysconfig/ /oldboy/oldgirl
cp: omitting directory /etc/sysconfig/
[root@localhost sysconfig]# cp -r /etc/sysconfig/ /oldboy/oldgirl
[root@localhost sysconfig]# cd /oldboy/oldgirl
[root@localhost oldgirl]# ls
sysconfig  tank
[root@localhost oldgirl]# cd /oldboy/oldgirl/sysconfig/
[root@localhost sysconfig]# pwd
/oldboy/oldgirl/sysconfig

cp :的参数
-r 进行递归复制
-p 拷贝是时候属性保存不变
-d 和链接相关的文件
-a == -drp

# 利用cp做备份
[root@localhost oldboy]# cat jason.txt
123
456
[root@localhost oldboy]# cp jason.txt jason.txt.bak   # 备份文件一般在文件尾缀.bak
[root@localhost oldboy]# ls
hosts  jason.txt  jason.txt.bak  lxx.txt  oldboy.txt  olddog  oldgirl  oldgirl.txt
[root@localhost oldboy]# rm -rf jason.txt   # rm -rf xxx 删除某个文件
[root@localhost oldboy]# ls
hosts  jason.txt.bak  lxx.txt  oldboy.txt  olddog  oldgirl  oldgirl.txt
[root@localhost oldboy]# cp jason.txt.bak jason.txt
[root@localhost oldboy]# ls
hosts  jason.txt  jason.txt.bak  lxx.txt  oldboy.txt  olddog  oldgirl  oldgirl.txt
[root@localhost oldboy]# cat jason.txt
123
456

# 如果cp的时候,多个文件,会出现多次确定,如何避免
[root@localhost oldboy]# cp -r /etc/sysconfig/ /oldboy/oldgirl
cp: overwrite /oldboy/oldgirl/sysconfig/ip6tables-config’? y
cp: overwrite /oldboy/oldgirl/sysconfig/iptables-config’? y
cp: overwrite /oldboy/oldgirl/sysconfig/cbq/avpkt’? ^C

#解决办法,在cp前面加个\
[root@localhost oldboy]# \cp -r /etc/sysconfig/ /oldboy/oldgirl
9 mv 剪切命名
mv --move
对文件或者文件夹进行剪切(移动)
语法格式: mv 要移动的文件或者文件夹  移动要什么位置
#在根目录创建test文件夹,然后创建heihei.txt
[root@localhost oldboy]# mkdir /test
[root@localhost oldboy]# cd /test
[root@localhost test]# touch heihei.txt

# 将 /test/heihei.txt文件 剪切(移动)到/oldboy/shanghai/的文件夹,
[root@localhost test]# mv /test/heihei.txt /oldboy/shanghai/
mv: cannot move /test/heihei.txt’ to /oldboy/shanghai/’: Not a directory

#创建/oldboy/shanghai文件夹

[root@localhost test]# mkdir /oldboy/shanghai
[root@localhost test]# mv /test/heihei.txt /oldboy/shanghai/
[root@localhost test]# cd /oldboy/shanghai
[root@localhost shanghai]# ls
heihei.txt
#原来的/test/heihei.txt文件消失
[root@localhost shanghai]# cd /test
[root@localhost test]# ls


# 将 /test/heihei.txt文件 剪切(移动)到/oldboy/shanghai,如果不加/,表示将heihei.txt文件内容写入
shanghai,文件,并将名字改成shanghai

# 在linux系统没有重命名这个东西,我们可以同mv 命令实现
[root@localhost oldboy]# ls
hosts  jason.txt  jason.txt.bak  lxx.txt  oldboy.txt  olddog  oldgirl  oldgirl.txt  shanghai
[root@localhost oldboy]# mv lxx.txt lxxsb.txt   # 可以将lxx改为lxxsb
[root@localhost oldboy]# ls
hosts  jason.txt  jason.txt.bak  lxxsb.txt  oldboy.txt  olddog  oldgirl  oldgirl.txt  shanghai
10 rm 命令(删除)
rm --->remove 
语法:rm 参数 要删除的数据信息

#删除文件
[root@localhost ~]# cd /oldboy/
[root@localhost oldboy]# ls
hosts jason.txt jason.txt.bak lxxsb.txt oldboy.txt olddog oldgirl oldgirl.txt shanghai
[root@localhost oldboy]# rm jason.txt.bak
rm: remove regular file ‘jason.txt.bak’? y
[root@localhost oldboy]# ls
hosts jason.txt lxxsb.txt oldboy.txt olddog oldgirl oldgirl.txt shanghai
# 删除文件夹(rm -r xx 会询问是否删除)
[root@localhost oldboy]# rm shanghai
rm: cannot remove ‘shanghai’: Is a directory
[root@localhost oldboy]# rm -r shanghai
rm: descend into directory ‘shanghai’? y
rm: remove regular empty file ‘shanghai/heihei.txt’? y
rm: remove directory ‘shanghai’? y

#强行删除,不询问(rm -f xx文件 | rm -rf xx文件夹)
[root@localhost oldboy]# ls
hosts jason.txt lxxsb.txt oldboy.txt olddog oldgirl oldgirl.txt
[root@localhost oldboy]# rm -f oldboy.txt
[root@localhost oldboy]# rm -rf olddog
[root@localhost oldboy]# ls
hosts jason.txt lxxsb.txt oldgirl oldgirl.txt




注意:

#centos7这个命令会保护
rm -rf /

# 不受保护,虚拟机会炸
rm -rf /*
10vim编辑器

#安装之前先切换镜像源(阿里镜像官网【https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.3e221b11AsEc0q】下面这是centos7的版本,直接复制到xshell中即可

    curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo



# 安装命令(-y表示同意安装,免去询问这一步)
#命令:yum -y install vim 或者 yum install vim -y

补充:若发现安装过程不顺利,或者出现vim已经开始执行,等待关毕,尝试下面这个方法关闭
# rm -f /var/run/yum.pid

# vim 是编辑器,他有三种状态
1 正常模式
vim 文件 进入后就vim的正常模式,从正常如何进入编辑模式,输入 i,o,a,I,O,A,R,都可以,但是
我们只要记住一个i,因为方便记忆。

正常模式底下的命令(即非编辑下才能使用):光标选择某一行直接按命令即可执行
拷贝: yy
粘贴:p

拷贝当前行向下2行,并粘贴
拷贝2行:2yy
粘贴:p

删当前行:
删除:dd
删除当前的下两行:
删除:2dd

光标移动到最后一行:G
光标移到首行:gg
光标移到第二行:2gg

撤回:u

   :set number 显示行号

   :set nonumber 隐藏行号

   /apache 在文档中查找apache 按n跳到下一个,shift+n上一个

   h(左移一个字符←)、j(下一行↓)、k(上一行↑)、l(右移一个字符→)



2 插入模式
进入编辑模式,就可以直接输入内容。
3 命令模式
1 查找内容:
shift + :/关键字
2 取消高亮:
shift + :nohl
3 显示行号:
shift + :set nu
4 取消行号
shift + :set nonu
5 没有修改情况下退出
shift + :q
6 如果修改了,但我们不想保存,
shift + :q!
7 如果修改,并且想保存,
shift + :wq

# 如果非正常退出或其他问题发现vim 不能编辑这个文件
# 我在这个文件所在目录下执行: ls -a
# 你会发现有一个 .文件名.swp的隐藏文件
#我们执行删除命令将其删除:rm -rf .文件名.swp即可

 

补充linux的基本命令

Linux命令补充
网络相关常见命令
  • hostname hostname 没有选项,显示主机名字 hostname –f 显示完整的主机名和域名 hostname –i 显示当前机器的 ip 地址

[root@localhost ~]# hostname
localhost.localdomain
[root@localhost ~]# hostname -f
localhost
[root@localhost ~]# hostname -i
::1 127.0.0.1
[root@localhost ~]#

 

  • ping   ping 可以将数据包发向用户指定地址。当包被接收,目标机器发送返回数据包 windows中的ping,只执行4次,linux中一直ping下去

[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (36.152.44.95) 56(84) bytes of data.
64 bytes from 36.152.44.95 (36.152.44.95): icmp_seq=1 ttl=128 time=16.8 ms
64 bytes from 36.152.44.95 (36.152.44.95): icmp_seq=2 ttl=128 time=15.8 ms
64 bytes from 36.152.44.95 (36.152.44.95): icmp_seq=3 ttl=128 time=16.3 ms
64 bytes from 36.152.44.95 (36.152.44.95): icmp_seq=4 ttl=128 time=16.8 ms
64 bytes from 36.152.44.95 (36.152.44.95): icmp_seq=5 ttl=128 time=16.2 ms
^C


ctrl+c退出

查看IP信息

  • ip addr(6和7版本都能使用)

[root@localhost ~]# ip addr
# 回环地址
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
   link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
   inet 127.0.0.1/8 scope host lo
      valid_lft forever preferred_lft forever
   inet6 ::1/128 scope host
      valid_lft forever preferred_lft forever
   
# 自己配的ip信息    
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
   link/ether 00:0c:29:88:a6:e7 brd ff:ff:ff:ff:ff:ff
   inet 10.0.0.200/24 brd 10.0.0.255 scope global noprefixroute ens33
      valid_lft forever preferred_lft forever
   inet6 fe80::7dd7:e410:5a7a:cd41/64 scope link noprefixroute
      valid_lft forever preferred_lft forever
  • ifconfig(这个只能在6及以下版本中使用)

清屏的命令

  • clear 或者 crtl+l

查看运行的程序和端口号(比较详细)

  • netstat

  • netstat -natup

注意:若发现无法使用这些命令,可能是未安装

安装方法:yum -y install net-tools

[root@localhost ~]# netstat
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State  
[root@localhost ~]# netstat -natup
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name(进程号/进程名)    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1525/master        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1375/sshd          
tcp        0      0 10.0.0.200:22           10.0.0.1:3275           ESTABLISHED 1975/sshd: root@pts
tcp        0      0 10.0.0.200:36290        112.28.217.191:80       TIME_WAIT   -                  
tcp        0      0 10.0.0.200:32816        112.30.217.238:80       TIME_WAIT   -                  
tcp        0      0 10.0.0.200:36288        112.28.217.191:80       TIME_WAIT   -                  
tcp6       0      0 ::1:25                 :::*                    LISTEN      1525/master        
tcp6       0      0 :::22                   :::*                    LISTEN      1375/sshd          
[root@localhost ~]#

查看服务器上运行的进程(可以通过过滤来查询进程是否正常执行)

  • ps

  • ps -aux 是列出当前服务器上所有的进程

    | : 管道符 , 将左边执行的命令结果传给右边进行操作 grep : 用来进行筛选过滤 ps -aux | grep mysql : 查看mysql所有的相关进程

[root@localhost ~]# ps
  PID TTY          TIME CMD
 1979 pts/0    00:00:00 bash
 2025 pts/0    00:00:00 ps
       
[root@localhost ~]# ps -aux
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          1  0.0  0.6 128220  6900 ?        Ss   16:58   0:04 /usr/lib/systemd/systemd --switched-root
root          2  0.0  0.0      0     0 ?        S    16:58   0:00 [kthreadd]
root          4  0.0  0.0      0     0 ?        S<   16:58   0:00 [kworker/0:0H]
root          5  0.0  0.0      0     0 ?        S    16:58   0:00 [kworker/u256:0]
root          6  0.0  0.0      0     0 ?        S    16:58   0:01 [ksoftirqd/0]
root          7  0.0  0.0      0     0 ?        S    16:58   0:00 [migration/0]
root          8  0.0  0.0      0     0 ?        S    16:58   0:00 [rcu_bh]
root          9  0.0  0.0      0     0 ?        R    16:58   0:01 [rcu_sched]
root         10  0.0  0.0      0     0 ?        S<   16:58   0:00 [lru-add-drain]
root         11  0.0  0.0      0     0 ?        S    16:58   0:01 [watchdog/0]
root         13  0.0  0.0      0     0 ?        S    16:58   0:00 [kdevtmpfs]
root         14  0.0  0.0      0     0 ?        S<   16:58   0:00 [netns]
root         15  0.0  0.0      0     0 ?        S    16:58   0:00 [khungtaskd]
root         16  0.0  0.0      0     0 ?        S<   16:58   0:00 [writeback]
root         17  0.0  0.0      0     0 ?        S<   16:58   0:00 [kintegrityd]
root         18  0.0  0.0      0     0 ?        S<   16:58   0:00 [bioset]
root         19  0.0  0.0      0     0 ?        S<   16:58   0:00 [bioset]
root         20  0.0  0.0      0     0 ?        S<   16:58   0:00 [bioset]
root         21  0.0  0.0      0     0 ?        S<   16:58   0:00 [kblockd]
root         22  0.0  0.0      0     0 ?        S<   16:58   0:00 [md]
root         23  0.0  0.0      0     0 ?        S<   16:58   0:00 [edac-poller]
root         24  0.0  0.0      0     0 ?        S<   16:58   0:00 [watchdogd]
root         30  0.0  0.0      0     0 ?        S    16:58   0:00 [kswapd0]
root         31  0.0  0.0      0     0 ?        SN   16:58   0:00 [ksmd]
root         32  0.0  0.0      0     0 ?        SN   16:58   0:00 [khugepaged]
root         33  0.0  0.0      0     0 ?        S<   16:58   0:00 [crypto]
root         41  0.0  0.0      0     0 ?        S<   16:58   0:00 [kthrotld]
root         43  0.0  0.0      0     0 ?        S<   16:58   0:00 [kmpath_rdacd]
root         44  0.0  0.0      0     0 ?        S<   16:58   0:00 [kaluad]
root         45  0.0  0.0      0     0 ?        S<   16:58   0:00 [kpsmoused]
root         47  0.0  0.0      0     0 ?        S<   16:58   0:00 [ipv6_addrconf]
root         60  0.0  0.0      0     0 ?        S<   16:58   0:00 [deferwq]
root         95  0.0  0.0      0     0 ?        S    16:58   0:00 [kauditd]
root        274  0.0  0.0      0     0 ?        S<   16:58   0:00 [nfit]
root        275  0.0  0.0      0     0 ?        S<   16:58   0:00 [mpt_poll_0]
root        276  0.0  0.0      0     0 ?        S<   16:58   0:00 [mpt/0]
root        277  0.0  0.0      0     0 ?        S    16:58   0:00 [scsi_eh_0]
root        284  0.0  0.0      0     0 ?        S<   16:58   0:00 [scsi_tmf_0]
root        291  0.0  0.0      0     0 ?        S<   16:58   0:00 [ata_sff]
root        299  0.0  0.0      0     0 ?        S    16:58   0:00 [scsi_eh_1]
root        300  0.0  0.0      0     0 ?        S<   16:58   0:00 [scsi_tmf_1]
root        301  0.0  0.0      0     0 ?        S    16:58   0:00 [scsi_eh_2]
root        302  0.0  0.0      0     0 ?        S<   16:58   0:00 [scsi_tmf_2]
root        315  0.0  0.0      0     0 ?        S    16:58   0:00 [irq/16-vmwgfx]
root        317  0.0  0.0      0     0 ?        S<   16:58   0:00 [ttm_swap]
root        385  0.0  0.0      0     0 ?        S<   16:58   0:00 [kdmflush]
root        386  0.0  0.0      0     0 ?        S<   16:58   0:00 [bioset]
root        396  0.0  0.0      0     0 ?        S<   16:58   0:00 [kdmflush]
root        397  0.0  0.0      0     0 ?        S<   16:58   0:00 [bioset]
root        409  0.0  0.0      0     0 ?        S<   16:58   0:00 [bioset]
root        410  0.0  0.0      0     0 ?        S<   16:58   0:00 [xfsalloc]
root        411  0.0  0.0      0     0 ?        S<   16:58   0:00 [xfs_mru_cache]
root        412  0.0  0.0      0     0 ?        S<   16:58   0:00 [xfs-buf/dm-0]
root        413  0.0  0.0      0     0 ?        S<   16:58   0:00 [xfs-data/dm-0]
root        414  0.0  0.0      0     0 ?        S<   16:58   0:00 [xfs-conv/dm-0]
root        415  0.0  0.0      0     0 ?        S<   16:58   0:00 [xfs-cil/dm-0]
root        416  0.0  0.0      0     0 ?        S<   16:58   0:00 [xfs-reclaim/dm-]
root        417  0.0  0.0      0     0 ?        S<   16:58   0:00 [xfs-log/dm-0]
root        418  0.0  0.0      0     0 ?        S<   16:58   0:00 [xfs-eofblocks/d]
root        419  0.0  0.0      0     0 ?        S    16:58   0:00 [xfsaild/dm-0]
root        420  0.0  0.0      0     0 ?        S<   16:58   0:00 [kworker/0:1H]
root        499  0.0  0.2  37112  2900 ?        Ss   16:58   0:00 /usr/lib/systemd/systemd-journald
root        516  0.0  0.4 127316  4060 ?        Ss   16:58   0:00 /usr/sbin/lvmetad -f
root        534  0.0  0.5  48572  5768 ?        Ss   16:58   0:00 /usr/lib/systemd/systemd-udevd
root        704  0.0  0.0      0     0 ?        S<   16:58   0:00 [xfs-buf/sda1]
root        706  0.0  0.0      0     0 ?        S<   16:58   0:00 [xfs-data/sda1]
root        708  0.0  0.0      0     0 ?        S<   16:58   0:00 [xfs-conv/sda1]
root        711  0.0  0.0      0     0 ?        S<   16:58   0:00 [xfs-cil/sda1]
root        713  0.0  0.0      0     0 ?        S<   16:58   0:00 [xfs-reclaim/sda]
root        716  0.0  0.0      0     0 ?        S<   16:58   0:00 [xfs-log/sda1]
root        718  0.0  0.0      0     0 ?        S<   16:58   0:00 [xfs-eofblocks/s]
root        720  0.0  0.0      0     0 ?        S    16:58   0:00 [xfsaild/sda1]
root        861  0.0  0.0  55528   888 ?        S<sl 16:58   0:00 /sbin/auditd
polkitd     941  0.0  1.4 612244 14152 ?        Ssl  16:58   0:00 /usr/lib/polkit-1/polkitd --no-debug
root        944  0.0  0.5 228248  5772 ?        Ss   16:58   0:00 /usr/sbin/abrtd -d -s
root        945  0.0  0.4 225756  4796 ?        Ss   16:58   0:00 /usr/bin/abrt-watch-log -F BUG: WARNING:
dbus        946  0.0  0.2  66472  2560 ?        Ssl  16:58   0:00 /usr/bin/dbus-daemon --system --address=s
root        955  0.0  0.9 699632  9044 ?        Ssl  16:58   0:01 /usr/sbin/NetworkManager --no-daemon
root        958  0.0  0.6  99684  6068 ?        Ss   16:58   0:00 /usr/bin/VGAuthService -s
root        960  0.1  0.6 305180  6376 ?        Ssl  16:58   0:26 /usr/bin/vmtoolsd
root        963  0.0  0.1  26436  1796 ?        Ss   16:58   0:00 /usr/lib/systemd/systemd-logind
root        969  0.0  0.1 126288  1672 ?        Ss   16:58   0:00 /usr/sbin/crond -n
root        988  0.0  0.2  96572  2444 ?        Ss   16:58   0:00 login -- root
root       1373  0.0  0.3 214452  3940 ?        Ssl  16:58   0:02 /usr/sbin/rsyslogd -n
root       1374  0.0  1.9 574204 19420 ?        Ssl  16:58   0:04 /usr/bin/python2 -Es /usr/sbin/tuned -l -
root       1375  0.0  0.4 112920  4312 ?        Ss   16:58   0:00 /usr/sbin/sshd -D
root       1525  0.0  0.2  89700  2180 ?        Ss   16:58   0:00 /usr/libexec/postfix/master -w
postfix    1530  0.0  0.4  89872  4076 ?        S    16:58   0:00 qmgr -l -t unix -u
postfix    1788  0.0  0.4  89804  4048 ?        S    20:18   0:00 pickup -l -t unix -u
root       1796  0.0  0.0      0     0 ?        S    20:58   0:01 [kworker/0:1]
root       1829  0.0  0.0      0     0 ?        S    21:27   0:00 [kworker/0:2]
root       1952  0.0  0.0      0     0 ?        S    21:29   0:00 [kworker/u256:1]
root       1958  0.0  0.1 115444  1988 tty1     Ss+  21:29   0:00 -bash
root       1975  0.0  0.5 158924  5608 ?        Ss   21:29   0:00 sshd: root@pts/0
root       1979  0.0  0.2 115448  2040 pts/0    Ss   21:30   0:00 -bash
root       2021  0.0  0.0      0     0 ?        R    21:33   0:00 [kworker/0:0]
root       2023  0.0  0.0      0     0 ?        S    21:34   0:00 [kworker/0:3]
root       2026  0.0  0.1 155372  1848 pts/0    R+   21:38   0:00 ps -aux
       
[root@localhost ~]# ps -aux |grep mysql
root       2029  0.0  0.0 112712   960 pts/0    R+   21:40   0:00 grep  --color=auto mysql

结束进程

  • kill -PID (注:pid指的就是进程号)

    kill -1525 (注:1525就是,某个进程的id)

  • kill -9 服务的进程号 (注:-9:强制杀死)

  • pkill 服务名 : 杀掉服务进程 pkill redis (注:可以不用找进程号)

查看系统服务

centos6的系统:

service命令能够将目录“/etc/init.d/”中有关网络服务或系统服务脚本程序以一种统一的格式执行,格式为:“service 脚本程序 选项”,常用选项有:status、stop、start、restart。service命令使用举例如下:

  • service 服务名 status : 查看某一个服务的状态

    • service sshd status :查看sshd服务的状态

  • service 服务名 stop : 关闭某一个服务

    • service sshd stop : 关闭sshd服务

  • service 服务名 start : 启动一个服务

    • service sshd start: 启动sshd的服务

  • service 服务名 restart : 重新启动一个服务

    • service sshd restart: 重新启动sshd的服务

   

centos 7的系统:

  • systemctl status 服务名: 查看某一个服务的状态

    • systemctl status sshd :查看sshd服务的状态

  • systemctl start 服务名: 启动一个服务

    • systemctl start sshd: 启动ssh的服务

  • systemctl restart 服务名 : 重新启动一个服务

    • systemctl restart sshd: 重新启动ssh的服务

 

动态展示服务器的进程使用信息(包括cpu等信息)

  • top

朝一个url发请求并解析获取页面信息

  • wget

安装: yum install wget -y

[root@localhost ~]# wget www.baidu.com
--2020-03-25 22:41:15--  http://www.baidu.com/
Resolving www.baidu.com (www.baidu.com)... 36.152.44.95, 36.152.44.96
Connecting to www.baidu.com (www.baidu.com)|36.152.44.95|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2381 (2.3K) [text/html]
Saving to: ‘index.html’

100%[=============================================================>] 2,381       --.-K/s   in 0s      

2020-03-25 22:41:15 (132 MB/s) - ‘index.html’ saved [2381/2381]

[root@localhost ~]# vim index.html

从宿主机上传文件到虚拟机

  • rz

从虚拟机上传文件到宿主机

  • sz

安装方法:yum install -y lrzsz

 

查看磁盘使用情况

  • df

[root@localhost ~]# df
Filesystem              1K-blocks    Used Available Use% Mounted on
devtmpfs                   485856       0    485856   0% /dev
tmpfs                      497872       0    497872   0% /dev/shm
tmpfs                      497872    7800    490072   2% /run
tmpfs                      497872       0    497872   0% /sys/fs/cgroup
/dev/mapper/centos-root  17811456 1822308  15989148  11% /
/dev/sda1                 1038336  139496    898840  14% /boot
tmpfs                       99576       0     99576   0% /run/user/0
  • df -h (注:h将字节做了格式化)

[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 475M     0  475M   0% /dev
tmpfs                    487M     0  487M   0% /dev/shm
tmpfs                    487M  7.7M  479M   2% /run
tmpfs                    487M     0  487M   0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  1.8G   16G  11% /
/dev/sda1               1014M  137M  878M  14% /boot
tmpfs                     98M     0   98M   0% /run/user/0
  • man df (注:查看df的参数)

DF(1)                                                       User Commands                                                      DF(1)

NAME
      df - report file system disk space usage

SYNOPSIS
      df [OPTION]... [FILE]...

DESCRIPTION
      This manual page documents the GNU version of df.  df displays the amount of disk space available on the file system contain‐
      ing each file name argument.  If no file name is given, the space available on all currently mounted file systems  is  shown.
      Disk  space  is shown in 1K blocks by default, unless the environment variable POSIXLY_CORRECT is set, in which case 512-byte
      blocks are used.

      If an argument is the absolute file name of a disk device node containing a mounted file system, df shows the space available
      on  that  file  system  rather  than on the file system containing the device node.  This version of df cannot show the space
      available on unmounted file systems, because on most kinds of systems doing so requires very nonportable  intimate  knowledge
      of file system structures.

OPTIONS
      Show information about the file system on which each FILE resides, or all file systems by default.

      Mandatory arguments to long options are mandatory for short options too.

      -a, --all
             include pseudo, duplicate, inaccessible file systems

      -B, --block-size=SIZE
             scale sizes by SIZE before printing them; e.g., '-BM' prints sizes in units of 1,048,576 bytes; see SIZE format below

      --direct
             show statistics for a file instead of mount point

      --total
             produce a grand total

      -h, --human-readable
             print sizes in human readable format (e.g., 1K 234M 2G)

      -H, --si
             likewise, but use powers of 1000 not 1024

      -i, --inodes
             list inode information instead of block usage

      -k     like --block-size=1K

      -l, --local
             limit listing to local file systems

      --no-sync
             do not invoke sync before getting usage info (default)

      --output[=FIELD_LIST]

查看cpu的具体情况

  • cat/proc/cpuinfo

[root@localhost ~]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 61
model name : Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz
stepping : 4
microcode : 0x2b
cpu MHz : 2200.001
cache size : 3072 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 20
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt arat spec_ctrl intel_stibp flush_l1d arch_capabilities
bogomips : 4400.00
clflush size : 64
cache_alignment : 64
address sizes : 43 bits physical, 48 bits virtual
power management:

查看文件树状结构

安装方法:yum install tree -y

  • tree

[root@localhost ~]# tree
.
├── anaconda-ks.cfg
├── day3.md
├── ifcfg-ens33
└── index.html

0 directories, 4 files

记录历史命令, (一般记录1000条左右)

  • history

执行历史记录, !命令行号

  • i123 (注:123表示第123条命令)

 

 

获取主版信息

  • dmidecode -t1

[root@localhost ~]# dmidecode -t1
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 2.7 present.

Handle 0x0001, DMI type 1, 27 bytes
System Information
Manufacturer: VMware, Inc.
Product Name: VMware Virtual Platform
Version: None
Serial Number: VMware-56 4d 4e 05 c1 17 0e 44-4c 11 3d 9b 14 88 a6 e7
UUID: 054e4d56-17c1-440e-4c11-3d9b1488a6e7
Wake-up Type: Power Switch
SKU Number: Not Specified
Family: Not Specified

 

 

 

 

 

 

 

posted @ 2020-03-24 23:07  Mr江  阅读(386)  评论(0编辑  收藏  举报