两个有用的shell工具总结

shell工具之一:sed

sed基础

sed编辑器被称作流编辑器,与常见的交互式文本编辑器刚好相反。文本编辑器可以通过键盘来交互式地插入、删除、替换文本中的数据;而流编辑器是基于一组预先的规则来编辑数据流。

sed命令的格式如下:

sed options script file


选项


说明


-e script


将script中指定的命令添加到运行的命令中


-f file


将file中指定的命令添加到运行的命令中


-n


不为每个命令生成输出,等待print命令来输出

说明:

script用于指定作用在数据量上的单个命令。

如果需要使用多个命令,有两种选择:可以在命令行中使用-e选项指定,不同命令之间用分号隔开;或者使用-f选项在文件中指定。

默认情况下,sed编辑器将指定的命令应用到STDIN输入流上,而不作用于数据源本身,就是说sed不会修改文本文件中的原数据。

1 替换命令substitute

s/pattern/replacement/flags

flags取值如下:

数字:表示replacement将替换每行中第几次出现的pattern

g表示replacement将替换所有出现的pattern

p打印用replacement替换过的行(经常与-n选项搭配使用,-n禁止sed输出,而p会输出修改过的行,二者搭配则仅输出被replacement替换过的行)

w file将替换的结果写到file文件中(只有被替换过的行才会保存到输出文件file中)

[[email protected] shell]# cat data1
benxin benxin benxin benxin benxin
benxin benxin benxin benxin benxin
benxin benxin benxin benxin benxin

[[email protected] shell]# sed ‘s/benxin/tuzi/3‘ data1
benxin benxin tuzi benxin benxin
benxin benxin tuzi benxin benxin
benxin benxin tuzi benxin benxin

[[email protected] shell]# sed ‘s/benxin/tuzi/g‘ data1
tuzi tuzi tuzi tuzi tuzi
tuzi tuzi tuzi tuzi tuzi
tuzi tuzi tuzi tuzi tuzi

[[email protected] shell]# cat data2
benxin benxin benxin benxin benxin
benxin benxin benxin benxin benxin
benxin benxin benxin benxin benxin
hello hello hello hello hello hello

[[email protected] shell]# sed -n ‘s/benxin/tuzi/p‘ data2
tuzi benxin benxin benxin benxin
tuzi benxin benxin benxin benxin
tuzi benxin benxin benxin benxin

[[email protected] shell]# sed ‘s/benxin/tuzi/w out‘ data2
tuzi benxin benxin benxin benxin
tuzi benxin benxin benxin benxin
tuzi benxin benxin benxin benxin
hello hello hello hello hello hello

[[email protected] shell]# cat out
tuzi benxin benxin benxin benxin
tuzi benxin benxin benxin benxin
tuzi benxin benxin benxin benxin

2 指定作用行

默认情况下,sed会作用于所有行,如果只想作用于特定行,必须使用行寻址,格式如下:

[address]command或者
address
{
    command1
    command2
    command3
    ...
}

address可以使用单个行号,或者是起始行号、逗号、结尾行号指定。

[[email protected] shell]# sed ‘2s/benxin/tuzi/‘ data1
benxin benxin benxin benxin benxin
tuzi benxin benxin benxin benxin
benxin benxin benxin benxin benxin

[[email protected] shell]# sed ‘2,$s/benxin/tuzi/‘ data1
benxin benxin benxin benxin benxin
tuzi benxin benxin benxin benxin
tuzi benxin benxin benxin benxin

[[email protected] shell]# sed ‘2,${
s/benxin/tuzi/3
s/hello/world/2
}‘ data2
benxin benxin benxin benxin benxin
benxin benxin tuzi benxin benxin
benxin benxin tuzi benxin benxin
hello world hello hello hello hello

delete命令会删除指定模式的所有行,如果没有加入行寻址,则会删除流中的所有文本(并不修改原文件)。

3 插入和追加

insert命令i在指定行增加一个新行;

append命令a在指定行增加一个新行。

格式如下:

sed ‘[address]command\new line‘

