ar command

主要来自man page

语法:
ar [-X32_64] [-]p[mod] [--plugin name] [--target bfdname] [relpos] [count] archive [member...]

commonly used options

r Insert the files member... into archive (with replacement).
s Add an index to the archive, or update it if it already exists.
c Create the archive.

unix>ar rcs libvector.a mul.o add.o

GNU ar allows you to mix the operation code p and modifier flags mod in any order, within the first command-line argument. If you wish, you may begin the first command-line argument with a dash. so the following line is equivalent to the above:

unix>ar -rcs libvector.a mul.o add.o

useful parameters:

1. the above ones(rcs).
2. t: Display a table listing the contents of archive, or those of the files listed in member... that are present in the archivear.

[user@hostname arCommandLearn]$ar t libvector.a 
mulvec.o
addvec.o

3. x: Extract members (named member) from the archive.把归档文件里面的.o文件提取出来,生成相应的.o文件:

[user@hostname arCommandLearn]$ls *.o
ls: cannot access *.o: No such file or directory
[user@hostname arCommandLearn]$ar x libvector.a 
[user@hostname arCommandLearn]$ls *.o
addvec.o  mulvec.o

4. r: Insert the files member... into archive (with replacement).

[user@hostname arCommandLearn]$ar t libvector.a 
mulvec.o
addvec.o
[user@hostname arCommandLearn]$ar r subvec.o
ar: subvec.o: File format not recognized
[user@hostname arCommandLearn]$ar r libvector.a  subvec.o
[user@hostname arCommandLearn]$ar t libvector.a 
mulvec.o
addvec.o
subvec.o

5. d: Delete modules from the archive. Specify the names of modules to be deleted as member...; the archive is untouched if you specify no files to delete.

[user@hostname arCommandLearn]$ar t libvector.a 
mulvec.o
addvec.o
subvec.o
[user@hostname arCommandLearn]$ar d libvector.a  subvec.o
[user@hostname arCommandLearn]$ar t libvector.a 
mulvec.o
addvec.o

把所有有交互界面使用了readline library的程序设置为vi mode

Put *Everything* in vi Mode
put gdb into vi mode
If you're a vi user like me, try adding these two lines to your ~/.inputrc file:

set keymap vi # 实践证明,这不是必须的
set editing-mode vi #这个比较重要

对于gdb,可以有临时方法:
Over in this question about ndk-gdb I learned that C-M-j will cause gdb to enter vi mode. I tried that with gdb 7.4.1 and it worked, but I don't know about gdb 7.5. (Note: C-M-j means "Alt-Ctrl-j" for those not used to emacs nomenclature or "Esc Ctrl-j" if you don't have an Alt key.)

让一些服务在Linux开机就启动

比较通用的方法

编辑rc.local文件:#vim /etc/rc.d/rc.local
加上你想加的任何命令,比如让mysql开机启动:
/etc/init.d/mysqld start

CentOS等RedHat系列的系统特有方法

先用chkconfig list查询apache服务是否存在,不存在则需要手动添加

chkconfig -add httpd
chkconfig --level 2345 httpd on
这个方法就写这些多吧,毕竟仅限于RedHat血统的OS.想深入了解可以man一下。

xfce终端,vim编辑器中,当cursor的颜色与字符的颜色一样时,看不见字符了

编辑~/.config/xfce4/terminal/terminalrc,如果没有,手动touch一个:
[Configuration]
ColorCursor=white
MiscCursorBlinks=TRUE
# cursor设为下划线类型
MiscCursorShape=TERMINAL_CURSOR_SHAPE_UNDERLINE
# ColorCursor=
# MiscCursorShape=TERMINAL_CURSOR_SHAPE_IBEAM
# 参考: http://docs.xfce.org/apps/terminal/advanced

Linux 从dhcp服务器那里释放ip并重新获取

# dhclient -r //release ip 释放IP
# dhclient //获取IP

解决ps aux | grep COMMAND 时候把grep自己也打印的问题

场景假设,想找出当前所有进程中有mpv命令的进程。很容易想到这么做:

