CENTOS下的常用命令(二)

忘是亡心i 2023-10-08 15:59 132阅读 0赞
① 查看SElinux策略

getsebool命令是用来查询SElinux策略内各项规则的布尔值,如下三条命令都可以:

  1. getsebool -a
  2. getsebool -a | grep httpd_can_network_connect
  3. /usr/sbin/sestatus -v
② 查看日志
  1. # 查看未打包的日志
  2. tail -f -n 1000 error.log
  3. # 查看已打包的日志
  4. zcat error.log-20220509.gz
③ VIM如何显示行号
  1. 1. 临时显示行号
  2. 只须按ESC键退出编辑内容模式, 输入":set number" 或者 ":set nu" 后按回车键,就可以显示行号了。
  3. 行号显示只是暂时的,退出vim后再次打开vim就不显示行号了。
  4. 取消显示行号:输入":set nonu"
  5. 2. 永久显示行号
  6. 需要修改vim配置文件vimrc
  7. 在默认情况下用户宿主目录(~)中是没有此文件的,需要在当前用户的宿主目录中手工建立,即使用下面的命令:
  8. vim ~/.vimrc
  9. 在打开的vimrc文件中最后一行输入:set number 或者 set nu, 然后保存退出。
  10. 再次用vim打开文件时,就会显示行号了。
④ /etc/profile 和 /etc/profile.d的区别和用法
  1. 区别:
    (1). /etc/profile是文件,/etc/profile.d/是目录;
    (2). 都用于设置环境变量,/etc/profile是永久性的环境变量,是全局变量;/etc/profile.d/ 设置所有用户生效的环境变量;
    (2). /etc/profile.d/比/etc/profile好维护,不想要什么变量直接删除/etc/profile.d/下对应的shell脚本即可,不用像/etc/profile需要改动此文件。
  2. 用法:
    在/etc/profile.d/ 目录下创建一个对应的SHELL脚本,如:rills-common.sh 脚本,脚本内容如下:

    [root@hm profile.d]# pwd
    /etc/profile.d
    [root@hm profile.d]# ll
    总用量 76
    -rw-r—r—. 1 root root 771 11月 17 2020 256term.csh
    -rw-r—r—. 1 root root 841 11月 17 2020 256term.sh
    -rw-r—r—. 1 root root 69 1月 11 2018 apache-maven.csh
    -rw-r—r—. 1 root root 88 1月 11 2018 apache-maven.sh
    -rw-r—r—. 1 root root 196 3月 25 2017 colorgrep.csh
    -rw-r—r—. 1 root root 201 3月 25 2017 colorgrep.sh
    -rw-r—r—. 1 root root 1741 11月 16 2020 colorls.csh
    -rw-r—r—. 1 root root 1606 11月 16 2020 colorls.sh
    -rw-r—r—. 1 root root 80 4月 1 2020 csh.local
    -rw-r—r—. 1 root root 1706 11月 17 2020 lang.csh
    -rw-r—r—. 1 root root 2703 11月 17 2020 lang.sh
    -rw-r—r—. 1 root root 123 7月 31 2015 less.csh
    -rw-r—r—. 1 root root 121 7月 31 2015 less.sh
    -rw-r—r— 1 root root 251 6月 2 12:19 rills-common.sh
    -rw-r—r—. 1 root root 81 4月 1 2020 sh.local
    -rw-r—r—. 1 root root 105 12月 16 2020 vim.csh
    -rw-r—r—. 1 root root 269 12月 16 2020 vim.sh
    -rw-r—r—. 1 root root 164 1月 28 2014 which2.csh
    -rw-r—r—. 1 root root 169 1月 28 2014 which2.sh
    [root@hm profile.d]# cat rills-common.sh

    1. SET JAVA ENVIRONMENT

    JAVA_HOME=/opt/software/jdk1.8.0_251
    JRE_HOME=$JAVA_HOME/jre
    CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
    PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
    export JAVA_HOME JRE_HOME CLASS_PATH PATH

    [root@hm profile.d]#

执行刷新指令:

  1. source /etc/profile
  1. 原因:
    /etc/profile.d/目录下的脚本文件之所以能够被自动执行,是因为在/etc/profile文件中使用一个FOR循环语句来调用这些脚本,如下:


    export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL

    By default, we want umask to get set. This sets it for login shell

    Current threshold for system reserved uid/gids is 200

    You could check uidgid reservation validity in

    /usr/share/doc/setup-*/uidgid file

    if [ $UID -gt 199 ] && [ “/usr/bin/id -gn“ = “/usr/bin/id -un“ ]; then

    1. umask 002

    else

    1. umask 022

    fi

    // 加载profile.d下的文件
    for i in /etc/profile.d*.sh /etc/profile.d/sh.local ; do

    1. if [ -r "$i" ]; then
    2. if [ "${-#*i}" != "$-" ]; then
    3. . "$i"
    4. else
    5. . "$i" >/dev/null
    6. fi
    7. fi

    done

    unset i
    unset -f pathmunge

发表评论

表情:
评论列表 (有 0 条评论,132人围观)

还没有评论,来说两句吧...

相关阅读

    相关 CentOS命令

    关键字: linux 查进程、杀进程、起进程 1.查进程     ps命令查找与进程相关的PID号:     ps a 显示现行终端机下的所有程序,包括其他用户的程