bash中一串命令的执行()与{}
bash中一串命令执行用()和{}区别
- ()只是对一串命令重新开一个子shell进行执行
- {}对一串命令在当前shell执行
- ()和{}都是把一串的命令放在括号里面,并且命令之间用;号隔开
- ()最后一个命令可以不用分号
- {}最后一个命令要用分号
- {}的第一个命令和左括号之间必须要有一个空格
- ()里的各命令不必和括号有空格
- ()和{}中括号里面的某个命令的重定向只影响该命令,但括号外的重定向则影响到括号里的所有命令
References:
[1]shell中的(),{}几种语法用法
nodetool自动监控bootstrapping\repairing\rebuilding进度
不用其他监控套件,只是用nodetool工具借助netstats指令简单的监控收发数据流进度:
1 | watch -n 10 'nodetool netstats | grep "Receiving\|Sending" | gawk {'"'"' print $1" - "$11/$4*100"% Complete, "($4-$11)/1024/1024/1024" GB remaining" '"'"'}' |
References:
[1]On Cassandra Stream Monitoring
vim技巧两则:使用数字序列替换匹配的pattern和插入数字序列
使用数字序列替换
vim查找替换时,可以使用一个数字序列来替换匹配的内容
1 | :let i=1 \[range\]g/PATTERN/s//\\=i/g let i=i+1 |
插入数字序列
1 | :put =range(11,15) |
可以在文件当前行后插入5行:
1 | 11 |
函数式替换
在替换命令 s/// 中可以使用函数表达式来书写替换内容,格式为
1 | :s/替换字符串/\\=函数式 |
在函数式中可以使用 submatch(1)、submatch(2) 等来引用 \1、\2 等的内容,而submatch(0)可以引用匹配的整个内容。
举个栗子,将文件从第一行开始的行首替换为如下样式:
1 | mem\[0\]= |
可以执行如下替换:
1 | :%s/^/\\='mem\['.(line(".")-1).'\]=' |
References:
[1]Making a list of numbers
[2]vi/vim的巧妙使用-数值加减,递增,序列等
nginx for windows x64
Kevin Worthington 一直在维护nginx for windows x64版本的build,致敬。
linux 修改按键映射
xmodmap(X modify key map)可以修改X下的键位映射
比如0现在用的键盘没有右边的CTRL,很难用,右侧的INSERT键刚好在空格右侧不远的地方,可以把它修改为右CTRL
可以使用xev程序来查看当前的keymap,可以看到右侧的INSERT键位映射为:
1 | KeyPress event, serial 33, synthetic NO, window 0x2a00001, |
导出原映射
1 | $ xmodmap -pke > ~/.Xmodmap |
修改映射
控制键要先clear,最后再add
编辑.Xmodmap文件,文件开头处添加
1 | clear Control |
将keycode 118修改为
1 | keycode 118 = Control_R NoSymbol Control_R |
然后文件尾部添加
1 | add Control = Control_L Control_R |
测试配置
修改好映射文件后
1 | $ xmodmap ~/.Xmodmap |
GDM,XDM和LightDM在开启xsession时会自动读取$HOME/.Xmodmap,但不稳定,时好时坏:(
使用startx时激活你自己的映射表,请添加下面的文件和内容:
1 | ~/.xinitrc |
References:
[1]Xmodmap
[2]linux下修改键位映射
bash $-变量
MacOS missing xcrun问题
升级MacOS后brew upgrade经常会出现如下错误:
1 | The bottle needs the Apple Command Line Tools to be installed. |
是因为系统升级后没有安装相应版本的Apple Command Line Tools
解决办法就是像错误提示里说的一样:
1 | $ xcode-select --install |
wine中文字体链接
字体链接
M$的字体是专有的,有版权的,因此应该使用开源字体。
Windows支持字体链接:当一种字体中不存在某个字时,可以尝试从另一个字体文件中寻找相应的字形。所以只要把当前系统中的中文字体设为”fallback”字体,汉字通常就能正确显示了。方法也很简单,只需创建一个文本文件,如chn_font.reg如下:
1 | REGEDIT4 |
注意请将wqy-microhei.ttc替换为你系统中的字体文件名,如文泉驿正黑是wqy-zenhei.ttc(请在/usr/share/fonts及其子文件夹中寻找相应字体文件)。
MacOSX上可以使用PingFang.ttc。
如果想使用其它字体,也可直接将相应的ttf或ttc文件复制到~/.wine/drive_c/windows/Fonts/,再用其文件名替换上面的wqy-zenhei.ttc即可。
最后,打开注册表wine regedit,导入上面的注册表文件即可。中文应该都能完美显示了(包括Picasa中文显示为方框、软件安装程序汉字无法显示等问题均可被解决)。
1 | $ wine regedit chn_font.reg |
注意上面的注册表键值只能使用字体的文件名,而不能使用字体名,这是由“字体链接”本身的特性决定的。
References:
[1]Wine的中文显示与字体设置
systemd的模板单元文件和实例单元文件
模板单元文件和实例单元文件
使用模板,一个模板单元(unit)文件可以创建多个实例化的单元文件,从而简化系统配置。
模板单元文件的文件名中包含一个@符号,@位于单元基本文件名和扩展名之间,比如:
1 | example@.service |
当从模板单元文件创建实例单元文件时,在@符号和单元扩展名(包括符号.)之前加入实例名,比如:
1 | example@instance1.service |
表明实例单元文件example@instance1.service实例化自模板单元文件example@.service,其实例名为instance1
实例单元文件一般是模板单元文件的一个符号链接,符号链接命中包含实例名,systemd就会传递实例名给模板单元文件。
在相应的target中创建实例单元文件符号链接之后,需要运行一下命令将其装载:
1 | $ sudo systemctl daemon-reload |
模板标识符/参数
模板单元文件中可以使用一些标识符,当被实例化为实例单元文件并运行时,systemd会将标识符的实际值传递给对应的标识符,比如在模板单元文件中是用%i,实际运行实例单元文件时,会将实例名传递给%i标识符。
有以下可用的标识符:
%n: Anywhere where this appears in a template file, the full resulting unit name will be inserted.
%N: This is the same as the above, but any escaping, such as those present in file path patterns, will be reversed.
%p: This references the unit name prefix. This is the portion of the unit name that comes before the @ symbol.
%P: This is the same as above, but with any escaping reversed.
%i: This references the instance name, which is the identifier following the @ in the instance unit. This is one of the most commonly used specifiers because it will be guaranteed to be dynamic. The use of this identifier encourages the use of configuration significant identifiers. For example, the port that the service will be run at can be used as the instance identifier and the template can use this specifier to set up the port specification.
%I: This specifier is the same as the above, but with any escaping reversed.
%f: This will be replaced with the unescaped instance name or the prefix name, prepended with a /.
%c: This will indicate the control group of the unit, with the standard parent hierarchy of /sys/fs/cgroup/ssytemd/ removed.
%u: The name of the user configured to run the unit.
%U: The same as above, but as a numeric UID instead of name.
%H: The host name of the system that is running the unit.
%%: This is used to insert a literal percentage sign.
References:
[1] Understanding Systemd Units and Unit Files