01/22/2020
-
NFS network file system, list nfs port: https://serverfault.com/questions/377170/which-ports-do-i-need-to-open-in-the-firewall-to-use-nfs
1
rpcinfo -p | grep nfs
It depends on the version of the protocol you intent to use. NFS 4 only require
2049
while older versions require more. -
setup nfs cluster to prevent single point of failure https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/high_availability_add-on_administration/ch-nfsserver-haaa
02/26/2020
-
如果不想让一个executable 执行多次,可以在每次run的时候在当前或固定文件夹create一个hidden file, for example:
.commad.lock
,然后写入当前正在run的command 参数等。通过检查这个file是否存在去决定是不是正在执行。 -
redhat 一个很不错的网站: https://www.redhat.com/sysadmin/
-
command
uuidgen
可以用来generate random unique number.
04/07/2020
find
softlink file, use typel
:
1 | find . -type l -name dsenv |
or use -L
, then the -type
predicate will always match against the type of the file that a symbolic link points to rather than the link itself (unless the symbolic link is broken).
1 | find -L / type f -name dsenv |
类似于readlink
, 会去softlink directory里面寻找original file.
04/09/2020
-
> /dev/null 2>&1
can be written as&> /dev/null
-
su
vssu -
. 都是login to another user,-
表示normal login,login后会完全变成当前user的初始环境,比如在当前user的home dir且$PATH也是当前user的。没有-
, 则会继承上个user的环境,比如dir还是上次的。2个login都会执行~/.bashrc.
04/18/2020
- 在pod container中,如果script process不是init process (pid 1),那么script中的trap 内容不会被执行。 还不太清楚为什么(这是docker container的一个特性)
04/26/2020
declare -F
show function name in current shelldeclare -f
show function definition in current shell,declare -f <f name>
get just that definition
06/16/2020
- 很多build可以用Makiefile + make command去实现,应该是一个通用的工具。
06/21/2020
- What is the difference between “#!/usr/bin/env bash” and “#!/usr/bin/bash”?
Using
#!/usr/bin/env NAME
makes the shell search for the first match of NAME in the$PATH
environment variable. It can be useful if you aren’t aware of the absolute path or don’t want to search for it.
06/24/2020
bash -x ./script
, no needset -x
06/25/2020
- script performance comparison
strace -c ./script
. 也就是说,多用bash internal command fromhelp
.-c
will output show system time on each system call.
06/26/2020
- Create custom systemd service: https://medium.com/@benmorel/creating-a-linux-service-with-systemd-611b5c8b91d6. Interesting. 印象里面和当时设置K8s systemd 有点类似.
07/05/2020
shopt -s nocasematch
, set bash case-insensitive match incase
or[[ ]]
condition. 这个是从bash tutorial 中文版中学到的,shopt
is bash built-in setting, unlikeset
is from POSIX.
07/09/2020
- vim can directly operate on file in tarball:
vim xx.tgz
then save the changes
07/12/2020
- Database SQL course online from Stanford or Edx.com
07/29/2020
!!
re-execute last command.!<beginning token>
re-execute last command start with this token.$_
last token in last command line
08/22/2020
- Interesting: top 10 most used CLI:
history | awk {'print $2'} | sort | uniq -c | sort -nr | head -n 10
- same idea to check my blog theme:
ls -ltr | awk 'NR>1 {print $NF}' | cut -d'-' -f1 | sort | uniq -c | sort
09/09/2020
- Mac netstat list listening port, the
netstat
on Mac is not that powerful as on Linux:1
2
3
4
5
6
7
8
9## -p: protocol
## -n: numerical address
## -a: show all connections
netstat -an -ptcp | grep -i listen
## or
## -i: lists IP sockets
## -P: do not resolve port names
## -n: do not resolve hostnames
lsof -i -P -n | grep -i "listen"
09/18/2020
- Interesting project https://github.com/hubotio/hubot
seq
commands, i.e.seq 1 9
generate sequence 1 to 9, used in shell for loop as counter.
10/25/2020
- Interesting,
ed
editor: https://sanctum.geek.nz/arabesque/actually-using-ed/ Dash
is a Mac app browser APITypora
markdown editor
11/03/2020
Known from IBM channel, docker security talk
- docker security scan
- k8s cilium: securing the network connectivity between application
11/20/2020
-
shell nop command:
:
, synopsis istrue
, do nothing, similar topass
in python1
2
3
4
5## : as true
while :; do
sleep 1
echo 1
done -
shell mutliline comment, can use heredoc
1
2
3: <<'COMMENT'
...
COMMENT
11/24/2020
- python shebang:
1 | #!/usr/bin/env python |
11/27/2020
ls -1
每行只输出一个文件名.mv -v
verbose
12/06/2020
- bash read file line by line
1 | cat $file | while read line |
12/09/2020
- sudo to edit restricted permission file:
1 | # executing as non-root user |
12/10/2020
- semantic versioning major.minor.patch
12/25/2020
cat jsonfile | python -m json.tool
和jq
类似,一个json的format工具,但只能pretty print.- sudo: unable to resolve host: 我不太理解为什么sudo 会涉及到hostname resolution?