2021-10-26


一、Linux命令和windows区别?

1、Linux命令全部严格区分大小写;而windows命令大小写都识别。

2、Linux所有的文件都是没有扩展名的,而windows是文件是有扩展名的。











创建一个新用户


[root@localhost mxh]# useradd mxh2        # 创建一个user
[root@localhost mxh]# password mxh2             #12345678
[root@localhost xxx]# groupadd mxhgrp     #创建一个组mxhgrp
[root@localhost xxx]# passwd  mxhgrp         #12345678

 passwd  命令用于更改密码

管理员可以更改任何人的密码;而普通用户只能更改自己的密码;

查找命令使用方法

1、man ls
2、 ls --help



二、使用命令

命令格式

        命令  [-选项]  [参数]     []->指可选参数,不加这两个参数的命令也可以单独执行,例如ls

       例如: ls     -la    /etc  

             ls:命令; -la:选项;/etc:操作对象

文件用户分为三类:所有者、用户组、其他人

1、所有者:只能有一个,而且身份可能是会变换的;比如我的电脑,我就是所有者,卖给别人后,那个卖买的人就是所有者,而我不是所有者了。

2、所属组:我的电脑可以给办公室里的美女使用,多个美女就是一个所属组,而我还是所有者

3、其他人:除了以上两个身份外的用户

目录处理命令
ls -a查看目录下所有文件,包括隐藏的文件
ls -l查看目录下文件的详细信息(包括权限)
ls -lh人性化查看目录下文件的详细信息(包括权限)
ls -ld查看文件详细信息(包括权限)
ls -li查看文件的ID序号

1、ls:主要查看当前目录下有什么文件,并没有定位到那个目录下

[root@localhost ~]# ls /
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr

2、cd:用于定位到那个目录下

[root@localhost ~]# ls /
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr
[root@localhost ~]# ls /run
auditd.pid   dbus                initramfs       plymouth     tmpfiles.d
blkid        dhclient-ens33.pid  lock            sepermit     tuned
chrony       dmeventd-client     log             setrans      udev
console      dmeventd-server     lvm             sshd.pid     user
crond.pid    ebtables.lock       mount           sudo         utmp
cron.reboot  faillock            netreport       syslogd.pid  vmware
cryptsetup   firewalld           NetworkManager  systemd      xtables.lock
[root@localhost ~]# cd /run
[root@localhost run]# ls
auditd.pid   dbus                initramfs       plymouth     tmpfiles.d
blkid        dhclient-ens33.pid  lock            sepermit     tuned
chrony       dmeventd-client     log             setrans      udev
console      dmeventd-server     lvm             sshd.pid     user
crond.pid    ebtables.lock       mount           sudo         utmp
cron.reboot  faillock            netreport       syslogd.pid  vmware
cryptsetup   firewalld           NetworkManager  systemd      xtables.lock
[root@localhost run]#

3、ls -a:显示当前目录下所有文件,包括隐藏的文件,隐藏的文件是以 .开头的

[root@localhost ~]# ls -a
.  ..  anaconda-ks.cfg  .bash_logout  .bash_profile  .bashrc  .cshrc  .tcshrc

4、ls -l(l->long) :文件以一个详细的信息列出来显示


[root@localhost ~]# ls -l
总用量 4
-rw-------. 1 root root 1216 10月 22 21:38 anaconda-ks.cfg

#1->引用计数; root->所有者(rw权限); root->所属组(无权限); 1216B->文件大小;10.22是文件修改时间

ls -lh(h->human人性化显示)


[root@localhost ~]# ls -lh   
总用量 4.0K
-rw-------. 1 root root 1.2K 10月 22 21:38 anaconda-ks.cfg

文件类型:区分软连接、文件、目录

-:表示一个文件

d开头:表示一个目录

l:开头表示一个软连接


[root@localhost ~]# ls -l /
总用量 20
lrwxrwxrwx.   1 root root    7 10月 22 21:29 bin -> usr/bin  #软连接
dr-xr-xr-x.   5 root root 4096 10月 23 09:23 boot            #目录

[root@localhost ~]# ls -a
.  ..  anaconda-ks.cfg  .bash_logout  .bash_profile  .bashrc  .cshrc  .tcshrc
[root@localhost ~]# ls -l /run     #查看run目录下所有文件权限
总用量 24
-rw-r--r--.  1 root   root      4 10月 23 09:21 auditd.pid
drwxr-xr-x.  2 root   root     80 10月 23 09:22 blkid     #所有者:rw、x、r权限;所属组:x、r权限
drwxr-x---.  2 chrony chrony   80 10月 23 09:23 chrony     #是一个目录
drwxr-xr-x.  2 root   root     40 10月 23 09:21 console
-rw-r--r--.  1 root   root      5 10月 23 09:23 crond.pid   #是一个文件

X执行权限最大;

5、ls -ld :查看文件权限,不是目录下文件的权限;注意与ls -l的区别;


[root@localhost ~]# ls -ld /run
drwxr-xr-x. 26 root root 740 10月 23 09:23 /run  #run这个文件:所有者rw、x、r权限

5、ls -li:查看文件的id序号(最前面的是ID号)


[root@localhost ~]# ls -li /run
总用量 24
15072 -rw-r--r--.  1 root   root      4 10月 23 09:21 auditd.pid
16995 drwxr-xr-x.  2 root   root     80 10月 23 09:22 blkid
24830 drwxr-x---.  2 chrony chrony   80 10月 23 09:23 chrony
15035 drwxr-xr-x.  2 root   root     40 10月 23 09:21 console
26891 -rw-r--r--.  1 root   root      5 10月 23 09:23 crond.pid
28110 ----------.  1 root   root      0 10月 23 09:23 cron.reboot
15034 drwx------.  2 root   root     40 10月 23 09:21 cryptsetup
24213 drwxr-xr-x.  2 root   root     60 10月 23 09:23 dbus
27608 -rw-r--r--.  1 root   root      5 10月 23 11:31 dhclient-ens33.pid
13853 prw-------.  1 root   root      0 10月 23 09:19 dmeventd-client
13852 prw-------.  1 root   root      0 10月 23 09:19 dmeventd-server
28868 -rw-------.  1 root   root      0 10月 23 09:23 ebtables.lock
15024 drwxr-xr-x.  2 root   root     40 10月 23 09:21 faillock
27614 drwxr-x---.  2 root   root     40 10月 23 09:23 firewalld
10562 drwxr-xr-x.  4 root   root    120 10月 23 09:19 initramfs
 1085 drwxr-xr-x.  5 root   root    120 10月 23 10:30 lock
10566 drwxr-xr-x.  3 root   root     60 10月 23 09:19 log

文件处理命令
mkdir

创建文件mkdir /tmp/mxh    在tmp目录下创建mxh文件夹

mkdir -p递归创建多个文件夹
cd定位到某个目录下
cd..返回上一级目录
pwd打印当前所在的完整目录
rmdir删除命令(只能删除空目录)
cp复制命令:将文件复制到其他目录下的操作
cp -r复制命令:将目录复制到其他目录下的操作
cp -p复制文件时保留其属性,修改时间不变,特别是日志
cp进行复制的同时还可以改名字

