linux查看vim 帮助,linux命令帮助及vi\vim的使用

最近特别忙,估计十一也不能回家,网速也很卡,不过这都不会减少我为同学们讲解linux的热情,今天我们将学习linux的命令帮助及vim的使用,很重要哦!!

学linux有困难找男人,也就是man,其实这主要是为了让大家能更好的记住这个命令,manual:手册

举个例子,比如ls命令,是查看当前目录下文件的,我们man一下它。

LS(1)                            User Commands                          LS(1)

NAME

ls - list directory contents

SYNOPSIS

ls [OPTION]... [FILE]...

DESCRIPTION

List  information  about  the FILEs (the current directory by default).  Sort

entries alphabetically if none of -cftuvSUX nor --sort.

Mandatory arguments to long options are mandatory for short options too.

-a, --all

do not ignore entries starting with .

-A, --almost-all

do not list implied . and ..

--author

with -l, print the author of each file

-b, --escape

print octal escapes for nongraphic characters

--block-size=SIZE

use SIZE-byte blocks.  See SIZE format below

-B, --ignore-backups

do not list implied entries ending with ~

-c     with -lt: sort by, and show, ctime (time of last modification of  file

status  information)  with  -l: show ctime and sort by name otherwise:

sort by ctime

-C     list entries by columns

--color[=WHEN]

colorize the output.  WHEN defaults to ‘always’ or can be  ‘never’  or

‘auto’.  More info below

-d, --directory

list  directory  entries  instead  of contents, and do not dereference

symbolic links

-D, --dired

generate output designed for Emacs’ dired mode

-f     do not sort, enable -aU, disable -ls --color

-F, --classify

append indicator (one of */=>@|) to entries

--file-type

likewise, except do not append ‘*’

--format=WORD

across -x, commas -m, horizontal -x, long -l, single-column  -1,  ver-

bose -l, vertical -C

--full-time

like -l --time-style=full-iso

-g     like -l, but do not list owner

--group-directories-first

group directories before files.

augment with a --sort option, but any use of --sort=none (-U) disables

grouping

-G, --no-group

in a long listing, don’t print group names

-h, --human-readable

with -l, print sizes in human readable format (e.g., 1K 234M 2G)

--si   likewise, but use powers of 1000 not 1024

-H, --dereference-command-line

follow symbolic links listed on the command line

--dereference-command-line-symlink-to-dir

follow each command line symbolic link that points to a directory

--hide=PATTERN

do not list implied entries matching shell PATTERN (overridden  by  -a

or -A)

--indicator-style=WORD

append indicator with style WORD to entry names: none (default), slash

(-p), file-type (--file-type), classify (-F)

-i, --inode

print the index number of each file

-I, --ignore=PATTERN

do not list implied entries matching shell PATTERN

-k     like --block-size=1K

-l     use a long listing format

-L, --dereference

when showing file information for a symbolic  link,  show  information

for the file the link references rather than for the link itself

-m     fill width with a comma separated list of entries

-n, --numeric-uid-gid

like -l, but list numeric user and group IDs

-N, --literal

print raw entry names (don’t treat e.g. control characters specially)

-o     like -l, but do not list group information

-p, --indicator-style=slash

append / indicator to directories

-q, --hide-control-chars

print ? instead of non graphic characters

--show-control-chars

show  non graphic characters as-is (default unless program is ‘ls’ and

output is a terminal)

-Q, --quote-name

enclose entry names in double quotes

--quoting-style=WORD

use quoting style  WORD  for  entry  names:  literal,  locale,  shell,

shell-always, c, escape

-r, --reverse

reverse order while sorting

-R, --recursive

list subdirectories recursively

-s, --size

print the allocated size of each file, in blocks

-S     sort by file size

--sort=WORD

sort by WORD instead of name: none -U, extension -X, size -S, time -t,

version -v

--time=WORD

with -l, show time as WORD instead of  modification  time:  atime  -u,

access  -u, use -u, ctime -c, or status -c; use specified time as sort

key if --sort=time

--time-style=STYLE

with -l, show  times  using  style  STYLE:  full-iso,  long-iso,  iso,

