Linux云自动化运维第三课

Linux云自动化运维第三课

一、正则表达式

1.匹配符

* ###匹配0到任意字符

? ###匹配单个字符

[[:alpha:]] ###匹配单个字母

[[:lower:]] ###匹配单个小写字母

[[:upper:]] ###匹配单个大写字母

[[:digit:]] ###匹配单个数字

[[:alnum:]] ###匹配单个数字或字母

[[:punct:]] ###匹配单个符号

[[:space:]] ###匹配单个空格

eg:[kiosk@foundation42 study]$ touch class{1..2}{a..b} ###新建文件class*

[kiosk@foundation42 study]$ touch class{1..2}{A..B}

[kiosk@foundation42 study]$ touch class{a..b}{A..B}

[kiosk@foundation42 study]$ ls

class1a  class1b  class2a  class2b  classaA  classbA

class1A  class1B  class2A  class2B  classaB  classbB

[kiosk@foundation42 study]$ rm -fr * ###*0到匹配任意字符,删除所有文件

[kiosk@foundation42 study]$ ls ###目录列表为空,class*文件都被删除

[kiosk@foundation42 study]$ touch class{1..2}{a..b}

[kiosk@foundation42 study]$ touch class{1..2}{A..B}

[kiosk@foundation42 study]$ touch class{a..b}{A..B}

[kiosk@foundation42 study]$ ls

class1a  class1b  class2a  class2b  classaA  classbA

class1A  class1B  class2A  class2B  classaB  classbB

[kiosk@foundation42 study]$ rm -fr class?A ###?匹配单个字符,删除文件class?A文件,第6个字符为任意字符

[kiosk@foundation42 study]$ ls ###class{1..2}A,class{a..b}A文件被删除

class1a  class1b  class1B  class2a  class2b  class2B  classaB  classbB

[kiosk@foundation42 study]$ rm -fr class1[[:alpha:]] ###删除class1[[:alpha:]]文件,第7个字符为任意字母

[kiosk@foundation42 study]$ ls ###class1{a..b},class1{A..B}文件被删除

class2a  class2b  class2B  classaB  classbB

[kiosk@foundation42 study]$ rm -fr class[[:lower:]]B ###删除class[[:lower:]]B文件,第5个字符为任意小写字母

[kiosk@foundation42 study]$ ls ###class{a..b}B文件被删除

class2a  class2b  class2B

[kiosk@foundation42 study]$ rm -fr class2[[:upper:]] ###删除class2[[:upper:]]文件,第7个字符为任意大写字母

[kiosk@foundation42 study]$ ls ###classa{A..B}文件被删除

class2a  class2b

[kiosk@foundation42 study]$ rm -fr class[[:digit:]]a ###删除class[[:digit:]]a文件,第6个字符为任意单个数字

[kiosk@foundation42 study]$ ls ###class2a被删除

class2b

[kiosk@foundation42 study]$ rm -fr class[[:alnum:]][[:alnum:]] ###删除class[[:alnum:]][[:alnum:]]文件,第6个字符、第7个字符分别为单个数字或字母

[kiosk@foundation42 study]$ ls ###class2b被删除

[kiosk@foundation42 study]$ touch class@3 class" "9 ###新建文件名称分别带有符号和空格的文件

[kiosk@foundation42 study]$ ls

class@3  class 9

[kiosk@foundation42 study]$ rm -fr class[[:punct:]]? ###删除文件名称第6个字符是符号的文件

[kiosk@foundation42 study]$ ls ###文件class@3被删除

class 9

[kiosk@foundation42 study]$ rm -fr class[[:space:]]? ###删除文件名称第6个字符是空格的文件

[kiosk@foundation42 study]$ ls ###文件class 9被删除

[kiosk@foundation42 study]$

2.{}表示不存在的或者存在的

{1..9} ###1-9

{a..f} ###a-f

{A..F} ###A-F

{1,3,5} ###1,3,5

{a,c,e} ###a,c,e

{1..3}{a..c} ###1a,1b,1c,2a,2b,2c,3a,3b,3c

eg:[kiosk@foundation42 study]$ touch class{1..9} ###建立文件class1-class9

[kiosk@foundation42 study]$ ls

class1  class2  class3  class4  class5  class6  class7  class8  class9

[kiosk@foundation42 study]$ rm -fr *

[kiosk@foundation42 study]$ touch class{a..f} ###建立文件classa-classf

