Linux基本命令学习/查询命令学习/vim常用练习

基本命令学习

命令的基本使用格式

命令字【选项】 【文件或者目录】

ls -l ---   长格式显示 目录下的内容信息

ls -lh --- 人类易读

ls -a 查询目录下所有 隐藏文件 以点开头的文件为隐藏文件

mkdir -p 目录 创建目录如果父目录不存在 一起创建,如果目录存在 不会报错

如何获取命令的帮助信息

man 命令字

/搜索关键字 n 向下找 N 向上找

q 退出帮助菜单

命令字的分类 命令字分内部命令和外部命令 cd 内部命令

命令解释器中自带的命令叫内部命令

通过第三方软件安装后得到的命令叫外部命令

Linux的命令解释器 bash --- centos kali 都在用

help 专门用来查看内部命令使用手册的命令字 他本身也是内部命令

man cd

查 统计 more less head tall grep awk sort uniq wc du find

more 分页查看 空格翻页 q退出

less 可以逐行查看 q退出

cat -n /etc/man_db.conf | less

| 表示管道符号 前一条命令的输出作为后一条命令的处理参数

head 文件查看文件前10行

tail 尾巴 看文件的后10行

跟踪自己的触发登录 ssh root@127.0.0.1提示yes 输入密码

tail -f /var/log/secure 如果退出 ctrl+c

找出谁连接我失败的ip

grep -i 关键字 文件 --- 过滤出关键字所在的行并且 -i忽略大小写

awk 过滤字段 awk '{print $4}' 文件 | 过滤文件内容的第四段 默认以空格区分

cat /etc/passwd 以冒号为分隔符 看第一个字段

awk -F:'{print $1}' /etc/passwd

sort 文件 排序

uniq 合并 -c 统计

grep "Accepted" /var/log/secure | awk '{print $11}' |sort | uniq -c 统计日志文件中所有登陆成功的ip 地址

wc 统计文件内的 行数 字数 字节数 -l 统计行

du 统计目录占用空间大小 -s 统计目录总大小 -h 人类易读

统计 查询  基本练习

wc统计 /etc/passwd多少行

du统计以下 /usr 目录占用空间大小

思考 find 命令 找出 /etc/目录下 名字为passwd的文件?

find /etc -name “passwd” -a type f

-name 按名字找?单字符通配 * 通配左右 【abc】通配单个

-type 按类型找 f 文件 d 目录 l 符号链接

-a 两个条件同时成立and并且

-o 两个条件任意成立or或者

查询进阶练习

找出/boot目录中文件大小10M以上的文件并拷贝到/tmp目录中

find /boot -size +10M -exec cp -r ‘{}’ /tmp \;

'{}'被找到的文件 -exec 扩展条件 ; 结束符号

找出/tmp目录中文件大小10M以上的文件并删除

find /tmp -size +10M | xargs rm -rf

find命令不可以直接使用管道符号 需要用xargs引出命令

文件颜色分类

蓝色 --- 目录

浅蓝色 --- 符号链接 (快捷方式)

黑色 --- 普通(可查看)绿色 可执行文件 (命令和脚本)

红色 --- 压缩文件

黑底黄色 --- 设备文件

快捷键应用

清屏 ctrl + l == clear

立即终止进程ctrl + c

清除光标前的所有内容 ctrl + u

调用历史命令 上箭头

历史命令查看 history 调用   ! 序号

编辑器的使用

:q!强制退出不保存

vim编辑器 综合练习

素材:将素材保存到桌面Desktop命名问man.config

