显示主机名称:hostname
临时:hostname mrciong
永久:vi /etc/hostname 修改完重启后才能生效
hostnamectl set-hostname mrxiong-01 不需重启永久生效
[root@mrxiong ~]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core)
/etc/hosts 在本地建立IP地址和名称的对应关系
[root@mrxiong ~]# vi /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.100.129 mrxiong-work
[root@mrxiong ~]# ping 192.168.200.129 PING 192.168.200.129 (192.168.200.129) 56(84) bytes of data. 64 bytes from 192.168.200.129: icmp_seq=1 ttl=128 time=0.228 ms 64 bytes from 192.168.200.129: icmp_seq=2 ttl=128 time=0.493 ms ^X64 bytes from 192.168.200.129: icmp_seq=3 ttl=128 time=0.997 ms 64 bytes from 192.168.200.129: icmp_seq=4 ttl=128 time=0.932 ms [root@mrxiong ~]# ping mrxiong-work PING mrxiong-work (192.168.200.129) 56(84) bytes of data. 64 bytes from mrxiong-work (192.168.200.129): icmp_seq=1 ttl=128 time=0.325 ms 64 bytes from mrxiong-work (192.168.200.129): icmp_seq=2 ttl=128 time=1.02 ms 64 bytes from mrxiong-work (192.168.200.129): icmp_seq=3 ttl=128 time=0.991 ms 64 bytes from mrxiong-work (192.168.200.129): icmp_seq=4 ttl=128 time=0.297 ms 64 bytes from mrxiong-work (192.168.200.129): icmp_seq=5 ttl=128 time=0.351 ms
/etc/fstab ---实现存储设备开启自动挂载配置文件
[root@mrxiong ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Wed Sep 16 03:06:26 2020 # # 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 # UUID=e3b7d78c-f1fd-4006-b742-a83947c165d3 / xfs defaults 0 0 UUID=617f7de8-9482-458a-bcf7-e3faffa46b55 /boot xfs defaults 0 0 UUID=7f6d0ed2-1560-4ebe-9b0f-69d9f0956e44 swap swap defaults 0 0
/etc/rc.local 开机自动加载文件中的命令
[root@mrxiong ~]# cat /etc/rc.local #!/bin/bash # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES # # It is highly advisable to create own systemd services or udev rules # to run scripts during boot instead of using this file. # # In contrast to previous versions due to parallel execution during boot # this script will NOT be run after all other services. # # Please note that you must run ‘chmod +x /etc/rc.d/rc.local‘ to ensure # that this script will be executed during boot. touch /var/lock/subsys/local
centos7 /etc/rc.local指向的是rc.d/rc.local 其权限是-rw-r--r-- 没有可执行权限,所有无法开启执行这个文件
[root@mrxiong rc.d]# ls -l rc.local -rw-r--r--. 1 root root 473 Oct 31 2018 rc.local
我们需要给他授权一个可执行权限,命令如下:
[root@mrxiong rc.d]# ls -l /etc/rc.d/rc.local -rwxr-xr-x. 1 root root 473 Oct 31 2018 /etc/rc.d/rc.local
runlevel 查看当前系统运行级别
centos7 启动级别 target
00 系统的关机级别 init 0进入到关机状态
01 系统的单用户模式 用于修复系统或重置密码信息
02 系统多用户级别
03 系统的多用户模式 正常系统运行级别多用户模式级别
04 预留级别
05 图形化界面级别
06 系统的重启级别
查看centos7下的各运行级别对应的garget
[root@mrxiong-01 ~]# ls -l /usr/lib/systemd/system/runlevel*target lrwxrwxrwx. 1 root root 15 Sep 16 03:06 /usr/lib/systemd/system/runlevel0.target -> poweroff.target lrwxrwxrwx. 1 root root 13 Sep 16 03:06 /usr/lib/systemd/system/runlevel1.target -> rescue.target lrwxrwxrwx. 1 root root 17 Sep 16 03:06 /usr/lib/systemd/system/runlevel2.target -> multi-user.target lrwxrwxrwx. 1 root root 17 Sep 16 03:06 /usr/lib/systemd/system/runlevel3.target -> multi-user.target lrwxrwxrwx. 1 root root 17 Sep 16 03:06 /usr/lib/systemd/system/runlevel4.target -> multi-user.target lrwxrwxrwx. 1 root root 16 Sep 16 03:06 /usr/lib/systemd/system/runlevel5.target -> graphical.target lrwxrwxrwx. 1 root root 13 Sep 16 03:06 /usr/lib/systemd/system/runlevel6.target -> reboot.target
获取当前运行级别
[root@mrxiong-01 ~]# systemctl get-default multi-user.target
修改运行级别
[root@mrxiong-01 ~]# systemctl set-default rescue.target
临时调整级别
init 2 2是运行级别号
/etc/profile 让变量信息永久生效
source /etc/profile 重新加载文件令其生效
echo $PATH 查看环境变量
修改环境变量 $PATH
临时:[root@mrxiong-01 ~]# PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
永久:vi /etc/profile 在最后一行加入export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
source /etc/profile 重新加载文件令其生效
which cat 查看cat命令所在目录
alias 配置系统别名 如:ll ll是ls -l的别名
[root@mrxiong-01 ~]# alias alias cp=‘cp -i‘ alias egrep=‘egrep --color=auto‘ alias fgrep=‘fgrep --color=auto‘ alias grep=‘grep --color=auto‘ alias l.=‘ls -d .* --color=auto‘ alias ll=‘ls -l --color=auto‘ alias ls=‘ls --color=auto‘ alias mv=‘mv -i‘ alias rm=‘rm -i‘ alias which=‘alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde‘
设置命令的语法:
alias 别名名称=‘命令信息’
取消别名的方法:
unalias + 别名名称
临时取消别名:
1、/usr/bin/rm -rf /etc/centos.txt 使绝对路径忽略别名
2、\rm -rf /etc/centos.txt 使用\忽略别名
永久设置别名的方法:
1、vi /etc/profile
把别名添加到最后一行如:alias catnet=‘cat /etc/sysconfig/network-scripts/ifcfg-ens33‘
2、source /etc/profile 重新加载文件令其生效
修改别名
实验1:
如把cat /etc/sysconfig/network-scripts/ifcfg-ens33 ===> 设置别名为catnet
修改如下:
[root@mrxiong-01 ~]# alias catnet=‘cat /etc/sysconfig/network-scripts/ifcfg-ens33‘
查看修改后的内容
[root@mrxiong-01 ~]# alias alias catnet=‘cat /etc/sysconfig/network-scripts/ifcfg-ens33‘ alias cp=‘cp -i‘ alias egrep=‘egrep --color=auto‘ alias fgrep=‘fgrep --color=auto‘ alias grep=‘grep --color=auto‘ alias l.=‘ls -d .* --color=auto‘ alias ll=‘ls -l --color=auto‘ alias ls=‘ls --color=auto‘ alias mv=‘mv -i‘ alias rm=‘rm -i‘ alias which=‘alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde‘
实验2:
rm 命令执行 ==> echo "rm command is weixian,not use rm"
修改如下:
[root@mrxiong-01 ~]# alias rm=‘echo rm command is weixian,not use rm‘
默认家目录中的别名
[root@mrxiong-01 ~]# cd ~ [root@mrxiong-01 ~]# ls -a . anaconda-ks.cfg .bash_logout .bashrc .lesshst .viminfo .. .bash_history .bash_profile .cshrc .tcshrc [root@mrxiong-01 ~]# cat .bashrc # .bashrc # User specific aliases and functions alias rm=‘rm -i‘ alias cp=‘cp -i‘ alias mv=‘mv -i‘ # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi
总结:
01、/etc/profile == /etc/bashrc (全局生效)
02、~/.bashrc == ~/.bash_profile (指定用户生效)
原文:https://www.cnblogs.com/mr-xiong/p/13704546.html