opskumu / issues

利用 issues 管理技术 tips
https://github.com/opskumu/issues/issues
80 stars 5 forks source link

Linux command tips #9

Closed opskumu closed 5 years ago

opskumu commented 8 years ago

ln

➜  ~ ln -snf <源目录> <链接文件>
opskumu commented 7 years ago

IO

# iostat 1
# sar -b 1
cat /sys/block/vda/queue/scheduler

CFQ (the default scheduler nowadays) aggregates all ideas from above and adds cgroup support that allows to reserve some amount of IO to a specific cgroup. It is useful on shared (and cloud) hosting - users who paid for 20 IO/s want to get their share if needed.

The characteristics of a SSD are different. It does not have moving parts. Random access is as fast as sequential one. An SSD can handle multiple requests at the same time. Modern devices' throughput ~10K IO/s, which is higher than workload on most systems. Essentially a user cannot generate enough requests to saturate a SDD, the requests queue is effectively always empty. In this case IO scheduler does not provide any improvements. Thus, it is recommended to use the noop scheduler for an SSD.

kvm io

opskumu commented 7 years ago

tcpdump

tcpdump -vv -i eth0 -n arp
tcpdump -vv -i eth0 -nn icmp and host 172.16.0.1
opskumu commented 7 years ago

Git

删除 git 仓库历史大文件

Removes large or troublesome blobs

opskumu commented 7 years ago

磁盘健康检测

opskumu commented 7 years ago

sed

sed -i 's/first/FIRST/g; s/second/SECOND/g; s/third/THIRD/g;' test.txt
opskumu commented 7 years ago

对应网卡配置文件添加 MAC 地址解决问题

# /etc/sysconfig/network-scripts/ifcfg-eth0
... ...
HWADDR=00:xx:xx:xx:xx:xx
... ...

Disabling NetworkManager on RHEL 7

opskumu commented 7 years ago

终端 http/https 代理设置

export http_proxy=x.x.x.x:xx https_proxy=x.x.x.x:xx 
opskumu commented 7 years ago

Linux shell

Here-doc

Here document 可以不顶格写,通过 <<- 实现,另外必须使用 tab 分隔而不是空格键

#! /bin/bash
cat <<-EOF
    indented
    EOF

Note that you must use tabs, not spaces to indent the here-doc. Can't indent heredoc to match nesting's indent

opskumu commented 7 years ago

RHEL6 respawn script

On RHEL 6 to respawn a script, go to /etc/init and create a file

cd /etc/init
vi scriptFileName.conf

And add this content

start on stopped rc RUNLEVEL=[12345]
stop on runlevel [!12345]
respawn
exec /you/respawned/script.sh -your -parameters

Save file and then launch this command (without .conf of file)

start scriptFileName
opskumu commented 7 years ago

随机密码

pwmake 用于生成随机密码,可由四种字符组成:大写字母小写字母数字特殊符号。熵值产生于 /dev/urandom,指定最小熵值为 56 位。创建一个 128 位的密码,则要运行下列命令:

pwmake 128
opskumu commented 7 years ago

cloc 代码统计

➜  ~ cloc ./
    1389 text files.
    1250 unique files.
     195 files ignored.

github.com/AlDanial/cloc v 1.72  T=14.26 s (83.8 files/s, 56992.9 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Go                            1094          43245          51420         703157
Markdown                        39           1127              0           3525
Protocol Buffers                23           1412           3120           2474
JSON                             4              2              0           1965
Bourne Shell                     7             42             53            253
C                                3             39             11            245
YAML                            15             50             31            232
Python                           1             14             13             99
make                             5             36             68             99
C/C++ Header                     2             14              8             55
Dockerfile                       2             14              9             46
-------------------------------------------------------------------------------
SUM:                          1195          45995          54733         712150
opskumu commented 7 years ago

Linux 信号值

# kill -l
 1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL       5) SIGTRAP
 6) SIGABRT      7) SIGBUS       8) SIGFPE       9) SIGKILL     10) SIGUSR1
11) SIGSEGV     12) SIGUSR2     13) SIGPIPE     14) SIGALRM     15) SIGTERM
16) SIGSTKFLT   17) SIGCHLD     18) SIGCONT     19) SIGSTOP     20) SIGTSTP
21) SIGTTIN     22) SIGTTOU     23) SIGURG      24) SIGXCPU     25) SIGXFSZ
26) SIGVTALRM   27) SIGPROF     28) SIGWINCH    29) SIGIO       30) SIGPWR
31) SIGSYS      34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3
38) SIGRTMIN+4  39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
43) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7
58) SIGRTMAX-6  59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
63) SIGRTMAX-1  64) SIGRTMAX
opskumu commented 7 years ago

mongo 3.0

> use test
> db.createUser({user:'test',pwd:'test',roles:['readWrite','dbAdmin']})
Successfully added user: { "user" : "test", "roles" : [ "readWrite", "dbAdmin" ] }
> 
opskumu commented 7 years ago

fusermount

fusermount -uz /path/to/

Force unmount of NFS-mounted directory

opskumu commented 7 years ago

du

du -sh * | sort -rh

How can I sort du -h output by size

opskumu commented 6 years ago

ansible

cron: http://docs.ansible.com/ansible/latest/cron_module.html

ansible <host> -m cron -a 'name=docker-gc minute=0 hour=2 job="docker run -e GRACE_PERIOD_SECONDS=86400 --rm -v /var/run/docker.sock:/var/run/docker.sock -v /etc:/etc:ro spotify/docker-gc" state=present'
opskumu commented 6 years ago

文件逐行处理

#!/bin/bash
while read line
do
      echo $line
done < filename
#!/bin/bash 

cat filename | while read line
do
    echo $line
done

From https://fukun.org/archives/01282174.html