[[email protected] shell]# cat data1
benxin benxin benxin benxin benxin
benxin benxin benxin benxin benxin
benxin benxin benxin benxin benxin

[[email protected] shell]# sed ‘3i\tuzi tuzi tuzi‘ data1
benxin benxin benxin benxin benxin
benxin benxin benxin benxin benxin
tuzi tuzi tuzi
benxin benxin benxin benxin benxin

[[email protected] shell]# sed ‘3a\tuzi tuzi tuzi‘ data1
benxin benxin benxin benxin benxin
benxin benxin benxin benxin benxin
benxin benxin benxin benxin benxin
tuzi tuzi tuzi

4 转换命令transform

转换命令y可以处理单个字符,格式如下:

[address]y/inchars/outchars/

用outchars的第一个字符替换inchars的第一个字符,outchars的第二个字符替换inchars的第二个字符,...,如果inchars和outchars的长度不同,则sed编辑器产生一个错误。

[[email protected] shell]# sed ‘y/bn/ti/‘ data1
teixii teixii teixii teixii teixii
teixii teixii teixii teixii teixii
teixii teixii teixii teixii teixii

5 打印命令

p: 打印文本行

=: 打印行号

l: 打印文本行和不可打印的ASCII字符

[[email protected] shell]# cat data2
benxin benxin benxin benxin benxin
benxin benxin benxin benxin benxin
benxin benxin benxin benxin benxin
hello hello hello hello hello hello

[[email protected] shell]# sed -n ‘2,4p‘ data2
benxin benxin benxin benxin benxin
benxin benxin benxin benxin benxin
hello hello hello hello hello hello

[[email protected] shell]# sed ‘=‘ data2
1
benxin benxin benxin benxin benxin
2
benxin benxin benxin benxin benxin
3
benxin benxin benxin benxin benxin
4
hello hello hello hello hello hello

[[email protected] shell]# sed -n ‘/hello/{
> =
> p
> }‘ data2
4
hello hello hello hello hello hello

[[email protected] shell]# sed -n ‘l‘ data2
benxin benxin benxin benxin benxin$
benxin benxin benxin benxin benxin$
benxin benxin benxin benxin benxin$
hello hello hello hello hello hello$

6 文件命令

[address]w filename

[address]r filename

[[email protected] shell]# cat data3
This is the line 1
This is the line 2
This is the line 3
This is the line 4

[[email protected] shell]# sed -n ‘3,4w outfile‘ data3
[[email protected] shell]# cat outfile
This is the line 3
This is the line 4

[[email protected] shell]# sed ‘1r outfile‘ data3
This is the line 1
This is the line 3
This is the line 4
This is the line 2
This is the line 3
This is the line 4

sed进阶

1 多行命令

N: 将数据流中的下一行加进来创建一个多行组

D: 删除多行组中的第一行

P: 打印多行组中的第一行

[[email protected] shell]# cat data3
This is the line 1
This is the line 2
This is the line 3
This is the line 4

[[email protected] shell]# sed ‘/line 2/{N; s/line/number/g}‘ data3
This is the line 1
This is the number 2
This is the number 3
This is the line 4

2 跳转命令

[address]b [label]

address决定了哪些行会触发跳转命令;label定义了要跳转的位置,如果没有label参数,那么将跳转到脚本的末尾。定义label:开始,最多可以有7个字符。

[[email protected] shell]# cat data3
This is the line 1
This is the line 2
This is the line 3
This is the line 4

[[email protected] shell]# sed ‘{2,3b; s/line/number/g}‘ data3
This is the number 1
This is the line 2
This is the line 3
This is the number 4

[[email protected] shell]# sed ‘{
2,3b
s/line/number/g
:label
s/the/a/g
}‘ data3
This is a number 1
This is the line 2
This is the line 3
This is a number 4

3 测试命令

[address]t [label]

测试命令的跳转不是基于地址,而是基于替换命令是否成功。如下程序每次去除一个逗号,直到一个逗号都没有时结束循环跳转。

