Linux基础题目

  1. 修改服务器名称为 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
  1. 系统运行级别 分别说下:

    init级别systemctl target注释
    0shutdown.target系统停机状态
    1emergency.target单用户工作状态
    2rescure.target多用户状态(没有NFS)
    3multi-user.target多用户状态(有NFS)
    4系统未使用,留给用户
    5graphical.target图形界面
    6系统正常关闭并重新启动
  2. 查看当前级别:

[root@localhost ~]# runlevel
N 3
# N代表在进入这个级别前,上一个级别是什么;3代表当前级别
[root@linux01 ~]# systemctl get-default
multi-user.target
# multi-user.target等于运行级别3
  1. 修改当前运行级别:
# 临时修改
# 方法一
[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
  1. 如何在不重启得情况下,将centos7从图形界面调成字符界面?
ctrl+alt+f3
  1. 更改默认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
  1. 使用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
  1. 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
    
  2. 把 abc压缩成格式如 2022-12-01.abc.tar.gz

    [root@linux01 ~]# tar -zcvf $( date +%F ).abc.tar.gz abc
    
  3. 解压如上文件

    [root@linux01 ~]# tar -zxvf 2022-12-01.abc.tar.gz
    
  4. 美元符号:$ 表达什么:!作用:| 作用: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 参数直接用 {}就能代替管道之前的标准输出的内容
    
  5. 查找指定数据信息进行复制 查找出*.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/ \;
    
  6. 查找指定数据信息进行移动 查找出*.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/ \;
    
  7. 将以abc开头的行找出来?

```bash
[root@linux01 test]# cat test.txt |grep "^abc"
```
  1. 将以linux结尾的行找出来?

    [root@linux01 test]# cat test.txt |grep "linux$"
    
  2. 将全部内容显示,但不要显示空行

    [root@linux01 test]# cat test.txt |grep -v "^$"
    
  3. 利用linux什么命令真正统计目录的大小?

    [root@linux01 test]# du -h
    
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值