[kiosk@foundation42 study]$ ls

classa  classb  classc  classd  classe  classf

[kiosk@foundation42 study]$ rm -fr *

[kiosk@foundation42 study]$ touch class{A..F} ###建立文件classA-classF

[kiosk@foundation42 study]$ ls

classA  classB  classC  classD  classE  classF

[kiosk@foundation42 study]$ rm -fr *

[kiosk@foundation42 study]$ touch class{1,3,5} ###建立文件class1,class3,class5

[kiosk@foundation42 study]$ ls

class1  class3  class5

[kiosk@foundation42 study]$ rm -fr *

[kiosk@foundation42 study]$ touch class{a,c,e} ###建立文件classa,classc,classe

[kiosk@foundation42 study]$ ls

classa  classc  classe

[kiosk@foundation42 study]$ rm -fr *

[kiosk@foundation42 study]$ touch class{1..3}{a..c} ###建立文件*1a,*1b,*1c,*2a,*2b,*2c,*3a,*3b,*3c

[kiosk@foundation42 study]$ ls

class1a  class1b  class1c  class2a  class2b  class2c  class3a  class3b  class3c

[kiosk@foundation42 study]$

3.[]表示存在的

[a-D] ###a,A,b,B,c,C,d,D

[a-d] ###a,A,b,B,c,C,d

[1-4] ###1,2,3,4

[14] ###1,4

[!abc][^abc] ###除了a,b,c

eg:[kiosk@foundation42 study]$ touch {a..d}

[kiosk@foundation42 study]$ touch {A..D}

[kiosk@foundation42 study]$ touch {1..4}

[kiosk@foundation42 study]$ ls

1  2  3  4  a  A  b  B  c  C  d  D

[kiosk@foundation42 study]$ rm -fr [a-c] ###删除文件a,A,b,B,c

[kiosk@foundation42 study]$ ls

1  2  3  4  C  d  D

[kiosk@foundation42 study]$ touch {a..d}

[kiosk@foundation42 study]$ touch {A..D}

[kiosk@foundation42 study]$ ls

1  2  3  4  a  A  b  B  c  C  d  D

[kiosk@foundation42 study]$ rm -fr [a-C] ###删除文件a,A,b,B,c,C

[kiosk@foundation42 study]$ ls

1  2  3  4  d  D

[kiosk@foundation42 study]$ touch {a..d}

[kiosk@foundation42 study]$ touch {A..D}

[kiosk@foundation42 study]$ ls

1  2  3  4  a  A  b  B  c  C  d  D

[kiosk@foundation42 study]$ rm -fr [1-3] ###删除文件1,2,3

[kiosk@foundation42 study]$ ls

4  a  A  b  B  c  C  d  D

[kiosk@foundation42 study]$ touch {1..4}

[kiosk@foundation42 study]$ ls

1  2  3  4  a  A  b  B  c  C  d  D

[kiosk@foundation42 study]$ rm -fr [14] ###删除文件1,4

[kiosk@foundation42 study]$ ls

2  3  a  A  b  B  c  C  d  D

[kiosk@foundation42 study]$ rm -fr [!abc] ###删除除了文件a,b,c之外的所有文件

[kiosk@foundation42 study]$ ls

a  b  c

[kiosk@foundation42 study]$ rm -fr [^ac] ###删除除了文件a,c之外的所有文件

[kiosk@foundation42 study]$ ls

a  c

[kiosk@foundation42 study]$

4.~当前用户家目录

~ ###当前用户家目录

~username ###指定用户家目录

~+ ###当前目录

~- ###当前目录所在目录

. ###当前目录

.. ###当前目录上一级

eg:[root@foundation42 ~]# pwd ###当前目录/root

/root

[root@foundation42 ~]# cd ~kiosk ###跳转到kiosk用户的家目录/home/kiosk

[root@foundation42 kiosk]# pwd

/home/kiosk

[kiosk@foundation42 Desktop]$ pwd ###当前目录/home/kiosk/Desktop

/home/kiosk/Desktop

[kiosk@foundation42 Desktop]$ cd ~ ###跳转到当前用户的家目录/home/kiosk

[kiosk@foundation42 ~]$ pwd

/home/kiosk

[kiosk@foundation42 ~]$ cd ~- ###跳转到当前用户之前所在目录/home/kiosk/Desktop

[kiosk@foundation42 Desktop]$ pwd

/home/kiosk/Desktop