#
# Generated automatically from man.conf.in by the
# configure script.
#
# man.conf from man-1.6f
#
# For more information about this file, see the man pages man(1)
# and man.conf(5).
#
# This file is read by man to configure the default manpath (also used
# when MANPATH contains an empty substring), to find out where the cat
# pages corresponding to given man pages should be stored,
# and to map each PATH element to a manpath element.
# It may also record the pathname of the man binary. [This is unused.]
# The format is:
#
# MANBIN		pathname
# MANPATH		manpath_element	[corresponding_catdir]
# MANPATH_MAP		path_element	manpath_element
#
# If no catdir is given, it is assumed to be equal to the mandir
# (so that this dir has both man1 etc. and cat1 etc. subdirs).
# This is the traditional Unix setup.
# Certain versions of the FSSTND recommend putting formatted versions
# of /usr/.../man/manx/page.x into /var/catman/.../catx/page.x.
# The keyword FSSTND will cause this behaviour.
# Certain versions of the FHS recommend putting formatted versions of
# /usr/.../share/man/[locale/]manx/page.x into
# /var/cache/man/.../[locale/]catx/page.x.
# The keyword FHS will cause this behaviour (and overrides FSSTND).
# Explicitly given catdirs override.
#
# FSSTND
FHS
#
# This file is also read by man in order to find how to call nroff, less, etc.,
# and to determine the correspondence between extensions and decompressors.
#
# MANBIN		/usr/local/bin/man
#
# Every automatically generated MANPATH includes these fields
#
MANPATH	/usr/man
MANPATH	/usr/share/man
MANPATH	/usr/local/man
MANPATH	/usr/local/share/man
MANPATH	/usr/X11R6/man
#
# Uncomment if you want to include one of these by default
#
# MANPATH	/opt/*/man
# MANPATH	/usr/lib/*/man
# MANPATH	/usr/share/*/man
# MANPATH	/usr/kerberos/man
#
# Set up PATH to MANPATH mapping
#
# If people ask for "man foo" and have "/dir/bin/foo" in their PATH
# and the docs are found in "/dir/man", then no mapping is required.
#
# The below mappings are superfluous when the right hand side is
# in the mandatory manpath already, but will keep man from statting
# lots of other nearby files and directories.
#
MANPATH_MAP	/bin			/usr/share/man
MANPATH_MAP	/sbin			/usr/share/man
MANPATH_MAP	/usr/bin		/usr/share/man
MANPATH_MAP	/usr/sbin		/usr/share/man
MANPATH_MAP	/usr/local/bin		/usr/local/share/man
MANPATH_MAP	/usr/local/sbin		/usr/local/share/man
MANPATH_MAP	/usr/X11R6/bin		/usr/X11R6/man
MANPATH_MAP	/usr/bin/X11		/usr/X11R6/man
MANPATH_MAP	/usr/bin/mh		/usr/share/man
#
# NOAUTOPATH keeps man from automatically adding directories that look like
# manual page directories to the path.
#
#NOAUTOPATH
#
# NOCACHE keeps man from creating cache pages ("cat pages")
# (generally one enables/disable cat page creation by creating/deleting
# the directory they would live in - man never does mkdir)
# 
#NOCACHE
#
# Useful paths - note that COL should not be defined when
# NROFF is defined as "groff -Tascii" or "groff -Tlatin1";
# not only is it superfluous, but it actually damages the output.
# For use with utf-8, NROFF should be "nroff -mandoc" without -T option.
# (Maybe - but today I need -Tlatin1 to prevent double conversion to utf8.)
#
# If you have a new troff (version 1.18.1?) and its colored output
# causes problems, add the -c option to TROFF, NROFF.
#
TROFF		/usr/bin/groff -Tps -mandoc
NROFF		/usr/bin/nroff -c -mandoc 2>/dev/null
EQN		/usr/bin/geqn -Tps
NEQN		/usr/bin/geqn -Tutf8
TBL		/usr/bin/gtbl
# COL		/usr/bin/col
REFER		/usr/bin/grefer
PIC		/usr/bin/gpic
VGRIND		
GRAP		
PAGER		/usr/bin/less -is
BROWSER		/usr/bin/less -is
HTMLPAGER	/bin/cat
CAT		/bin/cat
#
# The command "man -a xyzzy" will show all man pages for xyzzy.
# When CMP is defined man will try to avoid showing the same
# text twice. (But compressed pages compare unequal.)
#
CMP		/usr/libexec/man-cmp.sh
#
# Compress cat pages
#
COMPRESS	/usr/bin/lzma
COMPRESS_EXT	.lzma
#
# Default manual sections (and order) to search if -S is not specified
# and the MANSECT environment variable is not set (1x-8x sections are used by
# xorg packages).
#
MANSECT		1:1p:8:2:3:3p:4:5:6:7:9:0p:n:l:p:o:1x:2x:3x:4x:5x:6x:7x:8x
#
# Default options to use when man is invoked without options
# This is mainly for the benefit of those that think -a should be the default
# Note that some systems have /usr/man/allman, causing pages to be shown twice.
#
#MANDEFOPTIONS	-a
#
# Decompress with given decompressor when input file has given extension
# The command given must act as a filter.
#
.gz		/usr/bin/gunzip -c
.bz2		/usr/bin/bzip2 -c -d
.lzma		/usr/bin/unlzma -c -d
.z		
.Z		/bin/zcat
.F		
.Y		
#
# Enable/disable makewhatis database cron updates.
# If MAKEWHATISDBUPDATES variable is uncommented
# and set to n or N, cron scripts 
# /etc/cron.daily/makewhatis.cron
# /etc/cron.weekly/makewhatis.cron
# will not update makewhatis database.
# Otherwise the database will be updated.
# 
#MAKEWHATISDBUPDATES	n

1.在/tmp目录中建立一个名为man.config的文件

2.在/tmp/man.config文件中调用素材man.config的内容,并删除第一行空白行

在末行模式操作 :r /root/Desktop/man.config 先去第一行 命令模式输入 gg 跳转到第一行 dd 删除当前 光标所在行

3.设定显示行号

末行模式 :set nu

4.移动到第58行并且向右移动40个字符 会看到/dir/bin/foo

命令模式下 58G 40右箭头

5.移动到第一行并向下搜索bzip2字符串 出现在137行

gg 到第一行 / 搜索关键字 bzip2 回车

6.将50-100行小写的man替换成大写的MAN

:50,100 s/man/MAN/g 查找并替换 :% 每一行

7.替换完成后恢复

命令模式 u 撤销上一次操作 (ctrl+r 反撤销)

8.复制65-73行内容并且粘贴到后一行下面

末行模式操作 :65,73 y 复制 G 跳到后一行 p 粘贴

9.删除21-42行内容

末行模式操作 :21,42 d

10.将文件另存为man.test

末行模式 :w man.test

11.到27行删除15个字符如成功应该光标停留在you want位置

命令模式 27G 15x 向右删除15个字符 (x删除当前光标下的字符)

12.在第一行上面新增一行内容为I am a simple student

13.储存并退出

ZZ 或者 :wq

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值