[[email protected] shell]# echo "This,is,a,test,to,remove,commas." | sed -n ‘{
:start
s/,/ /p
t start
}‘
This is,a,test,to,remove,commas.
This is a,test,to,remove,commas.
This is a test,to,remove,commas.
This is a test to,remove,commas.
This is a test to remove,commas.
This is a test to remove commas.

4 模式替换

在行The cat sleeps in a hat中,如果想将cat和hat都加上引号,如何做呢?sed中可以使用&表示找到的匹配模式:

[[email protected] shell]# echo "The cat sleeps in a hat" | sed ‘s/.at/".at"/g‘
The ".at" sleeps in a ".at"

[[email protected] shell]# echo "The cat sleeps in a hat" | sed ‘s/.at/"&"/g‘
The "cat" sleeps in a "hat"

5 sed实例工具

# 加倍行间距G:$!G表示最后一行不加倍
[[email protected] shell]# cat data3
This is the line 1
This is the line 2
This is the line 3
This is the line 4

[[email protected] shell]# sed ‘$!G‘ data3
This is the line 1

This is the line 2

This is the line 3

This is the line 4
[[email protected] shell]#
# 行编号工具:
[[email protected] shell]# cat data3
This is the line 1
This is the line 2
This is the line 3
This is the line 4

[[email protected] shell]# sed ‘=‘ data3 | sed ‘N; s/\n/\t/‘
1       This is the line 1
2       This is the line 2
3       This is the line 3
4       This is the line 4
# 删除多余的空白行:
# 关键在于创建一个包含非空白行和一个紧挨空白行的地址区间,匹配该区间则不执行删除。
# /./,/^$/!d,/./表示至少包含一个字符的行,/^$/表示一个空行:
[[email protected] shell]# cat data4
This is the line 1

This is the line 2

This is the line 3

This is the line 4

[[email protected] shell]# sed ‘/./,/^$/!d‘ data4
This is the line 1

This is the line 2

This is the line 3

This is the line 4
# 删除开头的空行:
[[email protected] shell]# cat data5

This is the line 1

This is the line 2

This is the line 3

This is the line 4

[[email protected] shell]# sed ‘/./,$!d‘ data5
This is the line 1

This is the line 2

This is the line 3

This is the line 4
# 删除结尾的空行:
[[email protected] shell]# cat data6
This is the line 1

This is the line 2

This is the line 3

This is the line 4

[[email protected] shell]# sed ‘{
> :start
> /^\n*$/{$d; N; b start}
> }‘ data6
This is the line 1

This is the line 2

This is the line 3

This is the line 4
[[email protected] shell]#

shell工具之二:gawk

gawk基础

gawk程序是unix中原始awk程序的GNU版本。gawk提供了一种编程环境,允许修改和重新组织文件中的数据。格式如下:

gawk options program file


选项


说明


-F fs


指定行中分隔数据字段的分隔符


-f file


指定gawk程序的文件名


-v var=value


定义gawk程序中的一个变量及其默认值


-mf N


指定要处理的数据文件中的最大字段数


-mr N


指定要处理的数据文件中的最大行数


-W keyword


指定gawk的兼容模式或警告等级

gawk程序使用的脚本命令必须放在用单引号括起来的花括号中:

gawk ‘{print "hello benxintui"}‘

gawk在处理文本文件时,自动为行中的每个数据字段分配一个变量:

"$0"表示整行;

"$1"表示行中第1个字段;

"$2"表示行中第2个字段;

...

"$n"表示行中第n个字段。

gawk还可以指定程序何时运行。

在处理数据前运行脚本,可以使用BEGIN关键字:

[[email protected] shell]# cat data3
This is the line 1
This is the line 2
This is the line 3
This is the line 4

[[email protected] shell]# gawk ‘BEGIN{print "The data3 File Contents:"} {print $0}‘ data3
The data3 File Contents:
This is the line 1
This is the line 2
This is the line 3
This is the line 4

在处理数据后运行脚本,可以使用END关键字:

[[email protected] shell]# gawk ‘BEGIN{print "The data3 File Contents:"} {print $0} END{print "End of File"}‘ data3
The data3 File Contents:
This is the line 1
This is the line 2
This is the line 3
This is the line 4
End of File