1、mkdir 创建文件

mkdir +文件位置  这个只能在原有的目录下创建一个文件夹,不能连续创建多个子目录


[root@localhost ~]# mkdir /tmp/mxh
[root@localhost ~]# ls /tmp
ks-script-IAr5pa
mxh                #这个是我创建的文件夹
vmware-root_724-2965906890
vmware-root_7527-3853947382
yum.log

2、mkdir -p 加目录:可连续创建多个子目录


[root@localhost tmp]# mkdir -p /tmp/mxh/mxh1/mxh2  #连续创建两个子目录mxh1、mxh2
[root@localhost tmp]# ls /tmp/mxh
mxh1
[root@localhost tmp]# ls /tmp/mxh/mxh1
mxh2

3、mkdir 同时创建多个并行目录文件夹


[root@localhost ~]# mkdir /tmp/mxh/AK1 /tmp/mxh/AK2  #两个目录中间是用空格隔开
[root@localhost ~]# ls -l /tmp
总用量 4
-rwx------. 1 root root 836 10月 22 21:38 ks-script-IAr5pa
drwxr-xr-x. 5 root root  40 10月 23 13:00 mxh
drwx------. 3 root root  17 10月 23 09:23 systemd-private-4b41272e80d041ceb75a8d4cc2b1d4a6-chronyd.service-KlCaFC
drwx------. 3 root root  17 10月 22 21:41 systemd-private-4d581edd37154b6cb14d94ae0babdd78-chronyd.service-dubJHv
drwx------. 2 root root   6 10月 22 21:41 vmware-root_724-2965906890
drwx------. 2 root root   6 10月 23 09:23 vmware-root_7527-3853947382
-rw-------. 1 root root   0 10月 22 21:28 yum.log
[root@localhost ~]# ls -l /tmp/mxh
总用量 0
drwxr-xr-x. 2 root root  6 10月 23 13:00 AK1     #在/tmp/mxh下创建AK1
drwxr-xr-x. 2 root root  6 10月 23 13:00 AK2     #在/tmp/mxh下创建AK2
drwxr-xr-x. 3 root root 18 10月 23 12:52 mxh1

4、pwd


[root@localhost ~]# cd /tmp/mxh/AK1
[root@localhost AK1]# ls
[root@localhost AK1]# pwd
/tmp/mxh/AK1

5、cd用法,返回上一级命令

[root@localhost tmp]# cd /tmp/mxh/AK1
[root@localhost AK1]# pwd
/tmp/mxh/AK1
[root@localhost AK1]# cd ..
[root@localhost mxh]# cd ..
[root@localhost tmp]# cd ..
[root@localhost /]# cd ..
[root@localhost /]# ls /
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr

6、rmdir 删除命令使用(只能删除空目录)


[root@localhost /]# ls /tmp/mxh
AK1  AK2  mxh1
[root@localhost /]# rmdir /tmp/mxh/AK2   #删除AK2
[root@localhost /]# ls /tmp/mxh
AK1  mxh1

7、cp复制命令:#这个是将文件复制到其他目录下的操作

#这个是将文件复制到其他目录下的操作
[root@localhost tmp]# cp /run/auditd.pid /tmp/mxh/test  #将auditd.pid复制到test目录下
[root@localhost tmp]# ls /tmp/mxh/test
auditd.pid

8、将目录复制到其他目录下操作


[root@localhost tmp]# ls /tmp
ks-script-IAr5pa
mxh
systemd-private-4b41272e80d041ceb75a8d4cc2b1d4a6-chronyd.service-KlCaFC
systemd-private-4d581edd37154b6cb14d94ae0babdd78-chronyd.service-dubJHv
test1                         #将test1这个目录复制到麦mxh这个目录下
vmware-root_724-2965906890
vmware-root_7527-3853947382
yum.log
[root@localhost tmp]# cp -r /tmp/test1 /tmp/mxh
[root@localhost tmp]# ls /tmp/mxh
test  test1

9、cp同时复制多个文件到其他目录   cp 目标文件1  目标文件2  。。。。 目的目录

#将/run下的crond.pid、cron.reboot复制到test1目录下
[root@localhost tmp]# cp /run/crond.pid /run/cron.reboot /tmp/mxh/test1
[root@localhost tmp]# ls /tmp/mxh/test1
crond.pid  cron.reboot

10、cp -p :复制文件时保留其属性不变

[root@localhost tmp]# ls /run
auditd.pid   dbus                initramfs       plymouth     tmpfiles.d
blkid        dhclient-ens33.pid  lock            sepermit     tuned
chrony       dmeventd-client     log             setrans      udev
console      dmeventd-server     lvm             sshd.pid     user
crond.pid    ebtables.lock       mount           sudo         utmp
cron.reboot  faillock            netreport       syslogd.pid  vmware
cryptsetup   firewalld           NetworkManager  systemd      xtables.lock
[root@localhost tmp]# ls -l /run/crond.pid
-rw-r--r--. 1 root root 5 10月 23 09:23 /run/crond.pid
[root@localhost tmp]# cp -p /run/crond.pid  /tmp/mxh/test1
cp:是否覆盖"/tmp/mxh/test1/crond.pid"? y
[root@localhost tmp]# ls -l /tmp/mxh/test1
总用量 4
-rw-r--r--. 1 root root 5 10月 23 09:23 crond.pid   时间和修改前不变

11、cp进行复制的同时还可以改名字


[root@localhost tmp]# ls /tmp/mxh
test  test1
[root@localhost tmp]# ls /tmp/mxh/test1
crond.pid  cron.reboot
[root@localhost tmp]# cp -r /tmp/mxh/test1 /tmp/mxh/test/gaiming   #将test1这个目录复制到test目录下,并同时将test1这个目录名称改为gaiming这个名称
[root@localhost tmp]# ls /tmp/mxh/test
auditd.pid  gaiming
[root@localhost tmp]# ls /tmp/mxh/test/gaiming
crond.pid  cron.reboot

mv剪切功能:mv  剪切目标  剪切目的(可直接剪切文件或目录,不需要像cp -r 来复制目录)
mv该文件或文件夹名称

1、mv 剪切功能(可直接剪切文件或目录,不需要像cp -r 来复制目录)


[root@localhost ~]# ls /tmp/mxh/test1  
crond.pid  cron.reboot
[root@localhost ~]# mv /tmp/mxh/test1/crond.pid /tmp/mxh  #将crond.pid剪切到mxh目录下
[root@localhost ~]# ls /tmp/mxh
crond.pid  test1
[root@localhost ~]# ls /tmp/mxh/test1
cron.reboot

2、mv 剪切功能同时改名(可直接剪切文件或目录,不需要像cp -r 来复制目录)