locale, +FORMAT.  FORMAT is interpreted like ‘date’; if FORMAT is FOR-

MAT1FORMAT2, FORMAT1 applies to non-recent files and  FORMAT2

to  recent  files;  if  STYLE  is  prefixed with ‘posix-’, STYLE takes

effect only outside the POSIX locale

-t     sort by modification time

-T, --tabsize=COLS

assume tab stops at each COLS instead of 8

-u     with -lt: sort by, and show, access time with -l: show access time and

sort by name otherwise: sort by access time

-U     do not sort; list entries in directory order

-v     natural sort of (version) numbers within text

-w, --width=COLS

assume screen width instead of current value

-x     list entries by lines instead of by columns

-X     sort alphabetically by entry extension

-1     list one file per line

SELinux options:

--lcontext

Display security context.   Enable -l. Lines will probably be too wide

for most displays.

-Z, --context

Display security context so it fits on most displays.   Displays  only

mode, user, group, security context and file name.

--scontext

Display only security context and file name.

--help display this help and exit

--version

output version information and exit

SIZE  may  be (or may be an integer optionally followed by) one of following:

KB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.

Using color to distinguish file types is disabled both by  default  and  with

--color=never.   With  --color=auto,  ls emits color codes only when standard

output is connected to a terminal.  The LS_COLORS  environment  variable  can

change the settings.  Use the dircolors command to set it.

Exit status:

0      if OK,

1      if minor problems (e.g., cannot access subdirectory),

2      if serious trouble (e.g., cannot access command-line argument).

AUTHOR

Written by Richard M. Stallman and David MacKenzie.

REPORTING BUGS

Report ls bugs to [email protected]

GNU coreutils home page:

General help using GNU software:

AUTHOR

Written by Richard M. Stallman and David MacKenzie.

REPORTING BUGS

Report ls bugs to [email protected]

GNU coreutils home page:

General help using GNU software:

Report ls translation bugs to

COPYRIGHT

Copyright 2010 Free Software Foundation, Inc.  License GPLv3+: GNU GPL ver-

sion 3 or later .

This is free software: you are free to change and redistribute it.  There  is

NO WARRANTY, to the extent permitted by law.

SEE ALSO

The full documentation for ls is maintained as a Texinfo manual.  If the info

and ls programs are properly installed at your site, the command

info coreutils 'ls invocation'

should give you access to the complete manual.

GNU coreutils 8.4                  May 2016                              LS(1)

在这里完整的介绍了ls这个命令以及他的选项,都是英文的,可能对于刚开始学习的童鞋觉得英语是一个挑战,我想说是的,但其实计算机英语很好学习的,你不用像上学时那样去背去拼写,只要你认识他理解他的意思就好,因为我本身英文就不是很好~但只要你坚持每天都去背一些单词理解并认识它,相信不用很久就能学通了~

下面为大家简单总结了一下man命令的用法:

[root@localhost ~]# man ls

按↓或者回车:向下翻一行

按↑:向上翻一行

按空格或者PageDown:向下翻一页

按PageUp:向上翻一页

关注的点

NAME:命令的名字

SYNOPSIS:语法

DESCRIPTION:简要的描述

EXAMPLES:例子

man手册的搜索

/关键字:

假设想要查找-r选项的帮助

/-r:

输入n:继续查找下一个 next:下一个

输入N:向上搜索

man的级别:我们需要关注的级别

1 User Commands 用户命令

5 File Formats and Conventions 文件格式和约定

[root@localhost ~]# man passwd —— 查看的是passwd命令的帮助

[root@localhost ~]# man 5 passwd —— 查看的是/etc/passwd文件的帮助

除了man这个命令,我们linux还为你准备了help!救命~其实help更倾向于你本身掌握这个命令,但忘记了它的某些选项时使用的,它不像man那样详细。

这里引入一个概念:

内部命令:是shell本身自带的命令

外部命令:一般是用户安装软件之后产生的命令

[root@localhost ~]# ls --help

Usage: ls [OPTION]... [FILE]...

List information about the FILEs (the current directory by default).

Sort entries alphabetically if none of -cftuvSUX nor --sort.

Mandatory arguments to long options are mandatory for short options too.