gawk进阶

1 使用变量

内置变量:

1 字段和行分隔变量


变量


说明


FS


输入字段分隔符(默认为空格)


RS


输入行分隔符(默认为换行符)


OFS


输出字段分隔符(默认为空格)


ORS


输出行分隔符(默认为换行符)

[[email protected] shell]# cat data7
This,is,the,line,1
This,is,the,line,2
This,is,the,line,3
This,is,the,line,4

[[email protected] shell]# gawk ‘BEGIN{FS=","; OFS="<-->"; RS="\n"; ORS="|\n"} {print $1,$2,$3,$4,$5}‘ data7
This<-->is<-->the<-->line<-->1|
This<-->is<-->the<-->line<-->2|
This<-->is<-->the<-->line<-->3|
This<-->is<-->the<-->line<-->4|

[[email protected] shell]# gawk ‘BEGIN{FS=","; OFS="<-->"; RS="\n"; ORS="|\n"} {print $0}‘ data7
This,is,the,line,1|
This,is,the,line,2|
This,is,the,line,3|
This,is,the,line,4|

2 数据变量


变量


说明


ARGC


当前命令行参数个数


ARGV


当前命令行参数数组


ARGIND


当前文件在ARGV中的位置


CONVFMT


数字的转换格式,默认为%.6g


OFMT


数字的输出格式,默认为%.6g


ENVIRON


当前shell环境变量及其值组成的关联数组


ERRNO


错误号


FILENAME


数据文件名


FNR


数据文件中的当前行数


NF


数据文件中每行的字段数


NR


已处理的数据行数(如果同时处理多个文件,则该值会不断累加)


IGNORECASE


当其值非0时,忽略gawk命令中字符串的大小写


RLENGTH


由match匹配的子字符串的长度


RSTART


由match匹配的子字符串的起始位置

[[email protected] shell]# gawk ‘BEGIN{print ARGC, ARGV[0], ARGV[1]}‘ data7
2 gawk data7

[[email protected] shell]# gawk ‘BEGIN{print ENVIRON["HOME"]; print ENVIRON["PATH"]}‘
/root
/usr/lib/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/java/jdk1.7.0_75/bin:/usr/java/jdk1.7.0_75/jre/bin:/bigdata/hadoop-2.6.0/bin:/bigdata/hadoop-2.6.0/sbin:/usr/maven/apache-maven-3.3.3/bin:/home/benxintuzi/bin

[[email protected] shell]# gawk ‘
BEGIN{FS=","}
{print "FILENAME="FILENAME, "ARGIND="ARGIND, "NF="NF", FNR="FNR, "NR="NR}‘ data7 data7
FILENAME=data7 ARGIND=1 NF=5, FNR=1 NR=1
FILENAME=data7 ARGIND=1 NF=5, FNR=2 NR=2
FILENAME=data7 ARGIND=1 NF=5, FNR=3 NR=3
FILENAME=data7 ARGIND=1 NF=5, FNR=4 NR=4
FILENAME=data7 ARGIND=2 NF=5, FNR=1 NR=5
FILENAME=data7 ARGIND=2 NF=5, FNR=2 NR=6
FILENAME=data7 ARGIND=2 NF=5, FNR=3 NR=7
FILENAME=data7 ARGIND=2 NF=5, FNR=4 NR=8

自定义变量:

gawk变量名区分大小写。

[[email protected] shell]# gawk ‘
BEGIN{
testing="This is a test"
print testing
testing=45
print testing
}‘
This is a test
45

# 在命令行中给gawk变量赋值:
[[email protected] shell]# cat script1
BEGIN{FS=","}
{print $n}
[[email protected] shell]# gawk -f script1 n=2 data7
is
is
is
is
[[email protected] shell]# gawk -f script1 n=5 data7
1
2
3
4

2 操作数组

# 数组的定义
[[email protected] shell]# gawk ‘
> BEGIN{
> capital["China"]="beijing"
> print capital["China"]
> var[1]=20
> var[2]=10
> total=var[1] + var[2]
> print total
> }‘
beijing
30