[kiosk@foundation42 Desktop]$ cd ~+ ###跳转当前目录/home/kiosk/Desktop

[kiosk@foundation42 Desktop]$ cd . ###跳转当前目录/home/kiosk/Desktop

[kiosk@foundation42 Desktop]$ cd .. ###跳转当前目录的上一级目录/home/kiosk

[kiosk@foundation42 ~]$ pwd

/home/kiosk

[kiosk@foundation42 ~]$

二、man命令

1.man命令基本用法

man --manual ###man是手册manual的缩写

man man ###查看man命令的帮助

man passwd ###查看passwd命令的帮助

2.man的级别

1 系统命令

2 系统接口

3 函数库

4 特殊文件,比如设备文件

5 文件

6 游戏

7 系统的软件包

8 系统管理命令

9 内核

man 5 passwd ###查看/etc/passwd文件的帮助

man 1 passwd ###查看passwd命令的帮助

eg:[kiosk@foundation42 ~]$ man -k passwd

passwd (1)           - update user's authentication tokens ###passwd命令

passwd (5)           - password file ###passwd文件

3.man页面的快捷方式

上下键 ###向上或向下一行

pageup|pagedown ###向上一个屏幕或向下一个屏幕

d|u ###向下或者向上半个屏幕

G|gg ###跳转到页面到man的最下面或最上面

/关键字 ###搜索关键字,关键字会高亮显示,n向下匹配,N向上匹配

q ###退出帮助页面

三、管理输入输出

1.在linux系统中,正确输出的编号为1,错误输出的编号为2

2.在系统中用普通用户执行“student”

eg:[kiosk@foundation42 Desktop]$ find /etc -name passwd ###student用户权限有问题,会有以下输出

find: ‘/etc/pki/CA/private’: Permission denied ###没有进入权限,报错

find: ‘/etc/pki/rsyslog’: Permission denied

find: ‘/etc/dhcp’: Permission denied

find: ‘/etc/lvm/archive’: Permission denied

find: ‘/etc/lvm/backup’: Permission denied

find: ‘/etc/lvm/cache’: Permission denied

find: ‘/etc/selinux/targeted/modules/active’: Permission denied

/etc/passwd ###正确输出

find: ‘/etc/polkit-1/rules.d’: Permission denied

find: ‘/etc/polkit-1/localauthority’: Permission denied

find: ‘/etc/audit’: Permission denied

/etc/pam.d/passwd ###正确输出

find: ‘/etc/firewalld’: Permission denied

find: ‘/etc/grub.d’: Permission denied

find: ‘/etc/ipsec.d’: Permission denied

find: ‘/etc/libvirt’: Permission denied

find: ‘/etc/audisp’: Permission denied

find: ‘/etc/virt-who.d’: Permission denied

find: ‘/etc/sudoers.d’: Permission denied

[kiosk@foundation42 Desktop]$ find /etc/ -name passwd >file ###重定向正确输出

find: ‘/etc/pki/CA/private’: Permission denied ###显示的都是报错信息

find: ‘/etc/pki/rsyslog’: Permission denied

find: ‘/etc/dhcp’: Permission denied

find: ‘/etc/lvm/archive’: Permission denied

find: ‘/etc/lvm/backup’: Permission denied

find: ‘/etc/lvm/cache’: Permission denied

find: ‘/etc/selinux/targeted/modules/active’: Permission denied

find: ‘/etc/polkit-1/rules.d’: Permission denied

find: ‘/etc/polkit-1/localauthority’: Permission denied

find: ‘/etc/audit’: Permission denied

find: ‘/etc/firewalld’: Permission denied

find: ‘/etc/grub.d’: Permission denied

find: ‘/etc/ipsec.d’: Permission denied

find: ‘/etc/libvirt’: Permission denied

find: ‘/etc/audisp’: Permission denied

find: ‘/etc/virt-who.d’: Permission denied

find: ‘/etc/sudoers.d’: Permission denied

[kiosk@foundation42 Desktop]$ cat file ###正确输出在文件file中

/etc/passwd

/etc/pam.d/passwd

[kiosk@foundation42 Desktop]$ find /etc/ -name passwd 2>file ###重定向错误输出

/etc/passwd ###显示的都是正确信息

/etc/pam.d/passwd

[kiosk@foundation42 Desktop]$ cat file ###报错信息在file中

find: ‘/etc/pki/CA/private’: Permission denied