[root@localhost ~]# ls /tmp/mxh
test1
[root@localhost ~]# ls /tmp/mxh/test1
crond.pid  cron.reboot
[root@localhost ~]# cp /tmp/mxh/test1/crond.pid /tmp/mxh/test1/1.pid
[root@localhost ~]# ls /tmp/mxh/test1
1.pid  crond.pid  cron.reboot
[root@localhost ~]# mv /tmp/mxh/test1/1.pid /tmp/mxh/2.pid #将1.pid 剪切并改名为2.pid到mxh目录下
[root@localhost ~]# ls /tmp/mxh/test1
crond.pid  cron.reboot
[root@localhost ~]# ls /tmp/mxh
2.pid  test1

3、mv 直接改文件夹或文件名称

[root@localhost ~]# ls /tmp/mxh
2.pid  test1
[root@localhost ~]# cd /tmp/mxh
[root@localhost mxh]# mv 2.pid 3.pid
[root@localhost mxh]# ls
3.pid  test1
rm删除文件(每次删除会带有问你是否删除)
rm -f强制删除  (不会带有询问)
rm -rf删除目录文件夹

1、rm删除文件


[root@localhost ~]# ls /tmp/mxh
1.pid  test1
[root@localhost ~]# cp /tmp/mxh/1.pid /tmp/mxh/2.pid
[root@localhost ~]# ls /tmp/mxh           #绝对路经下复制
1.pid  2.pid  test1              
[root@localhost ~]# cd /tmp/mxh
[root@localhost mxh]# cp 2.pid 3.pid
[root@localhost mxh]# ls                 #进到路径下复制
1.pid  2.pid  3.pid  test1
[root@localhost mxh]# rm 1.pid            #删除文件
rm:是否删除普通文件 "1.pid"?y
[root@localhost mxh]# ls
2.pid  3.pid  test1
[root@localhost mxh]# cp 2.pid 1.pid
[root@localhost mxh]# ls
1.pid  2.pid  3.pid  test1
[root@localhost mxh]# mv 3.pid 4.pid
[root@localhost mxh]# ls
1.pid  2.pid  4.pid  test1

2、rm -f 强制删除  (不会带有询问)


[root@localhost mxh]# ls
1.pid  2.pid  4.pid  test1
[root@localhost mxh]# cd
[root@localhost ~]# rm -f /tmp/mxh/1.pid /tmp/mxh/2.pid  #删除1.pid 2.pid
[root@localhost ~]# ls /tmp/mxh
4.pid  test1

3、rm -rf 强制删除目录文件夹


[root@localhost mxh]# mkdir test
[root@localhost mxh]# ls
1.pid  2.pid  3.pid  4.pid  test  test1
[root@localhost mxh]# cp 1.pid 2.pid 3.pid 4.pid test
[root@localhost mxh]# ls test
1.pid  2.pid  3.pid  4.pid
[root@localhost mxh]# ls
1.pid  2.pid  3.pid  4.pid  test  test1
[root@localhost mxh]# ls test
1.pid  2.pid  3.pid  4.pid
[root@localhost mxh]# rm test
rm: 无法删除"test": 是一个目录
[root@localhost mxh]# rm -r test
rm:是否进入目录"test"? y
rm:是否删除普通文件 "test/1.pid"?y
rm:是否删除普通文件 "test/2.pid"?y
rm:是否删除普通文件 "test/3.pid"?y
rm:是否删除普通文件 "test/4.pid"?y
rm:是否删除目录 "test"?y
[root@localhost mxh]# ls
1.pid  2.pid  3.pid  4.pid  test1
[root@localhost mxh]# mkdir test
[root@localhost mxh]# cp 1.pid 2.pid 3.pid 4.pid test
[root@localhost mxh]# ls test
1.pid  2.pid  3.pid  4.pid
[root@localhost mxh]# ls
1.pid  2.pid  3.pid  4.pid  test  test1
[root@localhost mxh]# rm -rf test
[root@localhost mxh]# ls
1.pid  2.pid  3.pid  4.pid  test1

文件处理命令

touch新建一个文件(mkdir是创建一个目录,不一样)
cat直接浏览文件的具体内容(适合小文档内容查看)
cat -n显示内容的行号
more查看大文件很多内容的方法
less查看大文件很多内容的方法,比more好用(less只能区分大小写查找,要想找到只能输入的单词完全正确才行,与后面的grep 查找文档内容有区别)
head -n 行数m查看文件的前m行
tail -n 行数m查看文件的最后的m行
tail -f动态显示日志的后10行内容,日志变化显示也跟着变化

1、touch创建文件命令


[root@localhost mxh]# touch 7.pid
[root@localhost mxh]# ls
1.pid  2.pid  3.pid  4.pid  7.pid  test1

2、连续新建文档(适合小文档内容查看)


[root@localhost mxh]# touch 5.pid 6.pid
[root@localhost mxh]# ls
1.pid  2.pid  3.pid  4.pid  5.pid  6.pid  7.pid  test1

3、cat直接浏览文件的具体内容,cat -n 显示内容的行数


[root@localhost mxh]# cat 1.pid
7565

[root@localhost mxh]# cat -n 1.pid
     1  7565

4、more:查看一个文件里有很多内容方法


[root@localhost ~]# more /etc/services
# /etc/services:
# $Id: services,v 1.55 2013/04/14 ovasik Exp $
#
# Network services, Internet style
# IANA services version: last updated 2013-04-10
#
# Note that it is presently the policy of IANA to assign a single well-known
# port number for both TCP and UDP; hence, most entries here have two entries
# even if the protocol doesn't support UDP operations.
# Updated from RFC 1700, ``Assigned Numbers'' (October 1994).  Not all ports
# are included, only the more common ones.
#
# The latest IANA port assignments can be gotten from
#       http://www.iana.org/assignments/port-numbers
# The Well Known Ports are those from 0 through 1023.
# The Registered Ports are those from 1024 through 49151
# The Dynamic and/or Private Ports are those from 49152 through 65535
#
# Each line describes one service, and is of the form:
#
# service-name  port/protocol  [aliases ...]   [# comment]

tcpmux          1/tcp                           # TCP port service multiplexer
--More--(0%)

空格或f  往下翻页

Enter  一行一行的翻页

b        往上一页一页的往回翻页

ctrl +C  退出

5、more的用法

tcpmux          1/udp                           # TCP port service multiplexer
[root@localhost ~]# less /etc/services
[root@localhost ~]#
[root@localhost ~]# less /etc/services
# /etc/services:
# $Id: services,v 1.55 2013/04/14 ovasik Exp $
#
# Network services, Internet style
# IANA services version: last updated 2013-04-10
#
# Note that it is presently the policy of IANA to assign a single well-known
# port number for both TCP and UDP; hence, most entries here have two entries
# even if the protocol doesn't support UDP operations.
# Updated from RFC 1700, ``Assigned Numbers'' (October 1994).  Not all ports
# are included, only the more common ones.

PgDn向上翻页

PgDn向下翻页

q  退出