# 数组的遍历
[[email protected] shell]# gawk ‘
BEGIN{
var["a"]=1
var["b"]=2
var["c"]=3
for (dex in var)
{
    print "Index:" dex " --- " "Value:" var[dex]
}
}‘
Index:a --- Value:1
Index:b --- Value:2
Index:c --- Value:3

# 数组元素的删除
[[email protected] shell]# gawk ‘
BEGIN{
var["a"]=1
var["b"]=2
var["c"]=3
for (dex in var)
{
    print "Index:" dex " --- " "Value:" var[dex]
}
delete var["b"]
print "-------------------"
for (dex in var)
{
    print "Index:" dex " --- " "Value:" var[dex]
}
}‘
Index:a --- Value:1
Index:b --- Value:2
Index:c --- Value:3
-------------------
Index:a --- Value:1
Index:c --- Value:3

3 使用模式

使用正则表达式来匹配时,表达式必须放到作用脚本的花括号左边:

[[email protected] shell]# cat data7
This,is,the,line,1
This,is,the,line,2
This,is,the,line,3
This,is,the,line,4

[[email protected] shell]# gawk ‘BEGIN{FS=","} /,2/{print $0}‘ data7
This,is,the,line,2

使用匹配操作符˜来匹配数据行中的特定字段,如找出以1开头的第二个字段的行,如下所示:

[[email protected] shell]# cat out1
This is a test program 2684
Loop 1
Loop 2
Loop 3
Loop 4
Loop 5
Loop 6
Loop 7
Loop 8
Loop 9
Loop 10
This is the end of program

[[email protected] shell]# gawk ‘$2 ~ /^1/{print $0}‘ out1
Loop 1
Loop 10

还可以使用比较表达式(== / <= / < / >= / >)来匹配,如显示所有属于root用户组的系统用户(组ID==0):

[[email protected] shell]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
rtkit:x:499:497:RealtimeKit:/proc:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
pulse:x:498:496:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
saslauth:x:497:76:"Saslauthd user":/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
benxintuzi:x:500:500:CentOS:/home/benxintuzi:/bin/bash
[[email protected] shell]# gawk -F: ‘$4 == 0{print $1}‘ /etc/passwd
root
sync
shutdown
halt
operator

4 结构化命令


if格式:

if (condition)

{

statements

}

else

{

statements

}


if (condition) statements; else statements


while格式:

while (condition)

{

statements

}


do

{

statements

} while (condition)


for格式:

for (assignments; condition; iteration)

5 内置函数


数学函数


说明 (采用弧度为单位)


atan2(x, y)


x/y的反正切


cos(x)


x的余弦值


exp(x)


x的指数函数


int(x)


x的整数部分


rand()


0~1的随机浮点数


sin(x)


x的正弦值


sqrt(x)


x的平方根


srand(x)


种子函数


位操作函数


说明


and(v1, v2)


v1与v2按位与


or(v1, v2)


v1与v2按位或


compl(val)


对val求补


lshift(val, count)


将val左移count位


rshift(val, count)


将val右移count位


xor(v1, v2)


v1与v2按位异或


字符串函数


说明


asort(s [, d])


对数组s按数据元素排序。排序后数组的索引值变为表示顺序的数字。如果指定了d,则将排序后的数组存储到d中


asorti(s [, d])


对数组s按索引值进行排序。排序后数组的元素为表示顺序的索引值。如果指定了d,则将排序后的数组存储到d中


gensub(r, s, h [, t])


查找变量$0或者目标字符串t来匹配正则表达式r。如果h以g/G开头,则用s替换掉匹配的文本;如果h为数字,表示要替换掉第几处匹配的文本


gsub(r, s [, t])


查找变量$0或者目标字符串t来匹配正则表达式r。如果找到了,就全部替换为字符串s


index(s, t)


返回t在s中的索引值。如果没找到,则返回0


length([s])


返回字符串s的长度。如果没有指定s,则返回$0的长度


match(s, r, [, a])


