0
点赞
收藏
分享

微信扫一扫

RHCSA学习第三天

c一段旅程c 2022-02-13 阅读 95

1、总结vim实用命令

命令模式:

^ 行首

$ 行尾

yy 复制

4yy 复制从光标开始一共四行内容

cc 剪切

4cc 剪切从光标开始一共四行内容

p 粘贴(粘贴在光标所在的下一行)

末行模式 :

:q 退出

:w 保存

:10 跳转到第十行

:%s %匹配符

插入模式:

o 进入插入模式,在光标的下一行添加内容

O 进入插入模式,在光标的上一行添加内容

a 在光标后插入内容

2.文件管理命令练习

在/opt目录下创建一个临时目录tmp;

在临时目录下创建一个文件,文件名为a.txt;

将a.txt复制成b.txt;将b.txt改名成为c.txt;

创建符号链接,链接文件名为linkc.txt;

[root@localhost ~]# mkdir -p /opt/tmp
 
[root@localhost ~]# touch /opt/tmp a.txt
 
[root@localhost ~]# cp /opt/tmp/a.txt /opt/tmp/b.txt
cp: cannot stat '/opt/tmp/a.txt': No such file or directory
[root@localhost ~]# cp /opt/tmp/a.txt /opt/tmp/b.txt -p
cp: cannot stat '/opt/tmp/a.txt': No such file or directory
[root@localhost ~]# cp -p  /opt/tmp/a.txt /opt/tmp/b.txt 
cp: cannot stat '/opt/tmp/a.txt': No such file or directory
[root@localhost ~]# ll /opt/tmp
total 0
[root@localhost ~]# touch /opt/tmp/a.txt
[root@localhost ~]# ll /opt/tmp
total 0
-rw-r--r--. 1 root root 0 Feb 13 06:32 a.txt
[root@localhost ~]# cp -p  /opt/tmp/a.txt /opt/tmp/b.txt 
[root@localhost ~]# ll /opt/tmp
total 0
-rw-r--r--. 1 root root 0 Feb 13 06:32 a.txt
-rw-r--r--. 1 root root 0 Feb 13 06:32 b.txt
[root@localhost ~]# mv /opt/tmp/b.txt /opt/tmp/c.txt
[root@localhost ~]# ll /opt/tmp
total 0
-rw-r--r--. 1 root root 0 Feb 13 06:32 a.txt
-rw-r--r--. 1 root root 0 Feb 13 06:32 c.txt
 
[root@localhost ~]# ln -s /opt/tmp/c.txt linkc.txt
[root@localhost ~]# ll
total 8
lrwxrwxrwx. 1 root root   14 Feb 13 06:35 linkc.txt -> /opt/tmp/c.txt
 

3、vi练习:完成如下步骤

1) 应用vi命令在/tmp文件夹下创建文件,文件名newfile。在newfile首行输入日期时间

2) 将/boot/grub2/grub.cfg文档的内容读入到newfile文档中(在日期的下一行即第2行)

3) 查找文档中包含#号字符的行,将整行删除

4) 开启VI的行号提示功能

5) 将光标移动到第5行,并在第5行后产生一新的空白行第6行

6) 修改内容。将所有的timeout=5,更改为time=30

7) 将整个文档中的所有root字符更改为admin字符

8) 复制第1行的日期时间内容到文档末

9)将文档保存,将文档再次另存为/boot/newfile2,退出VI编辑器

[root@localhost ~]# mkdir -p /tmp
[root@localhost ~]# touch /tmp/newfile
[root@localhost ~]# date > /tmp/newfile
[root@localhost ~]# cat /tmp/newfile
Sun Feb 13 06:47:38 EST 2022
 
 
[root@localhost ~]# cat /boot/grub2/grub.cfg > /tmp/newfile
[root@localhost ~]# cat /tmp/newfile
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
 
 
[root@localhost ~]# vi /tmp/newfile
 
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#
 
### BEGIN /etc/grub.d/00_header ###
set pager=1
 
if [ -f ${config_directory}/grubenv ]; then
  load_env -f ${config_directory}/grubenv
elif [ -s $prefix/grubenv ]; then
  load_env
fi
if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   set default="${saved_entry}"
fi
 
if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
:g/#
 
 
#
  if [ "${menu_show_once}" ]; then
    unset menu_show_once
    save_env menu_show_once
    set timeout_style=menu
    set timeout=60
  elif [ "${menu_auto_hide}" -a "${menu_hide_ok}" = "1" ]; then
    set orig_timeout_style=${timeout_style}
    set orig_timeout=${timeout}
    if [ "${fastboot}" = "1" ]; then
      set timeout_style=menu
      set timeout=0
    else
      set timeout_style=hidden
      set timeout=1
    fi
  fi
