Linux 工作常用命令(四)解释!(图文并茂)

Linux 工作常用命令(四)解释!(图文并茂)

  1.  export	设置变量	export test=/home/lgb
    

export PATH=$PATH:/usr/local/mysql/bin
export -p

  1.  unset 	清除环境变量	unset test
    

场景:比如你需要安全oracle这个数据库或者说安装JAVA相关的软件时,你需要导入环境变量路径,那么需要这个命令

[root@localhost tmp]# export test=/home
[root@localhost tmp]#
[root@localhost tmp]#
[root@localhost tmp]#
[root@localhost tmp]# echo $test
/home
[root@localhost tmp]# unset test
[root@localhost tmp]# echo $test

[root@localhost tmp]#

  1.  chkconfig	管理服务软件自启	chkconfig --level 35 mysqld on 
    

chkconfig --list

场景:有时候,我们需要开机自动重启程序。

[root@localhost tmp]# chkconfig --level 35 NetworkManager
only one runlevel may be specified for a chkconfig query
[root@localhost tmp]#
[root@localhost tmp]# chkconfig --level 35 sshd
only one runlevel may be specified for a chkconfig query
[root@localhost tmp]#
[root@localhost tmp]#
[root@localhost tmp]#
[root@localhost tmp]# systemctl enable sshd
[root@localhost tmp]#

[root@localhost tmp]# chkconfig --list

Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.

  If you want to list systemd services use 'systemctl list-unit-files'.
  To see services enabled on particular target use
  'systemctl list-dependencies [target]'.

netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost tmp]#
[root@localhost tmp]# chkconfig --level 35 network
only one runlevel may be specified for a chkconfig query
[root@localhost tmp]# chkconfig --level 135 network
only one runlevel may be specified for a chkconfig query
[root@localhost tmp]# chkconfig --level 1 network
[root@localhost tmp]#
[root@localhost tmp]#
[root@localhost tmp]# chkconfig --level 3 network
[root@localhost tmp]#
[root@localhost tmp]#
[root@localhost tmp]# chkconfig --level 35 network
only one runlevel may be specified for a chkconfig query
[root@localhost tmp]# chkconfig --level 3 5 network
chkconfig version 1.3.61 - Copyright © 1997-2000 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.

usage: chkconfig [–list] [–type ] [name]
chkconfig --add
chkconfig --del
chkconfig --override
chkconfig [–level ] [–type ] <on|off|reset|resetpriorities>
[root@localhost tmp]# chkconfig --level 5 network
[root@localhost tmp]#
[root@localhost tmp]#

  1.  runlevel	显示系统当前运行级别	runlevel
    

[root@localhost tmp]# runlevel
N 3
[root@localhost tmp]#

  1.  getenforce	查看selinux的运行状态	getenforce
    

它这个属于系统级别的安全
场景:有时候我们一些服务无法使用,比如我们的FTP,所以作为初学者,我们需要去关闭selinux。
[root@localhost tmp]# getenforce
Enforcing
[root@localhost tmp]#

从上面可知selinux是开启的,那么需要去关闭掉,否则会对初学者易用性太差。
6. setenforce 关闭或者开启selinux
开启后,导致文件权限修改不了等问题,下面就是关闭设置setlinux的方法

[root@localhost tmp]# getenforce
Enforcing
[root@localhost tmp]# setenforce 0
[root@localhost tmp]#
[root@localhost tmp]#
[root@localhost tmp]# getenforce
Permissive
[root@localhost tmp]#

7. init 修改系统运行级别 重启系统:Init 6、关闭系统:init 0

我建议用这个命令进行开关机,因为它代表了系统运行级别的内容。

  1.  service	管理服务	 service httpd start
    

[root@localhost tmp]# service sshd start
Redirecting to /bin/systemctl start sshd.service
[root@localhost tmp]#
[root@localhost tmp]#
[root@localhost tmp]#

  1.  netstat	查看服务端口	netstat -anp
    

netstat -apn |grep 8080

场景:我们经常安装一些网络程序,有时候会查看看端口号及状态,特别有用。

Linux 工作常用命令(四)解释!(图文并茂)

  1. mount	挂载设备	Cd /mnt
    

mkdir -p /mnt/cdrom
mount -t auto /dev/cdrom /mnt/cdrom

场景:挂载U盘你的LINUX里面,还有需要挂载光驱到系统里面。
我们可以这样去想象:镜像ISO,就好比光盘;设备状态,就好比连接光驱或者弹出光驱。

Linux 工作常用命令(四)解释!(图文并茂)

[root@localhost /]# mkdir -p /mnt/cdrom
[root@localhost /]#
[root@localhost /]#
[root@localhost /]#
[root@localhost /]# mount -t auto /dev/cdrom /mnt/cdrom
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost /]# cd /mnt/cdrom/
[root@localhost cdrom]# ls
CentOS_BuildTag EFI EULA GPL images isolinux LiveOS Packages repodata RPM-GPG-KEY-CentOS-7 RPM-GPG-KEY-CentOS-Testing-7 TRANS.TBL
[root@localhost cdrom]#

[root@localhost cdrom]# cd Packages/
[root@localhost Packages]# rpm -ivh ne
neon-0.30.0-3.el7.x86_64.rpm nepomuk-widgets-4.10.5-3.el7.x86_64.rpm netpbm-progs-10.61.02-9.el7.x86_64.rpm net-snmp-devel-5.7.2-24.el7.x86_64.rpm nettle-devel-2.7.1-4.el7.x86_64.rpm
nepomuk-core-4.10.5-5.el7.x86_64.rpm netcf-libs-0.2.8-1.el7.x86_64.rpm netsniff-ng-0.5.8-6.el7.x86_64.rpm net-snmp-libs-5.7.2-24.el7.x86_64.rpm net-tools-2.0-0.17.20131004git.el7.x86_64.rpm
nepomuk-core-devel-4.10.5-5.el7.x86_64.rpm netlabel_tools-0.20-5.el7.x86_64.rpm net-snmp-5.7.2-24.el7.x86_64.rpm net-snmp-utils-5.7.2-24.el7.x86_64.rpm newt-0.52.15-4.el7.x86_64.rpm
nepomuk-core-libs-4.10.5-5.el7.x86_64.rpm netpbm-10.61.02-9.el7.x86_64.rpm net-snmp-agent-libs-5.7.2-24.el7.x86_64.rpm nettle-2.7.1-4.el7.x86_64.rpm newt-python-0.52.15-4.el7.x86_64.rpm
[root@localhost Packages]# rpm -ivh net-tools-2.0-0.17.20131004git.el7.x86_64.rpm
Preparing… ################################# [100%]
Updating / installing…
1:net-tools-2.0-0.17.20131004git.el################################# [100%]
[root@localhost Packages]#

[root@localhost Packages]# netstat -anp
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 1410/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2517/master
tcp 0 48 192.168.92.128:22 192.168.92.1:1105 ESTABLISHED 2602/sshd: root@pts
tcp6 0 0 :::22 ::

上一篇:[Bash] Add Executable Files to $PATH with Bash


下一篇:CentOS 命令行 网络配置