返回字符串s中正则表达式r位置的索引值。如果指定了a,则将s中匹配r的部分存储到a中


split(s, a [, r])


将s用FS字符或者r分隔开存储到a中,返回被分割的行数


sprintf(format, variables)


类似于printf


sub(r, s [, t])


在变量$0或者目标字符串t中查找正则表达式r的匹配,如果找到了,就用s替换掉第一处匹配


substr(s, i [, n])


返回s中从索引值i开始的n个字符构成的字符串。如果未指定n,则返回i开始的所有部分


tolower(s)


将s中的所有字符转换为小写


toupper(s)


将s中的所有字符转换为大写

# 按数组元素排序
[[email protected] shell]# gawk ‘
BEGIN{
var["d"]=4
var["b"]=3
var["a"]=2
var["c"]=1
asort(var, result)
for (i in result)
    print "index:" i " <---> " "value:" result[i]
}‘
index:4 <---> value:4
index:1 <---> value:1
index:2 <---> value:2
index:3 <---> value:3

# 按数组索引排序
[[email protected] shell]# gawk ‘
BEGIN{
var["d"]=4
var["b"]=3
var["a"]=2
var["c"]=1
asorti(var, result)
for (i in result)
    print "index:" i " <---> " "value:" result[i]
}‘
index:4 <---> value:d
index:1 <---> value:a
index:2 <---> value:b
index:3 <---> value:c

[[email protected] shell]# cat data7
This,is,the,line,1
This,is,the,line,2
This,is,the,line,3
This,is,the,line,4
[[email protected] shell]# gawk ‘
BEGIN{FS=","}
{
number=split($0, var)
print($number, var[1], var[2], var[3], var[4], var[5])
}‘ data7
1 This is the line 1
2 This is the line 2
3 This is the line 3
4 This is the line 4


时间函数


说明


mktime(datespec)


将一个YYYY MM DD HH MM SS [DST]格式的日期转换成时间戳


strftime(format [, timestamp])


将当前时间的时间戳转换为shell函数date()的格式


systime()


返回当前时间的时间戳

[[email protected] shell]# gawk ‘
> BEGIN{
> date=systime()
> day=strftime("%A %B %d %Y", date)
> print day
> }‘
Sunday August 16 2015

6 自定义函数

格式:

function name ([variables])

{

statements

}

函数的定义必须出现在所有代码块之前,包括BEGIN块。如果将函数放在库文件中定义,则在gawk中使用时,利用-f选项指定库文件。但是如果需要同时通过-f指定脚本文件名,则利用多次-f即可:

# 在命令行中定义函数
[[email protected] shell]# gawk ‘
function myfunc()
{
   print($1, $2, $5)
}
BEGIN{FS=","}
{ myfunc() }‘ data7
This is 1
This is 2
This is 3
This is 4

# 在库文件中定义函数
[[email protected] shell]# cat funclib
function myfunc()
{
        print($1, $2, $5)
}

[[email protected] shell]# cat script2
BEGIN{FS=","; RS="\n"}
{
        myfunc()
}

[[email protected] shell]# gawk -f funclib -f script2 data7
This is 1
This is 2
This is 3
This is 4
时间: 2024-08-25 22:26:05

两个有用的shell工具总结的相关文章

python两个有用的库工具Tornado和Fabric

Tornado 是 FriendFeed 使用的可扩展的非阻塞式 web 服务器及其相关工具的开源版本. http://www.tornadoweb.cn/ Fabric是一个Python库,可以通过SSH在多个host上批量执行任务.你可以编写任务脚本,然后通过Fabric在本地就可以使用SSH在大量远程服务器上自动运行.这些功能非常适合应用的自动化部署,或者执行系统管理任务. http://www.fabfile.org/

转:程序员必知:16个超有用的在线工具

16个超有用的在线工具,程序员们,快来MARK吧! 1. ExplainShell.com——命令解释 Linux用户每天都会写各种命令和脚本,可以使用这个网站工具来查看命令式如何工作的,这样可以避免不必要的错误出现,也是一个很好的学习命令的方式. 2. BashrcGenerator.com——定制个性命令提示符 简单说就是个性化生成命令提示符,可将生成的代码写入到用户家目录的 .bashrc 或者可以设置全局变量文件/etc/profile 对所有用户生效. 3.Vim-adventures