-a, --all                  do not ignore entries starting with .

-A, --almost-all           do not list implied . and ..

--author               with -l, print the author of each file

-b, --escape               print octal escapes for nongraphic characters

--block-size=SIZE      use SIZE-byte blocks.  See SIZE format below

-B, --ignore-backups       do not list implied entries ending with ~

-c                         with -lt: sort by, and show, ctime (time of last

modification of file status information)

with -l: show ctime and sort by name

otherwise: sort by ctime

-C                         list entries by columns

--color[=WHEN]         colorize the output.  WHEN defaults to `always'

or can be `never' or `auto'.  More info below

-d, --directory            list directory entries instead of contents,

and do not dereference symbolic links

-D, --dired                generate output designed for Emacs' dired mode

-f                         do not sort, enable -aU, disable -ls --color

-F, --classify             append indicator (one of */=>@|) to entries

--file-type            likewise, except do not append `*'

--format=WORD          across -x, commas -m, horizontal -x, long -l,

single-column -1, verbose -l, vertical -C

--full-time            like -l --time-style=full-iso

-g                         like -l, but do not list owner

--group-directories-first

group directories before files.

augment with a --sort option, but any

use of --sort=none (-U) disables grouping

-G, --no-group             in a long listing, don't print group names

-h, --human-readable       with -l, print sizes in human readable format

(e.g., 1K 234M 2G)

--si                   likewise, but use powers of 1000 not 1024

-H, --dereference-command-line

follow symbolic links listed on the command line

--dereference-command-line-symlink-to-dir

follow each command line symbolic link

that points to a directory

--hide=PATTERN         do not list implied entries matching shell PATTERN

(overridden by -a or -A)

--indicator-style=WORD  append indicator with style WORD to entry names:

none (default), slash (-p),

file-type (--file-type), classify (-F)

-i, --inode                print the index number of each file

-I, --ignore=PATTERN       do not list implied entries matching shell PATTERN

-k                         like --block-size=1K

-l                         use a long listing format

-L, --dereference          when showing file information for a symbolic

link, show information for the file the link

references rather than for the link itself

-m                         fill width with a comma separated list of entries

-n, --numeric-uid-gid      like -l, but list numeric user and group IDs

-N, --literal              print raw entry names (don't treat e.g. control

characters specially)

-o                         like -l, but do not list group information

-p, --indicator-style=slash

append / indicator to directories

-q, --hide-control-chars   print ? instead of non graphic characters

--show-control-chars   show non graphic characters as-is (default

unless program is `ls' and output is a terminal)

-Q, --quote-name           enclose entry names in double quotes

--quoting-style=WORD   use quoting style WORD for entry names:

literal, locale, shell, shell-always, c, escape

-r, --reverse              reverse order while sorting

-R, --recursive            list subdirectories recursively

-s, --size                 print the allocated size of each file, in blocks

-S                         sort by file size

--sort=WORD            sort by WORD instead of name: none -U,

extension -X, size -S, time -t, version -v

--time=WORD            with -l, show time as WORD instead of modification

time: atime -u, access -u, use -u, ctime -c,

or status -c; use specified time as sort key

if --sort=time

--time-style=STYLE     with -l, show times using style STYLE:

full-iso, long-iso, iso, locale, +FORMAT.

FORMAT is interpreted like `date'; if FORMAT is

FORMAT1FORMAT2, FORMAT1 applies to

non-recent files and FORMAT2 to recent files;

if STYLE is prefixed with `posix-', STYLE

takes effect only outside the POSIX locale

-t                         sort by modification time

-T, --tabsize=COLS         assume tab stops at each COLS instead of 8

-u                         with -lt: sort by, and show, access time

with -l: show access time and sort by name

otherwise: sort by access time

-U                         do not sort; list entries in directory order

-v                         natural sort of (version) numbers within text

-w, --width=COLS           assume screen width instead of current value

-x                         list entries by lines instead of by columns

-X                         sort alphabetically by entry extension

-1                         list one file per line

SELinux options:

--lcontext                 Display security context.   Enable -l. Lines

will probably be too wide for most displays.

-Z, --context              Display security context so it fits on most