#
# The latest IANA port assignments can be gotten from
#       http://www.iana.org/assignments/port-numbers
# The Well Known Ports are those from 0 through 1023.
# The Registered Ports are those from 1024 through 49151
# The Dynamic and/or Private Ports are those from 49152 through 65535
#
# Each line describes one service, and is of the form:
#
# service-name  port/protocol  [aliases ...]   [# comment]

tcpmux          1/tcp                           # TCP port service multiplexer
/service       #写入/ +要查找的关键字  就会帮你找出来  

 #写入"/" +要查找的关键字  就会帮你找出来

按键 n(next) 会帮你查找下一个关键字

6、head -n 行数m:查看文件内容的前m行

[root@localhost ~]# head -n 10 /etc/services
# /etc/services:
# $Id: services,v 1.55 2013/04/14 ovasik Exp $
#
# Network services, Internet style
# IANA services version: last updated 2013-04-10
#
# Note that it is presently the policy of IANA to assign a single well-known
# port number for both TCP and UDP; hence, most entries here have two entries
# even if the protocol doesn't support UDP operations.
# Updated from RFC 1700, ``Assigned Numbers'' (October 1994).  Not all ports

7、tail -n 行数m:查看文件内容的后m行(工作中查看日志常用)


[root@localhost ~]# tail -n 5 /etc/services
com-bardac-dw   48556/tcp               # com-bardac-dw
com-bardac-dw   48556/udp               # com-bardac-dw
iqobject        48619/tcp               # iqobject
iqobject        48619/udp               # iqobject
matahari        49000/tcp               # Matahari Broker

8、tail -f   动态显示日志的后10行内容,日志变化显示也跟着变化

链接命令:软链接命令相当于windows的快捷方式

ln(link)ln -s  [源文件]  [目标文件]  生成链接文件  针对的是文件,不是目录  软链接
ln   [源文件]  [目标文件]  生成链接文件  针对的是文件,不是目录,生成硬链接

  

1、ln -s  [源文件]  [目标文件]  生成链接文件  针对的是文件,不是目录  生成软链接


[root@localhost mxh]# ls
1.pid  2.pid  3.pid  4.pid  5.pid  6.pid  7.pid  mxhtest  test1
[root@localhost mxh]# ln -s mxhtest mxhtest.soft  生成软链接
[root@localhost mxh]# ls -l
总用量 16
-rw-r--r--. 1 root root  5 10月 23 22:18 1.pid
-rw-r--r--. 1 root root  5 10月 23 22:18 2.pid
-rw-r--r--. 1 root root  5 10月 23 22:18 3.pid
-rw-r--r--. 1 root root  5 10月 23 22:18 4.pid
-rw-r--r--. 1 root root  0 10月 23 23:17 5.pid
-rw-r--r--. 1 root root  0 10月 23 23:17 6.pid
-rw-r--r--. 1 root root  0 10月 23 23:07 7.pid
drwxr-xr-x. 2 root root  6 10月 24 10:00 mxhtest
lrwxrwxrwx. 1 root root  7 10月 24 10:01 mxhtest.soft -> mxhtest   #软连接
drwxr-xr-x. 2 root root 42 10月 23 21:51 test1

2、ln   [源文件]  [目标文件]  生成链接文件  针对的是文件,不是目录  生成硬链接


[root@localhost mxh]# ln mxhtest mxhtest.hard
[root@localhost mxh]# ls -l
总用量 16
-rw-r--r--. 1 root root  5 10月 23 22:18 1.pid
-rw-r--r--. 1 root root  5 10月 23 22:18 2.pid
-rw-r--r--. 1 root root  5 10月 23 22:18 3.pid
-rw-r--r--. 1 root root  5 10月 23 22:18 4.pid
-rw-r--r--. 1 root root  0 10月 23 23:17 5.pid
-rw-r--r--. 1 root root  0 10月 23 23:17 6.pid
-rw-r--r--. 1 root root  0 10月 23 23:07 7.pid
-rw-r--r--. 2 root root  0 10月 24 10:07 mxhtest
-rw-r--r--. 2 root root  0 10月 24 10:07 mxhtest.hard
lrwxrwxrwx. 1 root root  7 10月 24 10:07 mxhtest.soft -> mxhtest   #注意软链接的特点
drwxr-xr-x. 2 root root 42 10月 23 21:51 test1

权限管理命令

权限: r读 、w写、x执行 

权限对象:所有者、所属组、其他人

只有所有者或超级管理员才能更改权限

r  -> 4         w->2         x->1

chmod权限管理命令chmod 754 文件名称
chmod -R递归修改,就是如果、a/b/c,执行chmod -r 777 /a  ,那么,、b/c的权限也会和/a的权限一样被修改

 1、chmod修改文件目录权限

[root@localhost mxh]# ls -l 1.pid
-rwxr--r--. 1 root root 5 10月 23 22:18 1.pid

假设1.pid 原本的权限是 所有者rwx(4+2+1=7)  ;所属者r(4+0+0=4)  ;其他人 r(4+0+0=4)  1.pid的权限是744;我想要改成rwxrxw--(拆分就是754)

[root@localhost mxh]# ls -l 1.pid
-rwxr-xr--. 1 root root 5 10月 23 22:18 1.pid  #修改后

2、chmod -R递归修改文件目录权限,递归修改,就是如果、a/b/c,执行chmod -R 777 /a  ,那么,、b/c的权限也会和/a的权限一样被修改

[root@localhost mxh]# ls -l
总用量 0
-rw-r--r--. 1 root root  0 10月 24 10:07 mxhtest
lrwxrwxrwx. 1 root root  7 10月 24 10:07 mxhtest.soft -> mxhtest
drwxr-xr-x. 2 root root 42 10月 23 21:51 test1
drwxr-xr-x. 2 root root 32 10月 24 12:55 xxx    #未修改前
[root@localhost mxh]# ls -l xxx
总用量 8
-rw-r--r--. 1 root root 5 10月 23 22:18 2.pid    #未修改前
-rw-r--r--. 1 root root 5 10月 23 22:18 3.pid    #未修改前
[root@localhost mxh]# chmod -R 777 xxx          #递归修改xxx目录后,其底下的两个文件权限也跟着变
[root@localhost mxh]# ls -l
总用量 0
-rw-r--r--. 1 root root  0 10月 24 10:07 mxhtest
lrwxrwxrwx. 1 root root  7 10月 24 10:07 mxhtest.soft -> mxhtest
drwxr-xr-x. 2 root root 42 10月 23 21:51 test1
drwxrwxrwx. 2 root root 32 10月 24 12:55 xxx      #修改后
[root@localhost mxh]# ls -l xxx
总用量 8
-rwxrwxrwx. 1 root root 5 10月 23 22:18 2.pid     #修改后
-rwxrwxrwx. 1 root root 5 10月 23 22:18 3.pid     #修改后

目录权限

        对于目录来说,有以下权限就可以执行相应的操作:

           r -> ls查看

          w->mkdir\rm\rmdir\touch 删除和增加文件

           x-> cd 进入到目录下

有r权一定有x权限,不然查看不了目录的文件,进不去目录