# 如果有mpv命令在运行:
D.Deb[dice@ dbscan]$ps aux | grep mpv
dice     10978  4.0  0.6 1338328 53284 pts/0   Sl+  10:23   0:00 mpv --no-audio-display /home/dice/Music/qitian.mp3
dice     10995  0.0  0.0  12784   908 pts/4    S+   10:23   0:00 grep --color mpv
# 如果没有mpv命令在运行:
D.Deb[dice@ dbscan]$ps aux | grep mpv
dice     10881  0.0  0.0  12784   936 pts/4    S+   10:19   0:00 grep --color mpv

ps aux | grep mpv 本身是一个包含mpv的命令,grep把自己也filt出来了,但这并不是我们想要的结果,我们想要的是没有grep本身的结果。解决方案:

# 如果有mpv命令在运行:
D.Deb[dice@ dbscan]$ps aux | grep [m]pv
dice     11038  4.0  0.6 1338328 53412 pts/0   Sl+  10:26   0:00 mpv --no-audio-display /home/dice/Music/qitian.mp3
# 如果没有mpv命令在运行:
D.Deb[dice@ dbscan]$ps aux | grep [m]pv

"mpv --no-audio-display /home/dice/Music/qitian.mp3"这个字符串可以和模式 [m]pv匹配, "grep [m]pv"和模式 [m]pv不匹配。

shell programming

if then如果在同一行,if 和then要有';'隔开,
if then如果不在同一行,if 和then没有';'隔开.

# shell guide page208
char_name()
{
_LETTERS_ONLY=$1
_LETTERS_ONLY=`echo $1 | awk '{if($0~/[^a-zA-Z]/) print "1"}'`
	if [ "$_LETTERS_ONLY" != "" ]
	then
		return 1
	else
		return 0
	fi
}