find: ‘/etc/pki/rsyslog’: Permission denied

find: ‘/etc/dhcp’: Permission denied

find: ‘/etc/lvm/archive’: Permission denied

find: ‘/etc/lvm/backup’: Permission denied

find: ‘/etc/lvm/cache’: Permission denied

find: ‘/etc/selinux/targeted/modules/active’: Permission denied

find: ‘/etc/polkit-1/rules.d’: Permission denied

find: ‘/etc/polkit-1/localauthority’: Permission denied

find: ‘/etc/audit’: Permission denied

find: ‘/etc/firewalld’: Permission denied

find: ‘/etc/grub.d’: Permission denied

find: ‘/etc/ipsec.d’: Permission denied

find: ‘/etc/libvirt’: Permission denied

find: ‘/etc/audisp’: Permission denied

find: ‘/etc/virt-who.d’: Permission denied

find: ‘/etc/sudoers.d’: Permission denied

[kiosk@foundation42 Desktop]$ find /etc/ -name passwd &>file ###重定向所有输出

[kiosk@foundation42 Desktop]$ cat file ###所有输出都输出到文件file中

find: ‘/etc/pki/CA/private’: Permission denied

find: ‘/etc/pki/rsyslog’: Permission denied

find: ‘/etc/dhcp’: Permission denied

find: ‘/etc/lvm/archive’: Permission denied

find: ‘/etc/lvm/backup’: Permission denied

find: ‘/etc/lvm/cache’: Permission denied

find: ‘/etc/selinux/targeted/modules/active’: Permission denied

/etc/passwd

find: ‘/etc/polkit-1/rules.d’: Permission denied

find: ‘/etc/polkit-1/localauthority’: Permission denied

find: ‘/etc/audit’: Permission denied

/etc/pam.d/passwd

find: ‘/etc/firewalld’: Permission denied

find: ‘/etc/grub.d’: Permission denied

find: ‘/etc/ipsec.d’: Permission denied

find: ‘/etc/libvirt’: Permission denied

find: ‘/etc/audisp’: Permission denied

find: ‘/etc/virt-who.d’: Permission denied

find: ‘/etc/sudoers.d’: Permission denied

[kiosk@foundation42 Desktop]$ >file ###清空file,ps:>,2>,&>都会覆盖源文件内容

[kiosk@foundation42 Desktop]$ find /etc/ -name passwd >>file ###追加正确输出

find: ‘/etc/pki/CA/private’: Permission denied ###显示错误输出

find: ‘/etc/pki/rsyslog’: Permission denied

find: ‘/etc/dhcp’: Permission denied

find: ‘/etc/lvm/archive’: Permission denied

find: ‘/etc/lvm/backup’: Permission denied

find: ‘/etc/lvm/cache’: Permission denied

find: ‘/etc/selinux/targeted/modules/active’: Permission denied

find: ‘/etc/polkit-1/rules.d’: Permission denied

find: ‘/etc/polkit-1/localauthority’: Permission denied

find: ‘/etc/audit’: Permission denied

find: ‘/etc/firewalld’: Permission denied

find: ‘/etc/grub.d’: Permission denied

find: ‘/etc/ipsec.d’: Permission denied

find: ‘/etc/libvirt’: Permission denied

find: ‘/etc/audisp’: Permission denied

find: ‘/etc/virt-who.d’: Permission denied

find: ‘/etc/sudoers.d’: Permission denied

[kiosk@foundation42 Desktop]$ cat file ###正确输出在file中

/etc/passwd

/etc/pam.d/passwd

[kiosk@foundation42 Desktop]$ find /etc/ -name passwd 2>>file ###追加错误输出

/etc/passwd ###显示正确输出

/etc/pam.d/passwd

[kiosk@foundation42 Desktop]$ cat file ###错误输出追加到源文件内容之后,不覆盖源文件

/etc/passwd

/etc/pam.d/passwd

find: ‘/etc/pki/CA/private’: Permission denied

find: ‘/etc/pki/rsyslog’: Permission denied

find: ‘/etc/dhcp’: Permission denied

find: ‘/etc/lvm/archive’: Permission denied

find: ‘/etc/lvm/backup’: Permission denied

find: ‘/etc/lvm/cache’: Permission denied

find: ‘/etc/selinux/targeted/modules/active’: Permission denied

find: ‘/etc/polkit-1/rules.d’: Permission denied