chownchown 用户名 目标文件   更改目标文件的所有者
chgrpchgrp  用户名 目标文件     更改目标文件的所属组
umask -S查看当前创建目录有哪一些权限

1、chown 用户名 目标文件   更改目标文件的所有者


[root@localhost xxx]# ls -l
总用量 0
-rw-r--r--. 1 root root 0 10月 24 17:18 1.pid   #第一个root是所有者(一般是谁创建谁就是所有者)   第二个root是所属者
-rw-r--r--. 1 root root 0 10月 24 17:18 2.pid
[root@localhost xxx]# useradd mxh2
useradd:用户“mxh2”已存在
[root@localhost xxx]# chown mxh2 1.pid   #把所有者的身份从root转移到mxh2上
[root@localhost xxx]# ls -l
总用量 0
-rw-r--r--. 1 mxh2 root 0 10月 24 17:18 1.pid   #1.pid的所有者是mxh2
-rw-r--r--. 1 root root 0 10月 24 17:18 2.pid

2、chgrp  用户名 目标文件     更改目标文件的所属组


[root@localhost xxx]# ls -l
总用量 0
-rw-r--r--. 1 mxh2 root 0 10月 24 17:18 1.pid
-rw-r--r--. 1 root root 0 10月 24 17:18 2.pid
[root@localhost xxx]# chgrp mxhgrp 1.pid   #将1.pid所属者的身份从root变为mxhgrp用户
[root@localhost xxx]# ls -l
总用量 0
-rw-r--r--. 1 mxh2 mxhgrp 0 10月 24 17:18 1.pid   #成功修改权限
-rw-r--r--. 1 root root   0 10月 24 17:18 2.pid

3、chmod更改所有者和所属组的权限

[root@localhost xxx]# ls -l
总用量 0
-rw-r--r--. 1 mxh2 mxhgrp 0 10月 24 17:18 1.pid
-rw-r--r--. 1 root root   0 10月 24 17:18 2.pid
[root@localhost xxx]# ^C
[root@localhost xxx]# chmod 777 1.pid
[root@localhost xxx]# ls -l
总用量 0
-rwxrwxrwx. 1 mxh2 mxhgrp 0 10月 24 17:18 1.pid
-rw-r--r--. 1 root root   0 10月 24 17:18 2.pid

3、umask -S查看当前创建目录有哪一些权限

[root@localhost xxx]# ls
[root@localhost xxx]# umask -S   #针对创建目录查看其权限
u=rwx,g=rx,o=rx    
[root@localhost xxx]# mkdir test
[root@localhost xxx]# touch 1.pid
[root@localhost xxx]# ls -l  
总用量 0
-rw-r--r--. 1 root root 0 10月 24 18:48 1.pid  #为了安全性,一般新建的文件不具有可执行性
drwxr-xr-x. 2 root root 6 10月 24 18:48 test  #与umask -S 的权限一致

umask创建目录时的权限是怎么得来的:

[root@localhost ~]# umask
0022
#第一个0 :特殊权限
#022 对应一下:
#    ----w--w-    然后与777异或取值
#    rwxrwxrwx
----------------------
#    rwxr-xr-x     所以看到创建的目录是rwxr-xr-x

文件搜索命令

findfind会占用服务器大量的系统资源,尽量少用
find 目录范围  -name  文件名 (区分大小写查找)find 目录范围  -name  文件名  (精准查找)或 find 目录范围  -name *文件名* (只要有这个文件名的都找出来)
find 目录范围  -iname  文件名 (不区分大小写查找) 不区分大小写进行查找

1、find 目录范围  -name  文件名 (区分大小写查找) 精准查找和广泛查找(区分大小写查找)

[root@localhost ~]# find /etc -name init
/etc/sysconfig/init
/etc/selinux/targeted/active/modules/100/init
[root@localhost ~]# find /etc -name *init*
/etc/systemd/system/sysinit.target.wants
/etc/inittab
/etc/sysconfig/init
/etc/sysconfig/network-scripts/init.ipv6-global
/etc/init.d
/etc/rc.d/init.d
/etc/selinux/targeted/active/modules/100/init
/etc/selinux/targeted/contexts/initrc_context
/etc/security/namespace.init

2、find 目录范围  -iname  文件名 (不区分大小写查找) 


[root@localhost mxh]# cd xxx
[root@localhost xxx]# touch INIT
[root@localhost xxx]# ls
1.pid  INIT  test                       #在这里创建一个INIt文件

[root@localhost xxx]# find / -name init   #查找不到INIT
/sys/fs/selinux/initial_contexts/init 
/etc/sysconfig/init
/etc/selinux/targeted/active/modules/100/init
/usr/sbin/init
/usr/libexec/os-probes/init

[root@localhost xxx]# find / -iname init     #不区分大小写查找,查到了INIT文件
/sys/fs/selinux/initial_contexts/init
/etc/sysconfig/init
/etc/selinux/targeted/active/modules/100/init
/tmp/mxh/xxx/INIT                                #这里
/usr/sbin/init
/usr/libexec/os-probes/init
find  /目录 -size +n(大于)/-n(小于)/n(等于)根据文件大小来查找
find  /目录 -user/-group  文件名根据用户来查找文件
find /目录 -amin  -n分钟查找在n分钟访问过的文件目录
find /目录  -cmin  -n分钟根据在n分钟内更改过的文件来查找
find /目录  -mmin  -n分钟根据在n分钟内文件内容被修改来查找

1、根据文件大小来查找


[root@localhost ~]# find /tmp -size -1k
/tmp/yum.log
/tmp/mxh/test1/cron.reboot
/tmp/mxh/mxhtest
/tmp/mxh/xxx/1.pid
/tmp/mxh/xxx/INIT

2、根据用户来查找  find  /目录 -user/-group  文件名


[root@localhost ~]# find / -user mxh2 #查找用户mxh2的所有文件
/run/user/1000
/var/spool/mail/mxh2
/home/mxh2
/home/mxh2/.bash_logout
/home/mxh2/.bash_profile
/home/mxh2/.bashrc
/home/mxh2/.lesshst
/home/mxh2/.bash_history

3、find /目录 -amin  -n分钟 查找在n分钟访问过的文件目录


[root@localhost ~]# find /tmp -amin -100
/tmp/mxh/test1

4、find /目录  -cmin  -n分钟  根据在n分钟内更改过的文件来查找


[root@localhost ~]# find /tmp -cmin -200
/tmp/mxh/xxx
/tmp/mxh/xxx/INIT

5、find /目录  -mmin  -n分钟  根据在n分钟内文件内容被修改来查找


[root@localhost ~]# find /tmp -mmin -300
/tmp
/tmp/mxh/xxx
/tmp/mxh/xxx/test
/tmp/mxh/xxx/1.pid
/tmp/mxh/xxx/INIT
/tmp/systemd-private-e90722c3e92448538e73ca7ff7af2bf4-chronyd.service-UmZK4C
/tmp/systemd-private-e90722c3e92448538e73ca7ff7af2bf4-chronyd.service-UmZK4C/tmp
/tmp/vmware-root_713-4290166671
find  /目录 -type f查找文件(f是文件)
find  /目录 -type d查找目录(d是目录)
find  /目录 -type l查找软连接(l是软连接)
连接符:-a 条件同时满足
连接符:-o条件满足其中之一
find /目录 -iname 文件名  -exec ls -l {} \;解读:可以把ls -l 改成其他命令的组合;意思就是找到这些文件后你要操作什么步骤

