- 修改服务器名称为 linux01
# 方法一
[root@localhost ~]# hostnamectl set-hostname linux01
# 方法二
[root@localhost ~]# vim /etc/hostname
# 方法三 修改内核,优先级最高
[root@localhost ~]# vim /etc/sysctl.conf
kernel.hostname = linux01
# 方法四 Centos5/6(Centos7不建议)
[root@localhost ~]# vim /etc/sysconfig/network
hostname linux01
# 临时修改
[root@localhost ~]# hostname linux01
-
系统运行级别 分别说下:
init级别 systemctl target 注释 0 shutdown.target 系统停机状态 1 emergency.target 单用户工作状态 2 rescure.target 多用户状态(没有NFS) 3 multi-user.target 多用户状态(有NFS) 4 无 系统未使用,留给用户 5 graphical.target 图形界面 6 无 系统正常关闭并重新启动 -
查看当前级别:
[root@localhost ~]# runlevel
N 3
# N代表在进入这个级别前,上一个级别是什么;3代表当前级别
[root@linux01 ~]# systemctl get-default
multi-user.target
# multi-user.target等于运行级别3
- 修改当前运行级别:
# 临时修改
# 方法一
[root@localhost ~]# init 3
# 方法二
[root@localhost ~]# systemctl isolate multi-user.target
# 设置默认运行级别
# 方法一
[root@localhost ~]# vim /etc/inittab
# Centos7默认没有,不建议在Centos7中,使用该方法
id:3:initdefault
# 方法二
[root@localhost ~]# systemctl set-default multi-user.target
- 如何在不重启得情况下,将centos7从图形界面调成字符界面?
ctrl+alt+f3
- 更改默认yum 源为阿里云源
# ① 备份
[root@localhost ~]# cd /etc/yum.repos.d/ | mkdir back | mv * back
# ② 下载阿里源repo
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# ③ 清除之前yum缓存
[root@localhost ~]# yum clean all
# ④ 生成新的yum源缓存
[root@localhost ~]# yum makecache
- 使用yum不能安装软件如何排查
# 一、检查网络是否正确设置
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
# 推荐使用静态ip
IPADDR=YOUR IP
NETMASK=YOUR MASK
GATEWAY=YOUR WAY
# 第二步没有做的话,需要在此处设置下DNS
DNS1=8.8.8.8
DNS2=114.114.114.114
[root@localhost ~]# systemctl restart network
[root@localhost ~]# ifconfig
# 二、检测dns是否设置
[root@localhost ~]# vim /etc/resolv.conf
nameserver 8.8.8.8
nameserver 114.114.114.114
# 三、检查hosts文件,是否被恶意修改
[root@localhost ~]# vim /etc/hosts
-
find使用方法:
# 根据文件大小查找 命令 # 搜索小于6M的文件 -6M +6M大于6M 6M等于6M [root@linux01 ~]# find /root -type f -size -6M # 根据文件权限查找数据 # 查找权限等于777的文件 [root@linux01 ~]# find /root -type f -perm 777 # 查找权限不是777的文件 [root@linux01 ~]# find /root -type f ! -perm 777
-
把 abc压缩成格式如 2022-12-01.abc.tar.gz
[root@linux01 ~]# tar -zcvf $( date +%F ).abc.tar.gz abc
-
解压如上文件
[root@linux01 ~]# tar -zxvf 2022-12-01.abc.tar.gz
-
美元符号:$ 表达什么:!作用:| 作用:xargs作用:
# $符号 # 一、$()、``(反引号) 可以作为命令替换,推荐使用$(),例 [root@linux01 ~]# tar -zcvf $( date +%F ).abc.tar.gz abc [root@linux01 ~]# tar -zcvf `date +%F`.abc.tar.gz abc # 二、${ }变量替换 # $var与${var}是没有区别的,但是用${ }会比较精确的界定变量名称的范围 [root@localhost ~]# A=Linux [root@localhost ~]# echo $AB #表示变量AB [root@localhost ~]# echo ${A}B #表示变量A后连接着B LinuxB # 取路径、文件名、后缀 [root@localhost ~]# file=/dir1/dir2/dir3/my.file.txt [root@linux01 ~]# echo ${file#*/} # 拿掉第一条 / 及其左边的字符串 dir1/dir2/dir3/my.file.txt [root@linux01 ~]# echo ${file##*/} # 拿掉最后一条 / 及其左边的字符串 my.file.txt [root@linux01 ~]# echo ${file%/*} # 拿掉最后一条 / 及其右边的字符串 /dir1/dir2/dir3 [root@linux01 ~]# echo ${file%%/*} # 拿掉第一条 / 及其右边的字符串 (空值) # 取子串及替换 [root@linux01 ~]# echo ${file:0:5} # 提取最左边的 5 个字节 /dir1 [root@linux01 ~]# echo ${file:5:5} # 提取第 5 个字节右边的连续 5 个字节 /dir2 [root@linux01 ~]# echo ${file/dir/path} # 将第一个 dir 提换为 path /path1/dir2/dir3/my.file.txt [root@linux01 ~]# echo ${file//dir/path} # 将全部 dir 提换为 path /path1/path2/path3/my.file.txt [root@linux01 ~]# echo ${#file} # 获取变量长度 27 # 二、!作用 # 运行history中的命令 [root@linux01 ~]# history ... 259 echo ${#file} 260 history [root@linux01 ~]# !259 echo ${#file} 27 # !-6 执行history中,倒数第六个命令 # [ ! -d dir ]检查目录是否存在 # ! 逻辑否 [root@linux01 ~]# rm -rf !(*.txt) # 删除非txt结尾的文件 # !ls之前上一次执行的ls命令 # !$表示上一个命令的参数 # |作用 # 管道符Command A | Command B 将前A命令的输出作为B命令的输入 # xargs作用 # xargs 最重要的作用是以空格或者换行作为分隔符,把标准输入转化成多个命令行参数 # xargs -i -i 参数直接用 {}就能代替管道之前的标准输出的内容
-
查找指定数据信息进行复制 查找出*.txt文件,批量复制到/tmp目录*
[root@linux01 ~]# find /root/ -name '*.txt' -type f| xargs -i cp {} /tmp [root@linux01 test]# find ./ -name "*.txt" -type f -exec cp {} tmp/ \;
-
查找指定数据信息进行移动 查找出*.txt文件,批量移动到/tmp目录
[root@linux01 ~]# find /root -name "*.txt" -type f | xargs -i mv {} /tmp [root@linux01 test]# find ./ -name "*.txt" -type f -exec mv {} tmp/ \;
-
将以abc开头的行找出来?
```bash
[root@linux01 test]# cat test.txt |grep "^abc"
```
-
将以linux结尾的行找出来?
[root@linux01 test]# cat test.txt |grep "linux$"
-
将全部内容显示,但不要显示空行
[root@linux01 test]# cat test.txt |grep -v "^$"
-
利用linux什么命令真正统计目录的大小?
[root@linux01 test]# du -h