SVG开发包, 20 个有用的 SVG 工具,提供更好的图像处理

20 个有用的 SVG 工具,提供更好的图像处理 SVG 现正在 Web 设计领域变得越发流行, 你可以使用 Illustrator 或者 Inkscape 来创建 SVG 图像. 但当进行 Web 设计时,我们还需要做一些优化来使得 SVG 变得更加轻量. 下面介绍的 20 个工具,可以帮助你快速有效的创建 SVG 图像.现有的在线工具已经可以帮助我们进行优化.转换.新建模式等工作. 更详细的介绍,参见:How To Create SVG Animation Using CSS 交互式 SVG

[程序猿]推荐17个很有用的在线工具 - 简书

简 首页 专题 发钱啦 注册 登录 简首页 专题 下载手机应用 简书 交流故事,沟通想法 iOS· Android 显示模式 登录 下载简书移动应用 注册 登录 添加关注 作者 郭小力 2016.08.25 12:12 写了8570字,被20人关注,获得了67个喜欢 [程序猿]推荐17个很有用的在线工具 字数1032 阅读188 评论1 喜欢16 收藏文章 分享 1. ExplainShell.com 命令解释 对于Linux用户来说每天都会写各种命令和脚本,那么你可以使用这个网站工具来查看命令

为WEB程序员准备的20+有用的AngularJS工具

AngularJS是动态的Web应用程序的结构框架,最初由Misko Hevery开发,目前由谷歌维护.它有助于以灵活的方式创建Web应用程序.本篇文章就为大家分享20+非常有用个AngularJS工具. Sublime Text是一个非常有效的文本编辑器工具,易于切换项目,高度可定制.JASMINE,它基本上就是专门为JavaScript用户设计的.CodePen是前端程序员开发HTML.JS.CSS的完美编辑工具. Angular Deckgrid Angular fire Angular

使用远程shell工具SSH登录Linux主机,输完用户名回车后就卡住,10秒后才提示输入密码

使用远程shell工具SSH登录Linux主机,输完用户名回车后就卡住,10秒后才提示输入密码. 使用wireshark抓全过程包 因为ssh是加密了的协议,所以弄不懂里面内容是正常的,但可以加以过滤. 过滤栏:SSH 找到时间间隔大概为10s的NO.是x到y 过滤栏:frame.number>x&&frame.number<y 观察得出此处是DNS查询行为 原因:Linux服务器在收到SSH访问请求时,先会查询该客户端IP对应的PTR记录.假如经过5s没有收到回复,就再次发一

ipython是python的交互式shell工具

ipython: 是python的交互式shell工具,比默认的python shell工具要好用.支持变了自动补全,自动缩进,内置了很多的功能和函数 启动:可以通过cmd来启动该工具 自动补全: In [12]: import os In [13]: os.w  #直接回车,会自动显示出来该模块下的所有方法,如果我们忘记了os模块的方法具有哪些,方法记不全就可以采用这个办法os.waitpid os.walk os.write %env显示环境变量 %hist 或 %history显示历史记录

JAVA对多线程的两个有用的辅助类(CountDownLatch和AtomicBoolean)

AtomicBoolean可以让一个线程等待另一个线程完成任务后再执行: A boolean value that may be updated atomically. See the java.util.concurrent.atomic package specification for description of the properties of atomic variables. An AtomicBoolean is used in applications such as ato

二、hbase shell工具

hbase单节点安装请参考: https://www.cnblogs.com/lay2017/p/9944387.html 下文演示hbase shell工具常用的命令,首先启动hbase以及进入shell bin/start-hbase.sh hbase shell 进入shell如下 shell相关命令 查看状态 查看版本 create 以下创建了一个'test'表,以及'cf'列簇 list 列出所有的表,这里已经存在着test,userlist表 put 以下演示向test表的第1行,c