1、find  /目录 -type f   查找文件(f是文件)


[root@localhost ~]# find /tmp -type f
/tmp/yum.log
/tmp/ks-script-IAr5pa
/tmp/mxh/test1/cron.reboot
/tmp/mxh/test1/crond.pid
/tmp/mxh/mxhtest
/tmp/mxh/xxx/1.pid
/tmp/mxh/xxx/INIT

2、find  /目录 -type d  查找目录(d是目录)


[root@localhost ~]# find /tmp -type d
/tmp
/tmp/.XIM-unix
/tmp/.font-unix
/tmp/.X11-unix
/tmp/.ICE-unix
/tmp/.Test-unix

3、find  /目录 -type l  查找软连接(l是软连接)


[root@localhost ~]# find /tmp -type l
/tmp/mxh/mxhtest.soft

4、连接符:-a  条件同时满足

oot@localhost ~]# find /etc -iname *init* -a -type f  
/etc/inittab
/etc/sysconfig/init
/etc/sysconfig/network-scripts/init.ipv6-global
/etc/selinux/targeted/contexts/initrc_context
/etc/security/namespace.init
[root@localhost ~]# find /etc -iname *init* -a -type l
/etc/init.d
[root@localhost ~]# find /etc -iname *init* -a -type d
/etc/systemd/system/sysinit.target.wants
/etc/rc.d/init.d
/etc/selinux/targeted/active/modules/100/init

5、find /目录 -iname 文件名  -exec ls -l {} \;  {}表示前面找到的内容的一个集合

解读:可以把ls -l 改成其他命令的组合;意思就是找到这些文件后你要操作什么步骤


[root@localhost ~]# find /etc -iname init -a -type f
/etc/sysconfig/init
[root@localhost ~]# find /etc -iname init -a -type f -exec ls -l {} \;
-rw-r--r--. 1 root root 798 10月 13 2020 /etc/sysconfig/init

6、find和cp命令结合使用 {}表示前面找到的内容的一个集合


[root@localhost ~]# find /etc -iname init -a -type f -exec cp {} /tmp/mxh/xxx \;
[root@localhost ~]# ls -l /tmp/mxh/xxx
总用量 4
-rw-r--r--. 1 root root   0 10月 24 18:48 1.pid
-rw-r--r--. 1 root root 798 10月 24 22:44 init
-rw-r--r--. 1 root root   0 10月 24 19:21 INIT
drwxr-xr-x. 2 root root   6 10月 24 18:48 test

7、find . -inum 序号 -exec rm {} \;     {}表示前面找到的内容的一个集合


[root@localhost xxx]# touch 1.pid
[root@localhost xxx]# ls -il
总用量 0
33583818 -rw-r--r--. 1 root root 0 10月 25 13:04 1.pid
[root@localhost xxx]# find . -inum 33583818 -exec rm -rf {} \;
[root@localhost xxx]# ls -il
总用量 0
locate查找命令,首先安装yum install mlocate ;再更新库 updatedb;再进行 locate 文件名 进行查找 (基于数据库检索)
locate -i 文件名不区分大小写进行查找

1、locate 文件名  基于数据库查找 ;但是,存在临时文件的查找不了


[root@localhost ~]# yum install mlocate  #安装
已加载插件:fastestmirror
[root@localhost ~]# updatedb      #更新数据库

[root@localhost ~]# locate mxh    #关键字查找
/home/mxh2
/home/mxh2/.bash_history
/home/mxh2/.bash_logout
/home/mxh2/.bash_profile
/home/mxh2/.bashrc
/home/mxh2/.lesshst
/var/spool/mail/mxh2

 2、临时文件下面的查找不到


[root@localhost ~]# ls /tmp/mxh
mxhtest  mxhtest.soft  test1  xxx
[root@localhost ~]# locate test1
[root@localhost ~]#

3、locate -i 文件名   不区分大小写进行查找


[root@localhost home]# ls -il
总用量 0
33583836 -rw-r--r--. 1 root root  0 10月 25 19:38 MXh1
51042340 drwx------. 2 mxh2 mxh2 99 10月 24 17:30 mxh2
[root@localhost home]# updatedb
[root@localhost home]# locate -i mxh1
/home/MXh1
which 命令快速查找命令所在位置
whereis 命令快速查找命令和帮助文档所在位置
grep -i 关键词 文件目录可以不区分关键词大小写来进行查找文档内容

1、which 命令    快速查找命令所在位置


[root@localhost ~]# which groupadd
/usr/sbin/groupadd
[root@localhost ~]# which ls
alias ls='ls --color=auto'
 /usr/bin/ls

2、whereis 命令  同样能找到命令所在位置,还能知道帮助文件所在位置,whereis路径多出来的部分就是帮助文档的路径  以下:/usr/share/man/man1/ls.1.gz  就是帮助文档位置。


[root@localhost ~]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
[root@localhost ~]# which ls
alias ls='ls --color=auto'
 /usr/bin/ls

3、grep -i 关键词 文件目录  可以不区分关键词大小写来进行查找文档内容

[root@localhost ~]# more /etc/fstab

#
# /etc/fstab
# Created by anaconda on Fri Oct 22 21:28:51 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=57a167f9-7601-4c24-93e7-d2916c3a2445 /boot                   xfs     defaults        0
 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
[root@localhost ~]# grep -i created /etc/fstab
# Created by anaconda on Fri Oct 22 21:28:51 2021  #检索结果直接打出关键词的这一行

[root@localhost ~]# grep -i create /etc/fstab       #不完全输入完也能找出来
# Created by anaconda on Fri Oct 22 21:28:51 2021

帮助命令

man  命令man 命令  查看命令的帮助信息
man  配置文件查看配置文件的帮助内容
命令 --help也是可以查看帮助命令

安装man命令前要提前安装好库,一共一条语句:

、sudo yum install man-pape

1、man 命令  查看命令的帮助信息

[root@localhost ~]# man ls  #就能查看ls这个命令的使用法内容

 2、man  配置文件    查看配置文件的帮助内容

[root@localhost ~]# man services  #就能查看services这个文档的帮助内容

3、


[root@localhost ~]# whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz
# 1.gz  是指命令帮助信息
# 5.gz  是指配置文件帮助信息

3.1 如果直接man passwd   它就会优先显示passwd的命令帮助信息

[root@localhost ~]# man passwd

3.2 想要显示配置文件信息可以这样做

[root@localhost ~]# man 5 passwd  #因为5是配置文件信息,声明一下

4、命令 --help 查看命令帮助

[root@localhost ~]# ls --help

用户管理命令

管理员可以更改任何人的密码;而普通用户只能更改自己的密码;

