📄 01. unix note.txt
字号:
dw 删除词,剪切词。 ( 3dw删除 3 单词)
cw 替换一个单词。 (cw 和 dw 的区别 cw 删除某一个单词后直接进入编辑模式,而dw删除词后仍处于命令模式)
cc 替换一行
C 替换从光标到行尾
yy 复制行 (用法同下的 Y ,见下行)
Y 将光标移动到要复制行位置,按yy。当你想粘贴的时候,请将光标移动到你想复制的位置的前一个位置,然后按 p
yw 复制词
p 当前行下粘贴
1,2co3 复制行1,2在行3之后
4,5m6 移动行4,5在行6之后
u 当你的前一个命令操作是一个误操作的时候,那么可以按一下 u键,即可复原。只能撤销一次
r file2 在光标所在处插入另一个文件
~ 将字母变成大写
J 可以将当前行与下一行连接起来
/字符串 从上往下找匹配的字符串
?字符串 从下往上找匹配的字符串
n 继续查找
1,$s/旧串/新串/g 替换全文(或者 %s/旧串/新串/g)
(1表示从第一行开始) 没有g则只替换一次,加g替换所有
3、存盘和退出
w 存盘
w newfile 存成新文件
wq 存盘再退出VI(或者ZZ或 X)
q! 强行退出不存盘
查看用户
users 显示在线用户(仅显示用户名)。
who 显示在线用户,但比users更详细,包括用户名、终端号、登录时间、IP地址。
who am i 仅显示自己,(但包括用户名、端口、登录时间、IP地址;信息量=who)。
whoami 也仅显示自己,但只有用户名(仅显示自己的有效的用户名)。
w 显示比who更多内容,还包括闲置时间、占CPU、平均占用CPU、执行命令。
用法 w [ -hlsuw ] [ 用户 ]
su 改变用户,需再输入密码。
用法 su [-] [ username [ arg ... ] ]
su - 相当于退出再重新登录。
查找
find 查找文件
用法 find [-H | -L] 路径列表 谓词列表
find / -name perl 从根目录开始查找名为perl的文件。
find . -mtime 10 -print 从当前目录查找距离现在10天时修改的文件,显示在屏幕上。
(注 “10”表示第10天的时候;如果是“+10”表示10天以外的范围;“-10”表示10天以内的范围。)
grep 文件中查找字符;有过滤功能,只列出想要的内容
用法 grep -hblcnsviw 模式 文件 . . .
如 grep abc /etc/passwd 在passwd文件下找abc字符
wc 统计
-l 统计行数; -w统计单词数; -c 统计字符数
如 grep wang /etc/passwd|wc -l 统计passwd文件含“wang”的行数
du 查看目录情况
如 du -sk * 不加-s会显示子目录,-k按千字节排序
用法 du [-a] [-d] [-h|-k] [-r] [-o|-s] [-H|-L] [文件...]
进程管理
ps 显示进程。
用法 ps [ -aAdeflcjLPyZ ] [ -o 格式 ] [ -t 项列表 ]
[ -u 用户列表 ] [ -U 用户列表 ] [ -G 组列表 ]
[ -p 进程列表 ] [ -g 程序组列表 ] [ -s 标识符列表 ] [ -z 区域列表 ]
ps 显示自己的进程。
ps -e 显示每个进程,包括空闲进程。
ps -f 显示详情。
ps -ef 组合-e和-f,所有进程的详情。
ps -U uidlist(用户列表) 具体查看某人的进程。
kill
pkill
sleep
jobs
用法 jobs [-l ]
fg %n
bg %n
stop %n 挂起(仅csh能用)
Ctrl+C
Ctrl+Z
网络链接
ping
usage ping host [timeout]
usage ping -s [-l | U] [adLnRrv] [-A addr_family] [-c traffic_class] [-g gateway [-g gateway ...]] [-F flow_label] [-I interval] [-i interface] [-P tos] [-p port] [-t ttl] host [data_size] [npackets]
ifconfig -a
/sbin/ifconfig 查看本机的IP地址
netstat -rn
rlogin
ftp
帮助文件 [sd0807@localhost ~]$ help
GNU bash, version 3.1.17(1)-release (i686-redhat-linux-gnu)
These shell commands are defined internally. Type `help' to see this list.
Type `help name' to find out more about the function `name'.
Use `info bash' to find out more about the shell in general.
Use `man -k' or `info' to find out more about commands not in this list.
A star (*) next to a name means that the command is disabled.
JOB_SPEC [&] (( expression ))
. filename [arguments]
[ arg... ] [[ expression ]]
alias [-p] [name[=value] ... ] bg [job_spec ...]
bind [-lpvsPVS] [-m keymap] [-f fi break [n]
builtin [shell-builtin [arg ...]] caller [EXPR]
case WORD in [PATTERN [| PATTERN]. cd [-L|-P] [dir]
command [-pVv] command [arg ...] compgen [-abcdefgjksuv] [-o option
complete [-abcdefgjksuv] [-pr] [-o continue [n]
declare [-afFirtx] [-p] [name[=val dirs [-clpv] [+N] [-N]
disown [-h] [-ar] [jobspec ...] echo [-neE] [arg ...]
enable [-pnds] [-a] [-f filename] eval [arg ...]
exec [-cl] [-a name] file [redirec exit [n]
export [-nf] [name[=value] ...] or false
fc [-e ename] [-nlr] [first] [last fg [job_spec]
for NAME [in WORDS ... ;] do COMMA for (( exp1; exp2; exp3 )); do COM
function NAME { COMMANDS ; } or NA getopts optstring name [arg]
hash [-lr] [-p pathname] [-dt] [na help [-s] [pattern ...]
history [-c] [-d offset] [n] or hi if COMMANDS; then COMMANDS; [ elif
jobs [-lnprs] [jobspec ...] or job kill [-s sigspec | -n signum | -si
let arg [arg ...] local name[=value] ...
logout popd [+N | -N] [-n]
printf [-v var] format [arguments] pushd [dir | +N | -N] [-n]
pwd [-LP] read [-ers] [-u fd] [-t timeout] [
readonly [-af] [name[=value] ...] return [n]
select NAME [in WORDS ... ;] do CO set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
shift [n] shopt [-pqsu] [-o long-option] opt
source filename [arguments] suspend [-f]
test [expr] time [-p] PIPELINE
times trap [-lp] [arg signal_spec ...]
true type [-afptP] name [name ...]
typeset [-afFirtx] [-p] name[=valu ulimit [-SHacdfilmnpqstuvx] [limit
umask [-p] [-S] [mode] unalias [-a] name [name ...]
unset [-f] [-v] [name ...] until COMMANDS; do COMMANDS; done
variables - Some variable names an wait [n]
while COMMANDS; do COMMANDS; done { COMMANDS ; }
输入 man help
BASH_BUILTINS(1) BASH_BUILTINS(1)
NAME
bash, :, ., [, alias, bg, bind, break, builtin, cd, command, compgen, complete, continue,
declare, dirs, disown, echo, enable, eval, exec, exit, export, fc, fg, getopts, hash, help,
history, jobs, kill, let, local, logout, popd, printf, pushd, pwd, read, readonly, return,
set, shift, shopt, source, suspend, test, times, trap, type, typeset, ulimit, umask, una-
lias, unset, wait - bash built-in commands, see bash(1)
BASH BUILTIN COMMANDS
Unless otherwise noted, each builtin command documented in this section as accepting options
preceded by - accepts -- to signify the end of the options. For example, the :, true,
false, and test builtins do not accept options.
: [arguments]
No effect; the command does nothing beyond expanding arguments and performing any
specified redirections. A zero exit code is returned.
. filename [arguments]
source filename [arguments]
Read and execute commands from filename in the current shell environment and return
the exit status of the last command executed from filename. If filename does not
contain a slash, file names in PATH are used to find the directory containing file-
name. The file searched for in PATH need not be executable. When bash is not in
posix mode, the current directory is searched if no file is found in PATH. If the
sourcepath option to the shopt builtin command is turned off, the PATH is not
searched. If any arguments are supplied, they become the positional parameters when
filename is executed. Otherwise the positional parameters are unchanged. The return
status is the status of the last command exited within the script (0 if no commands
are executed), and false if filename is not found or cannot be read.
alias [-p] [name[=value] ...]
Alias with no arguments or with the -p option prints the list of aliases in the form
alias name=value on standard output. When arguments are supplied, an alias is
defined for each name whose value is given. A trailing space in value causes the
next word to be checked for alias substitution when the alias is expanded. For each
name in the argument list for which no value is supplied, the name and value of the
alias is printed. Alias returns true unless a name is given for which no alias has
been defined.
bg [jobspec ...]
Resume each suspended job jobspec in the background, as if it had been started with
&. If jobspec is not present, the shell’s notion of the current job is used. bg
jobspec returns 0 unless run when job control is disabled or, when run with job con-
trol enabled, any specified jobspec was not found or was started without job control.
bind [-m keymap] [-lpsvPSV]
bind [-m keymap] [-q function] [-u function] [-r keyseq]
bind [-m keymap] -f filename
bind [-m keymap] -x keyseq:shell-command
bind [-m keymap] keyseq:function-name
bind readline-command
Display current readline key and function bindings, bind a key sequence to a readline
function or macro, or set a readline variable. Each non-option argument is a command
as it would appear in .inputrc, but each binding or command must be passed as a sepa-
rate argument; e.g., ’"\C-x\C-r": re-read-init-file’. Options, if supplied, have the
following meanings:
-m keymap
Use keymap as the keymap to be affected by the subsequent bindings. Accept-
able keymap names are emacs, emacs-standard, emacs-meta, emacs-ctlx, vi,
vi-move, vi-command, and vi-insert. vi is equivalent to vi-command; emacs is
equivalent to emacs-standard.
-l List the names of all readline functions.
-p Display readline function names and bindings in such a way that they can be
re-read.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -