linux4

来源:互联网 发布:linux五笔输入法 编辑:程序博客网 时间:2024/05/24 02:23

##################################

############unit 4################

##################################

 

###############################

##########1管理输入输出##########

###############################

 

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

 

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

find /etc -name passwd

因为student用户权限问题会有以下输出

bash: find/etc/: No such file or directory

[kiosk@foundation41 Desktop]$ find /etc -name 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

/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

 

find /etc -name passwd >file   ##重定向正确输出

find /etc -name passwd 2> file ##重定向错误输出

find /etc -name passwd &> file ##重定向所有输出

 

注意:>,2>,&>  都会覆盖源文件内容

>file   ##清空file

 

find /etc -name passwd >> file    ##追加正确输出

find /etc -name passwd 2>> file   ##追加错误输出

find /etc -name passwd  &>> file  ##追加所有输出

 

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

 

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

 

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

 

系统中错误的输出是无法通过管道的

2>&1 可以把错误的输出编号由2变成1

eg:[kiosk@foundation41 Desktop]$ dwfdwef |wc -l

    bash: dwfdwef: command not found...

    0

   [kiosk@foundation41 Desktop]$ dwfdwef 2>&1|wc -l

    1

 

tee  复制输出到指定位置

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

 

###################

######2.vim########

###################

 

######1.vim 命令模式####

 

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

set nu    ##行号添加

set nonu    ##取消行号

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

set cursorline  ##行线显示

 

以上设定都是临时的,

永久设定方式

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

****

[kiosk@foundation41 Desktop]#echo set nu >>/etc/vimrc

#############################

###2 vim命令模式下字符的管理#####

#############################

1.字符的设置

yl  ##复制一个字母

y3l  ##复制3个字母

yw  ##复制一个单词

y3w  ##复制3个单词

yy  ##复制一行

y3y ##复制3行

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

 

2 字符的删除

d1  ##删除一个字母

d2l ##删除2个字母

dw  ##删除一个单词

d3w  ##删除3个单词

dd   ##删除一行

d3d ##删除3行

 

3 字符的剪切

cl       ##剪切一个字母

c3l   ##剪切3个字母

cw  ##剪切一个单词

c3w   ##剪切3个单词

cc       ##剪切一行

c3c   ##剪切3行

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

 

#########4 vim的可视化模式####

 

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

在可视模式下可以区域选择字符

 

可视模式下批量添加字符

*>> ctrl+V 选中要加入字符所在列

*>> 按"I"进入插入模式,写入要加入的字符

*>> 按esc

 

#####5 批量修改字符####

 

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

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

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

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

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

 

############6 vim的分屏功能###

ctrl+w s ##上下分屏

ctrl+w v ##左右分屏

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

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

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

 

#####7 vim 光标移动#####

在命令模式下<<<第四单元练习>>>

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

 

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

[student@foundation179 Desktop]$ find /etc -name passwd 2>/dev/null

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

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

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

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

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

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

        * 屏蔽此命令的所有输出

[student@foundation179 Desktop]$ find /etc -name passwd &>/dev/null

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

[student@foundation179 Desktop]$ find /etc -name passwd |tee file

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

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

 

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

 

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

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

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

[root@foundation179 Desktop]#vim /root/lines

:%s/\ /vim/g--->"Esc"--->:wq

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

G       ##文件最后一行

gg      ##文件第一行

 

在插入模式下

i  ##光标所在位置插入

I  ##光标所在行行首

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

A  ##光标所在行行尾

o  ##光标所在行下一行

O  ##光标所在行上一行

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

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

 

#####8 vim 的退出模式####

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

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

wq   ##保存退出

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

 

#####9 vim手册###

vimtutor   ##vim的手册

q        ##退出vimtutor

 

#######################

###########3.gedit#####

#######################

 

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

ctrl +s   ##保存文件

ctrl +o  ##打开文件

ctrl +x   ##剪切字符

ctrl +v   ##粘贴字符

ctrl +c         ##复制字符

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

 

 

###end###

 

linux4练习

<<<第四单元练习>>>

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

 

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

[student@foundation179 Desktop]$ find /etc -name passwd 2>/dev/null

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

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

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

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

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

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

        * 屏蔽此命令的所有输出

[student@foundation179 Desktop]$ find /etc -name passwd &>/dev/null

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

[student@foundation179 Desktop]$ find /etc -name passwd |tee file

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

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

 

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

 

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

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

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

[root@foundation179 Desktop]#vim /root/lines

:%s/\ /vim/g--->"Esc"--->:wq

 

  

 

 

 

0 0
原创粉丝点击