c语言中while(1) 在shell中的语法(while和`:'之间的空格不可省略).
break的用法.

# shell guide page208
while :
do
	echo "loop"
	echo -n "your first name:"
	read F_NAME
	if char_name $F_NAME
	then
		break
	else
		name_error $F_NAME
	fi
done

find exec {} + 与 find exec {} \;

from: https://unix.stackexchange.com/questions/195939/what-is-meaning-of-in-finds-exec-command
Using ; (semicolon) or + (plus sign) is mandatory in order to terminate the shell commands invoked by -exec/execdir.

The difference between ; (semicolon) or + (plus sign) is how the arguments are passed into find's  -exec/-execdir parameter. For example:

using ; will execute multiple commands (separately for each argument),

Example:

$ find /etc/rc* -exec echo Arg: {} ';'
Arg: /etc/rc.common
Arg: /etc/rc.common~previous
Arg: /etc/rc.local
Arg: /etc/rc.netboot
All following arguments to find are taken to be arguments to the command.

The string {} is replaced by the current file name being processed.

using + will execute the least possible commands (as the arguments are combined together). It's very similar to how xargs command works, so it will use as many arguments per command as possible to avoid exceeding the maximum limit of arguments per line.

Example:

$ find /etc/rc* -exec echo Arg: {} '+'
Arg: /etc/rc.common /etc/rc.common~previous /etc/rc.local /etc/rc.netboot
The command line is built by appending each selected file name at the end.

Only one instance of {} is allowed within the command.

ps command

ps命令查看程序开始时间,执行了多少时间
ps -eo cmd,pid,lstart,etime | grep main.py

向远程主机发送notify

ssh ice@192.168.40.158 'DISPLAY=:0 notify-send "TEST MESSAGE."'

把time命令的输出也重定向+后台运行

{ time ./build/tools/caffe-d train -solver models/VGGNet/VOC0712/SSD_300x300/solver.prototxt -weights models/VGGNet/VGG_ILSVRC_16_layers_fc_reduced.caffemodel ; } 2>&1 | tee train.log &

lsof

https://www.cnblogs.com/ggjucheng/archive/2012/01/08/2316599.html

diff 和patch

chrome-extension://fdpohaocaechififmbbbbbknoalclacl/capture.html?id=66&url=https%3A%2F%2Fblog.csdn.net%2Fsim120%2Farticle%2Fdetails%2F9923043
 diff patch blog image 

find -size参数

       -size n[cwbkMG]
              File uses n units of space, rounding up.  The following suffixes can be used:
              `b'    for 512-byte blocks (this is the default if no suffix is used)
              `c'    for bytes
              `w'    for two-byte words
              `k'    for Kibibytes (KiB, units of 1024 bytes)
              `M'    for Mebibytes (MiB, units of 1024 * 1024 = 1048576 bytes)
              `G'    for Gibibytes (GiB, units of 1024 * 1024 * 1024 = 1073741824 bytes)
              The  size  does not count indirect blocks, but it does count blocks in sparse files that are not actually allocated.  Bear in mind that the `%k' and `%b' format specifiers
              of -printf handle sparse files differently.  The `b' suffix always denotes 512-byte blocks and never 1024-byte blocks, which is different to the behaviour of -ls.
              The + and - prefixes signify greater than and less than, as usual; i.e., an exact size of n units does not match.  Bear in mind that the size is rounded  up  to  the  next
              unit. Therefore -size -1M is not equivalent to -size -1048576c.  The former only matches empty files, the latter matches files from 0 to 1,048,575 bytes.
-size 3k
返回 (2.0KiB, 3.0KiB]区间的文件,左开右闭
-size -3k
返回 [0.0KiB, 2.0KiB]区间的文件,左闭右闭
-size 3k 和 -size -3k刚好把 [0.0KiB, 3.0KiB]分成两个区间,没有重叠
-size 3M
返回 (2.0MiB, 3.0MiB]区间的文件,左开右闭
-size -3M
返回 [0.0MiB, 2.0MiB]区间的文件,左闭右闭
-size 3M 和 -size -3M刚好把 [0.0MiB, 3.0MiB]分成两个区间,没有重叠
 空白文件,各种大小

manually create user without useradd

Edit /etc/passwd with vipw and add a new line for the new account. Be careful with the syntax. Do not edit directly with an editor. vipw locks the file, so that other commands won't try to update it at the same time. You should make the password field be `x', so that it is impossible to log in.
Similarly, edit /etc/group with vigr, if you need to create a new group as well.
Create the home directory of the user with mkdir.
Copy the files from /etc/skel to the new home directory.
Fix ownerships and permissions with chown and chmod. The -R option is most useful. The correct permissions vary a little from one site to another, but usually the following commands do the right thing:
cd /home/newusername
chown -R username.group .
chmod -R go=u,go-w .
chmod go= .
Set the password with passwd.
After you set the password in the last step, the account will work. You shouldn't set it until everything else has been done, otherwise the user may inadvertently log in while you're still copying the files.

core file

 core file 

tcpdump

监控ssh的心跳包

source host=192.168.10.237 destination port=22303
tcpdump -n "src host 192.168.10.237 and dst port 22303"

sed:
http://www.grymoire.com/Unix/Sed.html#uh-1

linux终端光标消失

echo -e "\033[?25l"  隐藏光标
echo -e "\033[?25h" 显示光标

at命令时间格式

10K[root@ /]at 22:31 2019-12-17
warning: commands will be executed using /bin/sh
at> date >/tmp/123/bb.txt
at> <EOT>
job 4 at Tue Dec 17 22:31:00 2019

dd命令

notrunc很重要,防止truncate:
skip在输入中跳跃, seek在输出中跳跃
dd bs=1 count=2 if=a.bin of=b.bin skip=1 conv=notrunc
dd bs=1 count=2 if=a.bin of=v1_vTable.cpp skip=1 seek=2 conv=notrunc

bash return code

最好保存下来
https://tldp.org/LDP/abs/html/exitcodes.html

iptables清空

https://serverfault.com/questions/200635/best-way-to-clear-all-iptables-rules

iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -F
iptables -X


ip6tables -P INPUT ACCEPT
ip6tables -P FORWARD ACCEPT
ip6tables -P OUTPUT ACCEPT
ip6tables -F
ip6tables -X