displays.  Displays only mode, user, group,

security context and file name.

--scontext                 Display only security context and file name.

--help     display this help and exit

--version  output version information and exit

SIZE may be (or may be an integer optionally followed by) one of following:

KB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.

Using color to distinguish file types is disabled both by default and

with --color=never.  With --color=auto, ls emits color codes only when

standard output is connected to a terminal.  The LS_COLORS environment

variable can change the settings.  Use the dircolors command to set it.

Exit status:

0  if OK,

1  if minor problems (e.g., cannot access subdirectory),

2  if serious trouble (e.g., cannot access command-line argument).

Report ls bugs to [email protected]

GNU coreutils home page:

General help using GNU software:

For complete documentation, run: info coreutils 'ls invocation'

和man相比是不是精简了许多呢~ 大家可以在虚拟机上试一试,如果你的练习能敲坏一个键盘,那你一定会有质的飞跃,所以多练习是学习linux的不二选择。

如何查看命令的类型? type

[root@localhost ~]# type cd ————内部命令

cd is a shell builtin //builtin:内建的

[root@localhost ~]# help cd

[root@localhost ~]# type if

if is a shell keyword //keyword:关键字 关键字也是内部命令

[root@localhost ~]# help if

[root@localhost ~]# type whoami ———— 外部命令

whoami is /usr/bin/whoami

[root@localhost ~]# whoami --help

[root@localhost ~]# ls --help

如何查看系统中有哪些内部命令?

[root@localhost ~]# help

2、 info 查看命令的来源、功能、选项等等

[root@localhost ~]# info ls

按空格向下翻页,按q退出

3、whatis 查看命令的用途的

[root@localhost ~]# whatis ls

ls (1) - list directory contents

ls (1p) - list directory contents

whatis查询时候使用的是whatis数据库

数据库文件/var/cache/man/whatis

/var :存放经常变化的数据,比如:日志、缓存等 variable:可变的、变量(忘记的复习上一节的目录结构)

命令的查看及获取帮助说完了,下面进入一个炒鸡重要的环节!vim!!! 他是linux下的文本编辑器,我们一定要熟练的使用它,以及linux文本处理三剑客,grep,sed,awk,这三个命令在以后的讲解中我们会详细的带你理解它,现在暂时不用去学习

说道vim,它和vi是什么关系呢?你可以把vim当做vi的升级版,如果你安装的虚拟机是minimal的,那你需要手动安装vim,如果是图形界面的,自带vim,建议大家前期学习都装带图形界面的,能让你有一个缓冲的时间。

vim有三种常见的工作模式

命令模式

编辑模式(插入模式)

末行模式(尾行模式)

这三种模式如何切换呢?我们看一下图片

linux查看vim 帮助,linux命令帮助及vi\vim的使用_第1张图片

在平时的使用中,打开文件后默认进入命令模式,按下aioAIO任意一个字母进入编辑模式,如果想要搜索或者设置一些选项按下Esc在按下“:”输入即可,比如我想为当前操作文本添加行号,那么我可以在末行模式下输入"set nu "回车,你会发现所有行最前面都有了标号,如果你想永久修改,需要更改配置文件:

[root@localhost ~]# vim /etc/vimrc

在最后一行添加           set nu

如果你们没看懂没关系,下面为大家总结了一些基本的使用方式:

[root@localhost ~]# vim /etc/passwd

-- 光标的移动

上:k

下:j

左:h

右:l

-- 行内跳转

快速到行首:【Home】 或者 ^(shift+6)

快速到行尾:【End】 或者 $(shift+4)

-- 行间跳转

快速回到文件的第一行:gg

到任意行: ngg (n为数字)

5gg:跳转到第5行

跳转到最后一行:G

-- 删除、剪切 delete

d

dd:删除当前行 *

ndd:删除包含当前行在内的n行 *

d$:删除从光标所在位置到行尾 *

dG:删除从当前行到文件的最后一行 *

dw:删除从当前位置到一个单词结束

x:

x:删除当前字符 (一个字符) *

X:删除光标所在位置前面的一个字符

-- 复制 y yank

yy:复制当前行

nyy:复制从当前行开始的n行

