shell 换行:
\
gcb <new_branch> && \ git push -o merge_request.create \ -o merge_request.target=$(git_develop_branch) \ -o merge_request.remove_source_branch \ -o merge_request.merge_when_pipeline_succeeds \ -o merge_request.title="<title>" \ -o merge_request.assign="<user>" \ origin $(git_current_branch) gcd -m && gbd old_branch_name
cmd 换行:
^
mvn install:install-file -Dfile=iot-tcp.jar ^ -DgroupId=com.ccc ^ -DartifactId=iot-jar ^ -Dversion=1.0.0-SNAPSHOT ^ -Dpackaging=jar
1 wget
命令描述:在终端中下载文件。
命令格式:wget [参数] 下载地址
。
参数说明:
参数 | 作用 |
---|---|
-b | 后台下载 |
-P | 下载到指定目录 |
-t | 最大重试次数 |
-c | 断点续传 |
-p | 下载页面内所有资源,包括图片、视频等 |
-r | 递归下载 |
命令使用示例:
下载一张图片到路径/root/static/img/中,-P
参数默认值为当前路径,如果指定路径不存在会自动创建。
wget -P /root/static/img/ http://img.alicdn.com/tfs/TB1.R._t7L0gK0jSZFxXXXWHVXa-2666-1500.png
输出结果:
2 curl
- -L # 直接跳转
- -s(silent) -S(–show-error)(only) # 通常一起使用,
只输出错误信息
+屏蔽错误信息
=完全静音
- -O # 保存文件,将 URL 的最后部分当作文件名,等同于
wget -P ./ url
既wget url
命令 - -o filename # 保存文件为自定文件名
- -X POST #指定请求方式
- -d -G # 设置请求体data,默认post请求,指定get请求需要单独加-G
- --data-urlencode # 设置请求体data并自动转码
- -H # header
- -A # user-agent
- -b --cookie # cookie设置
- -i # 打印响应的 HTTP 标头,再输出网页的源码
- -I # 大写的i,仅打印返回的 HTTP 标头
- -v --trace # 参数输出通信的整个过程,用于调试。–trace 会输出原始的二进制数据
## case one (POST take body request):
curl -H "Content-Type: application/json" -X POST -d '{ "cash": "123456" }' http://127.0.0.1:8001/payment
## case two (in windows, 中文注意字符集, 输入:chcp 65001):
curl -H "Content-Type: application/json" -d "{ \"cash\": \"123456\" }" http://127.0.0.1:8001/payment
## case three (sS:完全静音、L:直达、O:保存文件)
curl -sSLO https://dlcdn.apache.org/zookeeper/zookeeper-3.8.0/apache-zookeeper-3.8.0-bin.tar.gz
3 xargs(用于传参)
The term “xargs” stands for “execute arguments.”
ls |xargs -P10 -I{} git -C {} pull
-P
parallel-I
“replace string” or “input placeholder”-d
‘\t’(分割)-p
(打印询问)-t
(打印后直接执行)-L
1(max-line)-n
1(max-args)
4 awk(用于处理表格日志类数据)
- -F ‘:’(分隔符)
- ‘条件{动作}’ : ‘NR<3{print $1}’
- 函数
- tolower():字符转为小写。
- length():返回字符串长度。
- substr():返回子字符串。
- sin():正弦。
- cos():余弦。
- sqrt():平方根。
- rand():随机数。
- $1
- NF 一行个数
- NR 行数
- FS
- RS
- OFS
- ORS
- OFMT
- if
- awk -F ‘:’ ‘{if ($1 > “m”) print $1; else print “—”}’ demo.txt
4.1 sed Stream EDitor (同awk)
The sed utility reads the specified files, or the standard input if no files are
specified, modifying the input as specified by a list of commands. The input is then
written to the standard output.
A single command may be specified as the first argument to sed. Multiple commands
may be specified by using the -e or -f options. All commands are applied to the
input in the order they are specified regardless of their origin.
The following options are available:
-E Interpret regular expressions as extended (modern) regular expressions rather
than basic regular expressions (BRE's). The re_format(7) manual page fully
describes both formats.
-a The files listed as parameters for the “w” functions are created (or
truncated) before any processing begins, by default. The -a option causes
sed to delay opening each file until a command containing the related “w”
function is applied to a line of input.
-e command
Append the editing commands specified by the command argument to the list of
commands.
-f command_file
Append the editing commands found in the file command_file to the list of
commands. The editing commands should each be listed on a separate line.
The commands are read from the standard input if command_file is “-”.
-I extension
Edit files in-place, saving backups with the specified extension. If a zero-
length extension is given, no backup will be saved. It is not recommended to
give a zero-length extension when in-place editing files, as you risk
corruption or partial content in situations where disk space is exhausted,
etc.
Note that in-place editing with -I still takes place in a single continuous
line address space covering all files, although each file preserves its
individuality instead of forming one output stream. The line counter is
never reset between files, address ranges can span file boundaries, and the
“$” address matches only the last line of the last file. (See Sed
Addresses.) That can lead to unexpected results in many cases of in-place
editing, where using -i is desired.
-i extension
Edit files in-place similarly to -I, but treat each file independently from
other files. In particular, line numbers in each file start at 1, the “$”
address matches the last line of the current file, and address ranges are
limited to the current file. (See Sed Addresses.) The net result is as
though each file were edited by a separate sed instance.
-l Make output line buffered.
-n By default, each line of input is echoed to the standard output after all of
the commands have been applied to it. The -n option suppresses this
behavior.
-r Same as -E for compatibility with GNU sed.
-u Make output unbuffered.
The form of a sed command is as follows:
[address[,address]]function[arguments]
Whitespace may be inserted before the first address and the function portions of the
command.
Normally, sed cyclically copies a line of input, not including its terminating
newline character, into a pattern space, (unless there is something left after a “D”
function), applies all of the commands with addresses that select that pattern space,
copies the pattern space to the standard output, appending a newline, and deletes the
pattern space.
Some of the functions use a hold space to save all or part of the pattern space for
subsequent retrieval.
5 ln(创建,修改,删除软连接)
- -s (加-s是软链接,不加是硬链接,软链接是快捷方式,随源文件消亡,硬链接是指针,指向源文件地址,删了还有,删除只是该地址无主了,硬链接保存的地址还在)
ln -s sourcefile linkfile
- -snf 修改软链接
- 删除:
unlink linkfile
(格式: unlink 链接源 [原文件或目录])rm -rf linkfile
(注意后面别带/
,带了会删除链接的源文件夹。)rm linkfile
# rm linkrm -r linkfile
# rm -r link 这里的参数 r 其实是没有意义的, 因为link是一个软连接 不是目录
6 tail
- -f 追加
- -n 行数
tail -fn 10 /var/log/messages
7 shell 多条命令关联
&&
代表上一个成功才执行下一个;||
代表上一个失败才执行下一个;; 分号
代表无关联顺序执行;&
代表前一个命令进入后台立即执行后面的命令;
8 cat 展示小文件
-n
显示行号
-b
或 --number-nonblank
显示行号但是不对空行进行编号
-s
或 --squeeze-blank
合并连续两行以上的空行
9 more 和 less 的区别:
- more like cat
- less like vim
同样是分页查看文件, 但实现方式不同. more 类似于echo 或 cat 的方式输出到屏幕上, 而 less 类似于 vim 到方式占满一个屏幕,退出后没有残留。
10「more」不能指定行数, 而「head、tail」可以指定行数的命令 (cat like):
- head 命令指定从前往后显示的行数的内容。(-c指定字符 -n指定行数 -q不显示文件名)
- tail 命令用于查看文档的后N行或持续刷新内容。(多了一个 -f 可以附加显示)
head -n 5 /etc/passwd # 可以省略为 head -5 /etc/passwd
tail -f -n 5 /etc/passwd # 有多个参数, 不能省略-n