find: ‘/etc/polkit-1/localauthority’: Permission denied

find: ‘/etc/audit’: Permission denied

find: ‘/etc/firewalld’: Permission denied

find: ‘/etc/grub.d’: Permission denied

find: ‘/etc/ipsec.d’: Permission denied

find: ‘/etc/libvirt’: Permission denied

find: ‘/etc/audisp’: Permission denied

find: ‘/etc/virt-who.d’: Permission denied

find: ‘/etc/sudoers.d’: Permission denied

[kiosk@foundation42 Desktop]$ find /etc/ -name passwd &>>file ###追加所有输出

[kiosk@foundation42 Desktop]$ cat file ###所有输出追加到源文件内容之后,不覆盖源文件

/etc/passwd

/etc/pam.d/passwd

find: ‘/etc/pki/CA/private’: Permission denied

find: ‘/etc/pki/rsyslog’: Permission denied

find: ‘/etc/dhcp’: Permission denied

find: ‘/etc/lvm/archive’: Permission denied

find: ‘/etc/lvm/backup’: Permission denied

find: ‘/etc/lvm/cache’: Permission denied

find: ‘/etc/selinux/targeted/modules/active’: Permission denied

find: ‘/etc/polkit-1/rules.d’: Permission denied

find: ‘/etc/polkit-1/localauthority’: Permission denied

find: ‘/etc/audit’: Permission denied

find: ‘/etc/firewalld’: Permission denied

find: ‘/etc/grub.d’: Permission denied

find: ‘/etc/ipsec.d’: Permission denied

find: ‘/etc/libvirt’: Permission denied

find: ‘/etc/audisp’: Permission denied

find: ‘/etc/virt-who.d’: Permission denied

find: ‘/etc/sudoers.d’: Permission denied

find: ‘/etc/pki/CA/private’: Permission denied

find: ‘/etc/pki/rsyslog’: Permission denied

find: ‘/etc/dhcp’: Permission denied

find: ‘/etc/lvm/archive’: Permission denied

find: ‘/etc/lvm/backup’: Permission denied

find: ‘/etc/lvm/cache’: Permission denied

find: ‘/etc/selinux/targeted/modules/active’: Permission denied

/etc/passwd

find: ‘/etc/polkit-1/rules.d’: Permission denied

find: ‘/etc/polkit-1/localauthority’: Permission denied

find: ‘/etc/audit’: Permission denied

/etc/pam.d/passwd

find: ‘/etc/firewalld’: Permission denied

find: ‘/etc/grub.d’: Permission denied

find: ‘/etc/ipsec.d’: Permission denied

find: ‘/etc/libvirt’: Permission denied

find: ‘/etc/audisp’: Permission denied

find: ‘/etc/virt-who.d’: Permission denied

find: ‘/etc/sudoers.d’: Permission denied

ps:>>,2>>,&>>不会覆盖源文件内容,会把相应的输出字符放到文件的最后

3.|管道,管道的作用是将前一条命令的输出变成管道之后命令的输入

ls /bin | wc -l ###统计ls /bin 命令输出的行数

tee ###复制输出到指定位置

date |tee file |wc -l ###tee命令复制date命令的输出到file中,并统计输出行数

ps:系统中错误的输出是无法通过管道的。用2>&1可以错误的输出编号由2变成1.

eg:[kiosk@foundation42 Desktop]$ ls /bin | wc -l ###统计ls /bin命令输出的行数

1903

[kiosk@foundation42 Desktop]$ sdjksljf | wc -l ###系统中错误的输出是无法通过管道的

bash: sdjksljf: command not found...

0

[kiosk@foundation42 Desktop]$ sdjksljf 2>&1 | wc -l ###用2>&1可以错误的输出编号由2变成1

1

[kiosk@foundation42 Desktop]$ date |tee file |wc -l ###tee命令复制date命令的输出到file中,并统计输出行数

1

[kiosk@foundation42 Desktop]$ cat file ###文件file中是命令date的输出

Tue Mar 21 13:36:46 CST 2017

四、vim

1.vim的命令模式

在vim的命令模式下可以配置vim的工作方式

:set nu ###行号添加

:set nonu ###取消行号

:set mouse=a ###添加鼠标选择

:set cursorline ###行线显示

ps:以上设定都是临时的,永久设定方式:

vim /etc/vimrc ###此文件为vim的配置文件,在此文件最后加上以上参数,加到文件中的参数不需要:

