Introduction: Next Linux Learning (ii) VIM text editor says vim text editor
u 撤销最近的更改 /* 撤销之前多次更改 U? 撤消光标落在这行后所有此行的更改 按ctrl?+ r 重做最后的“撤消”更改 . 重复前一个操作 n. 重复前一个操作n次 退出模式下 e! 直接还原到文件最初打开状态
v 面向字符选中 V 面向行选中 ctrl + v 面向块选中
配置文件:永久有效 全局: /etc/vimrc 个人: ~/.vimrc
扩展模式:当前vim进程有效 set nu 显示行号 set ic 忽略大小写
Four, shell scripting Basics 1.shell Scripting Basics
格式要求:首行shabang机制 "#!/bin/bash" "#!/usr/bin/python" "#!/usr/bin/perl"
2. Create a shell script
使用文本编辑器(例如vim)创建文本文件 第一行必须包括shell声明序列: "#!" 例如:"#!/bin/bash" 添加注释 注释以 "#" 开头
shell脚本示例
脚本调试 检测脚本中的语法错误 bash -n 调试执行 bash -x
3. Local Variables
变量赋值: name=‘value’ 可以使用引用value: (1) 可以是直接字串:name= "root" (2) 变量引用: name="$USER" (3) 命令引用: name=`COMMAND` name=$(COMMAND)
变量引用: ${name} $name "":弱引用,其中的变量引用会被替换为变量值 ‘‘:强引用,其中的变量引用不会被替换为变量值,而保持原字符串
4. Exit status
进程使用退出状态来报告成功或失败 0 代表成功, 1-255代表失败 $? 变量保存最近的命令退出状态 (echo执行)
5. Arithmetic operations
实现算数运算 var=$[ 算术表达式 ] var=$(( 算术表达式 )) echo ‘算术表达式’ | bc
? What are the useful shortcuts when writing scripts ?
CTRL + Z can be saved to the background when writing scripts
?? FG back to Background script
BG See how many backstage
?? Shift +^ jumps to the beginning of the line
?? Shift +$ jumps to the end of the line
?? : e! Restore directly to the original state of the file
6. Logical operation
! 非,取反向结果( ! 加到前面,后面要有空格)
7. Condition Testing
test [ ] [[ ]]
There must be a white space character before and after the brackets
/usr/bin/[ 相当于test man test 整理命令选项(解释很详尽,随时用随时查)
执行操作符 && 并且,同时为真为真 相当于‘ -a‘ || 或者,有一个假为假 相当于‘-o‘
used in [[]]
数值测试 -gt 是否大于 -ge 是否大于等于 -eq 是否等于 -ne 是否不等于 -lt 是否小于 -le 是否小于等于
There is a space before the space
字符串测试 == 是否等于 != 是否不等于 =~ 左侧的字符串能否匹配右面的模式 -z 字符串是否为空 -n 字符串是否为不空
Strings generally need to be caused by ""
文件测试 文件存在性及类别测试 -e FILE: 文件存在性测试,存在为真,否则为假 -f FILE:是否存在且为普通文件 文件权限测试: -r FILE:是否存在且可读 -w FILE: 是否存在且可写 -x FILE: 是否存在且可执行 文件特殊权限测试: -u FILE:是否存在且拥有suid权限 -g FILE:是否存在且拥有sgid权限 -k FILE:是否存在且拥有sticky权限 文件大小测试 -s FILE: 是否存在且非空
8.read command
read 接受输入 -p 显示输入的内容 -s 静默,不显示输入的内容 -t N 控制输入时间 -n N 控制输入字符的最大长度 -d 字符 结束符
Usually-P puts the last
9.bash configuration file
全局配置 /etc/profile /etc/profile.d/*.sh /etc/bashrc个人配置 ~/.bashrc ~/.bashrc_profileprofile 类 /etc/profile /etc/profile.d/*.sh ~/.bashrc_profile 控制 : 环境变量 ; 运行命令或脚本bashrc 类 /etc/bashrc ~/.bashrc 控制 : 命令别名和函数 ; 本地变量修改配置文件生效方法 重启shell进程 . 或 source(后面接文件路径命,中间有空格)
10. Two ways to log in
交互式登录 直接通过终端输入账号密码登录 使用“su - UserName” 切换的用户 执行顺序: /etc/profile --> /etc/profile.d/*.sh --> ~/.bash_profile --> ~/.bashrc --> /etc/bashrc 非交互式登录 可以继承 su UserName 图形界面下打开的终端 执行脚本 任何其它的bash实例 执行顺序: ~/.bashrc --> /etc/bashrc --> /etc/profile.d/*.sh
Additional information about what you might be able to use
-: Normal file
D: Catalog file
B: Block device
C: Character device
L: Symbolic Link file
P: Piping File pipe
S: Socket file socket
Wall Broadcast
PING-W1-C1 is executed only once and waits one second
Stty-echo knocking command does not show no line break
Stty Echo Lift
Linux Learning (iii)