fi
 
 
 
 
 
 
if [ -f  ${config_directory}/custom.cfg ]; then
  source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg;
fi
 
 
    125   if [ "${menu_show_once}" ]; then
    126     unset menu_show_once
    127     save_env menu_show_once
    128     set timeout_style=menu
    129     set timeout=60
    130   elif [ "${menu_auto_hide}" -a "${menu_hide_ok}" = "1" ]; then
    131     set orig_timeout_style=${timeout_style}
    132     set orig_timeout=${timeout}
    133     if [ "${fastboot}" = "1" ]; then
    134       set timeout_style=menu
    135       set timeout=0
    136     else
    137       set timeout_style=hidden
    138       set timeout=1
    139     fi
    140   fi
    141 fi
    142 
    143 
    144 
    145 
    146 
    147 
    148 if [ -f  ${config_directory}/custom.cfg ]; then
    149   source ${config_directory}/custom.cfg
    150 elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
    151   source $prefix/custom.cfg;
    152 fi
:set nu
 
 
 
      1 
      2 set pager=1
      3 
      4 if [ -f ${config_directory}/grubenv ]; then
      5   load_env -f ${config_directory}/grubenv
      6 
      7 elif [ -s $prefix/grubenv ]; then
      8   load_env
      9 fi 
     10 if [ "${next_entry}" ] ; then
     11    set default="${next_entry}"
     12    set next_entry=
     13    save_env next_entry
     14    set boot_once=true
     15 else
     16    set default="${saved_entry}"
     17 fi
     18 
     19 if [ x"${feature_menuentry_id}" = xy ]; then
     20   menuentry_id_option="--id"
     21 else
     22   menuentry_id_option=""
     23 fi
     24 
     25 export menuentry_id_option
     26 
     27 if [ "${prev_saved_entry}" ]; then
     28   set saved_entry="${prev_saved_entry}"
先进入末行模式,然后输入5o,接着按o,再退出末行模式
 
 
 
     59   set time=30
     60 else
     61   set time=30
     62 fi
     63 
     64 set tuned_params=""
     65 set tuned_initrd=""
 
先进入末行模式,输入%s/timeout=50/time=30/g
 
     93   search --no-floppy --fs-uuid --set=admin ff7463e5-8537-4a9d-b465-29dfdb3ed8d5
     94 fi  
     95 insmod part_msdos
     96 insmod xfs 
     97 set boot='hd0,msdos1'
     98 if [ x$feature_platform_search_hint = xy ]; then
     99   search --no-floppy --fs-uuid --set=boot --hint='hd0,msdos1'  ff7463e5-8537-4a9d-b465-29dfdb3ed8d5
    100 else
    101   search --no-floppy --fs-uuid --set=boot ff7463e5-8537-4a9d-b465-29dfdb3ed8d5
    102 fi 
    103   
    104   
    105 if [ -z "${kernelopts}" ]; then
    106   set kernelopts="admin=/dev/mapper/rhel-admin ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/a        dmin rd.lvm.lv=rhel/swap rhgb quiet "
    107 fi
    108 
    109 insmod blscfg
    110 blscfg
    111 
    112 if [ "${boot_success}" = "1" -o "${boot_indeterminate}" = "1" ]; then
    113   set menu_hide_ok=1
    114 else
    115   set menu_hide_ok=0 
    116 fi  
    117 if [ "${boot_success}" = "1" ] ; then
    118   set boot_indeterminate=0
    119 elif [ "${boot_indeterminate}" = "1" ]; then
8 substitutions on 6 lines
方法如上
 
 
Sun Feb 13 07:24:53 EST 2022
Sun Feb 13 07:24:53 EST 2022
~                                                                                                                       
~                                                                                                                                                                                                                                         
:1 copy $
由于看到原本的文档里第一行没有时间,于是保存退出,再把时间导入到首行,进入文档后想起来是覆盖,所以展示出来是以上的样子
 
 
Sun Feb 13 07:24:53 EST 2022
Sun Feb 13 07:24:53 EST 2022
~                                                                                                                       
~                                                                                                                                                                                                                            
~                                                                                                                       
:wq /boot/newfile2
[root@localhost ~]# cat /boot/newfile2
Sun Feb 13 07:24:53 EST 2022
Sun Feb 13 07:24:53 EST 2022
 

4、文件查看
复制用户配置文件(/etc/passwd)到/opt目录下;
查看/opt/mima文件的第6行;

[root@localhost ~]# cp -a /etc/passwd /opt
[root@localhost ~]# ll /opt
total 4
-rw-r--r--. 1 root root 2554 Feb 10 14:42 passwd
[root@localhost ~]# head -3 /opt/passwd |tail -1
daemon:x:2:2:daemon:/sbin:/sbin/nologin

5.统计显示用户配置文件(/etc/passwd)nologin 出现的次数

[root@localhost ~]# cat /etc/passwd |grep  nologin|wc -l
41

6.显示系统共有多少用户

[root@localhost ~]# cat /etc/passwd | wc -l
46

7.将系统时间(时分秒)写入time文件

[root@localhost ~]# date -s 21:06:50
Sun Feb 13 21:06:50 EST 2022

8.history可以显示系统命令历史,统计当前系统命令频率最高的前三。(命令重复出现多的三个命令)

[root@localhost ~]# history
    1  cd
    2  cd /
    3  cd home
    4  cd redhat
    5  pwd
    6  cd ~
    7  pwd
    8  cd redhat
    9  cd /home/redhat
   10  pwd
   11  cls
   12  ll
   13  ifconfig
   14  ip a 
   15  mkdir -p /opt/tmp
   16  touch /opt/tmp a.txt
   17  cp /opt/tmp/a.txt /opt/tmp/b.txt
   18  cp /opt/tmp/a.txt /opt/tmp/b.txt -p
   19  cp -p  /opt/tmp/a.txt /opt/tmp/b.txt 
   20  ll /opt/tmp
   21  touch /opt/tmp/a.txt
   22  ll /opt/tmp
   23  cp -p  /opt/tmp/a.txt /opt/tmp/b.txt 
   24  ll /opt/tmp
   25  mv /opt/tmp/b.txt /opt/tmp/c.txt
   26  ll /opt/tmp
   27  ln -s c.txt linc.txt
   28  ll
   29  rm linc.txt
   30  ln -s /opt/tmp/c.txt linkc.txt
   31  ll
   32  rm linkc.txt
   33  rm /opt
   34  rm /opt -r
   35  ll
   36  rm a.txt
   37  ll
   38  rm /opt -r
   39  ll
   40  mkdir -p /tmp
   41  touch /tmp/newfile
   42  date
   43  vi
   44  ll /tmp/newfile
   45  vi
   46  vim /tmp/newfile
   47  date > /tmp/file
   48  date > /tmp/newfile
   49  ll /tmp/newfile
   50  cat /tmp/newfile
   51  cat /boot/grub2/grub.cfg > /tmp/newfile
   52  cat /tmp/newfile
   53  grep -n # /tmp/newfile
   54  grep  # /tmp/newfile -n
   55  grep -n  # /tmp/newfile 
   56  vim /tmp/newfile
   57  vi /tmp/newfile
   58  grep -n '#' /tmp/newfile
   59  grep -n '#' /tmp/newfiled
   60  grep -n '#' d/tmp/newfile
   61  vi /tmp/newfile
   62   date > /tmp/newfile
   63  vi /tmp/newfile
   64  cat /boot/newfile2
   65  rm /boot/newfile2
   66  rm /tmp
   67  rm -r /tmp
   68  yy
   69  y
   70  yy
   71  y
   72  cat /etc/passwd
   73  copy /etc/passwd /opt
   74  cp -p /etc/passwd /opt
   75  ll /opt
   76  ll /opt/passwd
   77  cat /opt/passwd
   78  cp -a /etc/passwd /opt
   79  ll /opt
   80  cp -p /etc/passwd /opt
   81  cat /opt/passwd
   82  head -3 /opt/passwd
   83  cat -n /opt/passwd
   84  cp -a /etc/passwd /opt
   85  cat -n /opt/passwd
   86  cp -a /etc/passwd /opt
   87  ll /opt
   88  cp -p /etc/passwd /opt/
   89  cp -p /etc/passwd /opt
   90  ll /opt
   91  cat /opt/passwd
   92  cat /etc/passwd
   93  cp -a /etc/passwd /opt
   94  cat -a /opt/passwd
   95  cat -p /opt/passwd
   96  cat -n /opt/passwd
   97  cp -a  /etc/passwd  /opt
   98  ll /opt
   99  mkdir -p /opt
  100  cp -p /etc/passwd /opt
  101  ll
  102  ll /opt
  103  cd /opt
  104  cat -a /opt/passwd
  105  cat -n /opt/passwd
  106  vi /etc/passwd
  107  wc -l /etc/passwd | cut -d "nologin"  -f 1
  108  cat /etc/passwd |grep  nologin|wc -l
  109  echo /etc/passwd |grep ' ' |wc -l
  110  echo 当前系统共有用户\`wc -l /etc/passwd | cut -d " "  -f 1`个 > file
q
EOf
EOF
  111  cat /etc/passwd | wc -l
  112  cat time
  113  cat /etc/time
  114  time
  115  date -s 21:06:50
  116  history

举报

相关推荐

rhcsa 第三天

RHCSA(第三天)

RHCSA第三天作业

rhcsa--第三天

RHCSA/Linux基础第三天

第三天 RHCSA 虚拟机

第三天学习

java学习第三天

0 条评论