[root@foundation42 ~]# echo set nu  >>/etc/vimrc ###永久设定行号添加

2.vim命令模式下关键字搜索

/关键字

n向下匹配

N向上匹配

3.vim命令模式下字符的管理

1)字符的复制

yl ###复制一个字母

y3l ###复制3个字母

yw ###复制一个单词

y3w ###复制3个单词

yy ###复制一行

y3y ###复制3行

p ###复制完成后按“P”粘贴

2)字符的删除

dl ###删除一个字母

d3l ###删除3个字母

dw ###删除一个单词

d3w ###删除3个单词

dd ###删除一行

d3d ###删除3行

2)字符的剪切

cl ###剪切一个字母

c3l ###剪切3个字母

cw ###剪切一个单词

c3w ###剪切3个单词

cc ###剪切一行

c3c ###剪切3行

esc -> p ###剪切过后会进入到插入模式,在执行粘贴动作时一定要退出插入模式

4.vim的可视化模式

1)在命令模式下按“ctrl+v”进入到可视模式

2)在可视模式下可以区域选择字符,使用上下左右键

3)可视模式下批量添加字符

ctrl+v->选中要加入字符所在列->按“I”进入插入模式,写入要加入的字符->按“esc”

5.批量修改字符

:%s/原有字符/替换后字符 ###只替换每一行中出现的第一个原有字符

:%s/原有字符/替换后字符/g ###替换所有

:%s/\t//g ###把全文的tab键替去掉,\t 表示tab键

:%s/^\ *//g ###把全文行首的空格去掉,"^\ *"表示行首的空格

:%s/\ *//g ###把全文的空格去掉

:%s/^\#\ */#/g ###把全文#后的空格去掉

6.vim的分屏功能

ctrl+w s ###上下分屏

ctrl+w v ###左右分屏

ctrl+w c ###关闭光标所在屏幕

ctrl+w 上下左右 ###光标移动到指定屏幕

:sp file2 ###同时编辑当前文件和file2

7.vim光标移动

1)在命令模式下

:数字 ###移动到指定行

G ###光标移动到文件最后一行

gg ###光标移动到文件第一行

2)在插入模式下

i ###光标所在位置插入

I ###光标所在行行首

a ###光标所在字符的下一个位置

A ###光标所在行行尾

o ###光标所在行下一行

O ###光标所在行上一行

s ###删除光标所在字符插入

S ###删除光标所在行插入

8.vim的退出模式

:q ###当用vim打开文件但没有对字符作任何操作时可直接退出

:q! ###当用vim打开文件并对字符作操作,放弃所有操作退出

:wq ###保存退出

:wq! ###强行保存退出,对超级用户及文件所有人生效

9.vim手册

vimtutor ###vim的手册

:q ###退出vimtutor

五、gedit

ctrl+n ###在gedit中打开一个新的tab

ctrl+s ###保存文件

ctrl+o ###打开文件

ctrl+x ###剪切字符

ctrl+v ###粘贴字符

ctrl+c ###复制字符

yelp help:gedit ###gedit的图形手册

unit3-作业

1.用命令和正则表达式按照要求建立文件

*)用一条命令建立12个文件WESTOS_classX_linuxY(X的数值范围为1-2,Y的数值范围为1-6)

*)这些文件都包含在root用户桌面的study目录中

[root@foundation42 Desktop]# mkdir study

[root@foundation42 Desktop]# touch ./study/WESTOS_class{1..2}_linux{1..6}

[root@foundation42 Desktop]# ls ./study/

WESTOS_class1_linux1  WESTOS_class1_linux5  WESTOS_class2_linux3

WESTOS_class1_linux2  WESTOS_class1_linux6  WESTOS_class2_linux4

WESTOS_class1_linux3  WESTOS_class2_linux1  WESTOS_class2_linux5

WESTOS_class1_linux4  WESTOS_class2_linux2  WESTOS_class2_linux6

*)用一条命令建立8个文件redhat_versionX(x的范围为1-8)

*)redhat_virsionX这些文件都包含在/mnt目录中的VERSION中

[root@foundation42 Desktop]# mkdir /mnt/VERSION

[root@foundation42 Desktop]# touch /mnt/VERSION/redhat_version{1..8}

[root@foundation42 Desktop]# ls /mnt/VERSION/

redhat_version1  redhat_version3  redhat_version5  redhat_version7