useradd增加用户
passwd更改密码
who查看有谁在登陆linux

1、who  查看谁登陆服务器


[yangmi@localhost ~]$ who
root     tty1         2021-10-25 19:19       #tty1  表示本地登录
root     pts/0        2021-10-25 19:19 (192.168.32.1)    #pts1  表示远程登陆1  登录时间  登陆ip地址
yangmi   pts/1        2021-10-25 21:41 (192.168.32.1)    #pts2  表示远程登陆2  登录时间  登陆ip地址

2、w  这个命令可以详细查看用户登录信息


[yangmi@localhost ~]$ w
 21:56:38 up  2:41,  3 users,  load average: 0.08, 0.03, 0.05  #
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty1                      19:19    2:37m  0.12s  0.12s -bash
root     pts/0    192.168.32.1     19:19   12:30   6.73s  6.73s -bash
yangmi   pts/1    192.168.32.1     21:41    6.00s  1.56s  1.20s w

文件压缩命令

在linux和windows之间共用的压缩后缀名是 .zip

gzip  文件文件压缩命令(压缩后源文件没有了,只有压缩包) 不可压缩目录  gz  文件名
gunzip  压缩文件解压文件
tar  可以压缩文件和目录(能保留源文件)tar -cvzf  文件名.tar.gz  要打包的目录(打包并压缩目录或文件)  -c 表示打包;-v 表示打包什么内容; -z 表示打包后并压缩;-f 表示指定文件名(f一定要放在最后)
tar  可以压缩文件和目录(能保留源文件)tar -xvzf  文件名.tar.gz     -x表示解压;-v 表示打包什么内容; -z 表示打包后并压缩;-f 表示指定文件名(f一定要放在最后)
zip  压缩(能保留源文件)

zip  文件名.zip  要压缩的文件 

(压缩目录:zip  -r  文件名.zip  要压缩的文件)

unzip  解压(能保留源文件)unzip 压缩包
bzip2bzip2  -k  文件名     -k保留原文件压缩
bunzip2  解压bunzip 文件名.bz2
bzip2  (一般用于压缩大文件)

tar  -cvjf  文件名.tar.bz2  文件名

(与tar对比就是 -cvzf变成了-cvjf)

bunzip2 解压tar -xvjf  文件名.tar.bz2

1、gzip  文件  文件压缩命令  不可压缩目录


[root@localhost mxh]# gzip mxhtest
[root@localhost mxh]# ls -il
总用量 4
51042136 -rw-r--r--. 1 root root 28 10月 24 10:07 mxhtest.gz

2、gunzip  压缩文件 解压文件


[root@localhost mxh]# ls -l
总用量 4
-rw-r--r--. 1 root root 26 10月 26 19:08 1.pid.gz
[root@localhost mxh]# gunzip 1.pid.gz
[root@localhost mxh]# ls -l
总用量 0
-rw-r--r--. 1 root root  0 10月 26 19:08 1.pid

3、tar   (打包并压缩)

-c 表示打包;-v 表示打包什么内容; -z 表示打包后并压缩;-f 表示指定文件名(f一定要放在最后)

[root@localhost mxh]# ls
1.pid  Mxh3  mxhtest.soft  test1  xxx  xxx.tar.gz
[root@localhost mxh]# ls xxx
1  2  3.4
[root@localhost mxh]# tar -cvzf xxx.tar.gz xxx
xxx/                          打包后的文件名  要打包的文件
xxx/1/
xxx/1/2/
xxx/1/2/3/
xxx/2/
xxx/3.4/
[root@localhost mxh]# ls
1.pid  Mxh3  mxhtest.soft  test1  xxx  xxx.tar.gz

4、tar (解压)    -x表示解压;-v 表示打包什么内容; -z 表示打包后并压缩;-f 表示指定文件名(f一定要放在最后)


[root@localhost mxh]# ls
1.pid  Mxh3  mxhtest.soft  test1  xxx.tar.gz
[root@localhost mxh]# tar -xvzf xxx.tar.gz      # x表示解压
xxx/
xxx/1/
xxx/1/2/
xxx/1/2/3/
xxx/2/
xxx/3.4/
[root@localhost mxh]# ls
1.pid  Mxh3  mxhtest.soft  test1  xxx  xxx.tar.gz
[root@localhost mxh]# ls xxx
1  2  3.4

5、zip      zip  文件名.zip  要压缩的文件 (压缩目录:zip  -r  文件名.zip  要压缩的文件)(能保留源文件)  安装zip命令:yum install zip


[root@localhost mxh]# ls                    #压缩
1.pid  Mxh3  mxhtest.soft  test1  xxx
[root@localhost mxh]# zip -r xxx.zip xxx
  adding: xxx/ (stored 0%)
  adding: xxx/1/ (stored 0%)
  adding: xxx/1/2/ (stored 0%)
  adding: xxx/1/2/3/ (stored 0%)
  adding: xxx/1/2/3/1.pid (stored 0%)
  adding: xxx/1/2/2.pid (stored 0%)
  adding: xxx/2/ (stored 0%)
  adding: xxx/3.4/ (stored 0%)

[root@localhost mxh]# unzip xxx.zip         #解压
Archive:  xxx.zip
   creating: xxx/
   creating: xxx/1/
   creating: xxx/1/2/
   creating: xxx/1/2/3/
 extracting: xxx/1/2/3/1.pid
 extracting: xxx/1/2/2.pid
   creating: xxx/2/
   creating: xxx/3.4/
[root@localhost mxh]# ls
1.pid  Mxh3  mxhtest.soft  test1  xxx  xxx.zip

6、bzip2  (一般用于压缩大文件)    tar  -cvjf  文件名.tar.bz2  文件名(与tar对比就是 -cvzf变成了-cvjf)    先安装bzip2命令:yum install bzip2


1.pid  Mxh3  mxhtest.soft  test1  xxx  xxx.tar.gz   #压缩xxx
[root@localhost mxh]# tar -cvjf xxx.tar.bz2 xxx
xxx/
xxx/1/
xxx/1/2/
xxx/1/2/3/
xxx/1/2/3/1.pid
xxx/1/2/2.pid
xxx/2/
xxx/3.4/
[root@localhost mxh]# ls
1.pid  Mxh3  mxhtest.soft  test1  xxx  xxx.tar.bz2  xxx.tar.gz

网络命令

write  用户名

write  用户名  直接写信给用户  ,ctrl+D进行保存

wall  写信内容直接进行所有用户广播
pingping  -c  次数  IP

1、write  用户名  直接写信给用户  ,ctrl+D进行保存

[mxh2@localhost ~]$ write root                #写给超级用户
write: root is logged in more than once; writing to pts/1
maixiuhu


[root@localhost ~]#                        #超级用户这边已经收到
Message from mxh2@localhost.localdomain on pts/0 at 22:26 ...
maixiuhu
EOF

2、wall  写信内容  直接进行所有用户广播