-- 粘贴 p paste

p:粘贴到当前行的下一行 *

将第8行的内容剪切到第2行下面

8gg ——> dd ——> 2gg ——> p

np:粘贴n次

3p —— 粘贴3遍

d和p组合,相当于剪切粘贴

y和p组合,相当于复制粘贴

-- 撤销 u undo

u

-- 重做 redo

ctrl + r 对撤销的反撤销操作

-- 替换 replace

r:替换当前字符

按r,输入替换后的字符

x ——> 8

操作:r -- 8

R:替换从当前位置开始的一串字符,直到按下【Esc】为止

(二)编辑模式

i:在光标前面插入新的内容

I:在当前行的行首插入内容

a:在光标后面追加新的内容 append:追加

A:在当前行的行尾插入内容

o:在当前行的下一行插入新行

O:在当前行的上一行插入新行

(三)末行模式

w —— write 写

q —— quit 退出

! —— 强制

x 也是保存

具体用法:

:wq —— 保存修改并退出 等价于 :x

:wq! —— 强制保存退出

:w —— 只保存,不退出

:1,5w /tmp/pass15 ##将文件的前5行另存到/tmp/pass15文件

:5,$w /tmp/pass666 # $表示最后一行

:q —— 不保存退出

:q! —— 不保存强制退出

:set nu —— 显示行号

:set nonu —— 取消显示行号

vim编辑器一定要用的十分熟练,以后我们搭建服务,写shell脚本等等都必不可少的,一定要多练习,以上是对于vim的一些基本的操作流程的总结,下面总结的是一些小技巧,在你将来批量修改的时候很适用!

vim的搜索

/关键字:正向搜索,从当前位置开始向下搜索

n:下一个

N:上一个

vim中的替换 ****

:s///

:s///g

:%s///

:%s///g

:5,8s///

:5,8s///g

g:全局的,替换的是一行中的多个

例子:

:s/root/666/ 将当前行第一个匹配到的root替换成666

:s/root/666/g 将当前行中所有匹配到的root替换成666

:%s/root/666/ 将整篇文件每行第一个匹配到的root替换成666

:%s/root/666/g 将整篇文件中所有匹配到的root替换成666

:1,$s/root/666/g 将整篇文件中所有匹配到的root替换成666

:5,8s/bin/8888888/g 将第5行到第8行中所有的bin替换成8888888

/// ### %%% @@@ 等价的

样例文件

1 xixihaha/dou/hehe

2 xixihaha/dou/hehe

3 xixihaha/dou/hehe

4 xixihaha/dou/hehe

5 xixihaha/dou/hehe

6 xixihaha/dou/hehe

/dou/替换成mei/shi/xian/de

:%s@/dou/@mei/shi/xian/de@

插曲

只想替换bin,不替换sbin

:5,8s/\/8888888/g

\

\

bin binary

\>:词尾定位符

bin\>

sbin bin

\ 只能是bin

^:行首定位符

$:行尾定位符

vim的其他模式

可视化模式、块选模式

删除每行的第一个字符

gg ——> Ctrl + v ——> G ——> x 或者 delete

给文件批量加注释

:%s/^/#/

用途之一:

[root@localhost ~]# cat douni.txt

#xixihaha/dou/hehe

#xixihaha/dou/hehe

#xixihaha/dou/hehe

#xixihaha/dou/hehe

#xixihaha/dou/hehe

#xixihaha/dou/hehe

批量取消注释

gg ——> Ctrl + v ——> G ——> x 或者 delete

或者

:%s/^#//

大家可以复制一些文件用来练习,比如将passwd文件复制到tmp中用vim编辑器打开进行操作。

[root@localhost ~]# cp /etc/passwd /tmp

[root@localhost ~]# vim /tmp/passwd

尽量不要去拿原来的配置文件玩耍,因为可能一不小心你的系统就起不来了~所以复制出来我们在玩耍。

cp :copy  复制的意思,后面加要复制的目录或文件  然后指定位置。

未来几天我们总的介绍一些linux入门所使用的一系列的基本命令,别着急,面包会有的,牛奶也会有的。

你可能感兴趣的:(linux查看vim,帮助)