redhat_version2  redhat_version4  redhat_version6  redhat_version8

2.管理刚才信建立的文件要求如下

*)用一条命令把redhat_versionX中的带有奇数的文件复制到桌面的SINGLE中

[root@foundation42 Desktop]# mkdir SINGLE

[root@foundation42 Desktop]# cp /mnt/VERSION/redhat_version[1357] ./SINGLE/

[root@foundation42 Desktop]# ls SINGLE/

redhat_version1  redhat_version3  redhat_version5  redhat_version7

*)用一条命令把redhat_versionX中的带偶数数的文件复制到/DOUBLE中

[root@foundation42 Desktop]# mkdir DOUBLE

[root@foundation42 Desktop]# cp /mnt/VERSION/redhat_version[^1357] ./DOUBLE/

[root@foundation42 Desktop]# ls DOUBLE/

redhat_version2  redhat_version4  redhat_version6  redhat_version8

*)用一条命令把WESTOS_classX_linuxY中class1的文件一动到当前用户桌面的CLASS1中

[root@foundation42 Desktop]# mkdir CLASS1

[root@foundation42 Desktop]# mv study/WESTOS_class1* CLASS1/

[root@foundation42 Desktop]# ls CLASS1/

WESTOS_class1_linux1  WESTOS_class1_linux3  WESTOS_class1_linux5

WESTOS_class1_linux2  WESTOS_class1_linux4  WESTOS_class1_linux6

*)用一条命令把WESTOS_classX_linuxY中class2的文件一动到当前用户桌面的CLASS2中

[root@foundation42 Desktop]# mkdir CLASS2

[root@foundation42 Desktop]# mv study/WESTOS_class2* CLASS2/

[root@foundation42 Desktop]# ls CLASS2/

WESTOS_class2_linux1  WESTOS_class2_linux3  WESTOS_class2_linux5

WESTOS_class2_linux2  WESTOS_class2_linux4  WESTOS_class2_linux6

3.备份/etc目录中所有名字带有数字并且以.conf结尾的文件到桌面上的confdir中

[root@foundation42 Desktop]# mkdir confdir

[root@foundation42 Desktop]# cp /etc/*[[:digit:]]*.conf confdir

[root@foundation42 Desktop]# ls confdir/

e2fsck.conf  krb5.conf  mke2fs.conf

4.删掉刚才建立或者备份的所有文件

[root@foundation42 Desktop]# rm -fr * /mnt/VERSION

5.在student用户下执行find /etc -name passwd 命令,并管理其输出要求如下:

*)显示所有正确输出,屏蔽错误输出

[kiosk@foundation42 Desktop]$ find /etc/ -name passwd 2>/dev/null

/etc/passwd

/etc/pam.d/passwd

*)保存正确数出到/tmp/find.out,错误数出到/tmp/find.err中

[kiosk@foundation42 Desktop]$ find /etc/ -name passwd >/tmp/find.out 2>/tmp/find.err

*)建立/tmp/find.all文件,并且保存所有输出到此文件中

[kiosk@foundation42 Desktop]$ find /etc/ -name passwd &>/tmp/find.all

*)再次保存所有输出到/tmp/find.all中,并且保持源文件内容

[kiosk@foundation42 Desktop]$ find /etc/ -name passwd &>>/tmp/find.all

*)屏蔽此命令的所有输出

[kiosk@foundation42 Desktop]$ find /etc/ -name passwd &>/dev/null

*)显示此命令的所有输出并保存输出到桌面上的任意文件中

[kiosk@foundation42 Desktop]$ find /etc/ -name passwd | tee file

*)保存正确输出到/tmp/find.out.1中,屏蔽错误输出

[kiosk@foundation42 Desktop]$ find /etc/ -name passwd >/tmp/find.out.1 2>/dev/null

6.处理文件在文件/usr/share/mime/packages/freedesktop.org.xml要求如下:

*)找到此文件中包含ich的行,并保存这些行到/root/lines中

[root@foundation42 Desktop]# cat /usr/share/mime/packages/freedesktop.org.xml |grep ich | tee /root/lines

*)用vim替换掉/root/lines中的空格,但要保持文件中原有的内容

[root@foundation42 Desktop]# vim /root/lines->命令模式下输入":%s/\ /vim/g"->按“esc”->命令模式下输入“:wq”

上一篇:从On-Premise本地到On-Cloud云上运维的演进


下一篇:mysql中in查询中排序