[root@localhost ~]# wall mxh yijing you nanpy!
[root@localhost ~]#
Broadcast message from root@localhost.localdomain (pts/1) (Tue Oct 26 22:35:03 2021):

mxh yijing you nanpy!              #首先自己也能收到


[mxh2@localhost ~]$                 #mxh2这个用户也能收到
Broadcast message from root@localhost.localdomain (pts/1) (Tue Oct 26 22:35:03 2021):

mxh yijing you nanpy!

3、ping -c 次数 IP


[mxh2@localhost ~]$ ping -c 4 192.168.32.1
PING 192.168.32.1 (192.168.32.1) 56(84) bytes of data.
64 bytes from 192.168.32.1: icmp_seq=1 ttl=128 time=2.67 ms
64 bytes from 192.168.32.1: icmp_seq=2 ttl=128 time=1.31 ms
64 bytes from 192.168.32.1: icmp_seq=3 ttl=128 time=0.852 ms
64 bytes from 192.168.32.1: icmp_seq=4 ttl=128 time=0.931 ms

--- 192.168.32.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 0.852/1.441/2.670/0.731 ms

lastlast命令能够查看登录用户,以及重启时间
lastlog查看所有用户最后一次登陆的时间
netstat  -ltun查看本机监听的端口
netstat  -an查看本机连接的所有网络连接
netstat  -rn查看本机路由表

1、last命令查看用户登录详细情况,包括系统重启时间


[mxh2@localhost ~]$ last
mxh2     pts/2        192.168.32.3     Wed Oct 27 21:32   still logged in
yangmi   pts/4        192.168.32.3     Wed Oct 27 21:27 - 21:30  (00:03)
root     pts/3        192.168.32.3     Wed Oct 27 21:18   still logged in
mxh2     pts/2        192.168.32.3     Wed Oct 27 21:18 - 21:30  (00:12)
mxh2     pts/1        192.168.32.3     Wed Oct 27 19:05   still logged in
root     pts/0        192.168.32.3     Wed Oct 27 19:05   still logged in
root     tty1                          Wed Oct 27 19:04   still logged in
reboot   system boot  3.10.0-1160.el7. Wed Oct 27 19:03 - 21:33  (02:29)
mxh2     pts/0        192.168.32.3     Wed Oct 27 11:31 - crash  (07:32)
root     pts/2        192.168.32.3     Wed Oct 27 11:30 - crash  (07:32)
mxh2     pts/1        192.168.32.3     Wed Oct 27 11:23 - 11:30  (00:07)
root     pts/0        192.168.32.3     Wed Oct 27 11:23 - 11:30  (00:07)
root     tty1                          Wed Oct 27 11:22 - crash  (07:40)
reboot   system boot  3.10.0-1160.el7. Wed Oct 27 11:21 - 21:33  (10:11)

2、lastlog 查看所有用户最后一次登陆的时间

[mxh2@localhost ~]$ lastlog
用户名           端口     来自             最后登陆时间
root             pts/3    192.168.32.3     三 10月 27 21:18:25 +0800 2021
bin                                        **从未登录过**
daemon                                     **从未登录过**
adm                                        **从未登录过**
mxh2             pts/2    192.168.32.3     三 10月 27 21:32:38 +0800 2021
yangmi           pts/4    192.168.32.3     三 10月 27 21:27:28 +0800 2021

3、netstat -ltun  查看本机监听的端口(TCP 相当于打电话;UDP相当于发短信;TCP有监听,PDp没有监听)


[root@localhost ~]# netstat -ltun
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 ::1:25                  :::*                    LISTEN
udp        0      0 127.0.0.1:323           0.0.0.0:*
udp6       0      0 ::1:323                 :::*

4、netstat -an   查看本机所有的网络连接

[root@localhost ~]# netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN
tcp        0      0 192.168.32.111:22       192.168.32.3:10190      ESTABLISHED #表示正在连接 和netstat -lutn的区别就在这
tcp        0      0 192.168.32.111:22       192.168.32.3:4371       ESTABLISHED
tcp        0      0 192.168.32.111:22       192.168.32.3:7340       ESTABLISHED
tcp        0      0 192.168.32.111:22       192.168.32.3:4376       ESTABLISHED
tcp        0      0 192.168.32.111:22       192.168.32.3:9658       ESTABLISHED
tcp        0      0 192.168.32.111:22       192.168.32.3:4377       ESTABLISHED
tcp        0     48 192.168.32.111:22       192.168.32.3:10189      ESTABLISHED
tcp        0      0 192.168.32.111:22       192.168.32.3:7337       ESTABLISHED
tcp        0      0 192.168.32.111:22       192.168.32.3:4370       ESTABLISHED
tcp        0      0 192.168.32.111:22       192.168.32.3:8178       ESTABLISHED
tcp        0      0 192.168.32.111:22       192.168.32.3:9656       ESTABLISHED
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 ::1:25                  :::*                    LISTEN
udp        0      0 192.168.32.111:47888    84.16.73.33:123         ESTABLISHED
udp        0      0 127.0.0.1:323           0.0.0.0:*
udp6       0      0 ::1:323                 :::*
raw6       0      0 :::58                   :::*   

5、netstat -rn 查看路由表


[root@localhost ~]# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.32.1    0.0.0.0         UG        0 0          0 ens33
192.168.32.0    0.0.0.0         255.255.255.0   U         0 0          0 ens33
mount  -t  文件系统  设备文件名  挂载点

1、mount  -t  文件系统  设备文件名  挂载点

        (1)先在/mnt目录下建立一个空目录cdrom  ;   /mnt这个目录用于挂载的目录


[root@localhost mnt]# mkdir cdrom
[root@localhost mnt]# ls
cdrom

        (2)# mount -t iso9660 /dev/sr0 /mnt/新建的目录   只有新建的目录要改,其他都是固定格式

[root@localhost mnt]# mount -t iso9660 /dev/sr0 /mnt/cdrom
mount: /dev/sr0 写保护,将以只读方式挂载

# mount -t iso9660 /dev/sr0 /mnt/新建的目录   只有新建的目录要改,其他都是固定格式

        (3)打开挂载好的目录后可以看见iso文件里的东西


[root@localhost mnt]# ls -l cdrom
总用量 696
-rw-r--r--.  3 root root     14 10月 30 2020 CentOS_BuildTag
drwxr-xr-x.  3 root root   2048 10月 27 2020 EFI
-rw-rw-r--. 21 root root    227 8月  30 2017 EULA
-rw-rw-r--. 21 root root  18009 12月 10 2015 GPL
drwxr-xr-x.  3 root root   2048 10月 27 2020 images
drwxr-xr-x.  2 root root   2048 11月  3 2020 isolinux
drwxr-xr-x.  2 root root   2048 10月 27 2020 LiveOS
drwxr-xr-x.  2 root root 673792 11月  4 2020 Packages
drwxr-xr-x.  2 root root   4096 11月  4 2020 repodata
-rw-rw-r--. 21 root root   1690 12月 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r--. 21 root root   1690 12月 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--.  1 root root   2883 11月  4 2020 TRANS.TBL

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值