Linux Tips

9 分钟读完

Tips是平时随手乱记下的,的确很实用,但是也特别杂乱。有些东西是小技巧,有些知识点扩展开可能写许多。如果有疑问,直接找我。

查看命令启动位置

  • lsof -p <pid> | head 部分时候有用
  • java的可以用jinfo <pid>

send udp packet

1
$ echo "This is my data" > /dev/udp/127.0.0.1/3000

nload查看网络实时流量

个人知道的感觉最好的

zmore

1
$ zmore nginx1.20171224.gz | awk -F ' [|]# ' '{if ($3 >= "2017-12-22 09:00:00" ) exit; if ($3 >= "2017-12-22 09:00:00") print $0;}' | more

gzip

1
2
3
4
5
gzip filename
  -f force to overwrite existing gz file
  -k keep original file
  -r folder recurve
  -1  compress level1
1
2
3
4
5
depress
gzip  gzfile
  -d depress
  -l list members in
  -v valid

redirect err to info

2>&1

1
2
$ 2>&1 nginx -V
$ nginx -V 2>&1

prefer to the former.

nohup

1
$ nohup node server.js > nohup.log 2>&1 &

ps

1
$ ps -p $PPID -o cmd | tail -1

tar

1
tar --extract --file={tarball.tar} {file}

check swap memory

1
$ awk '/VmSwap|Name/{printf $2 " " $3}END{ print  "" }'  /proc/[pid]/status
1
2
3
for file in /proc/*/status ; do
  awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file;
done
1
2
3
for es in $(jps | grep Elasticsearch | awk '{print $1}'); do
  awk '/VmSwap|Name/{printf $2 " " $3}END{ print " " }'  /proc/$es/status;
done

cannot ssh to remote machine with root

  1. modify /etc/ssh/sshd_config
    1
    2
    
    #PermitRootLogin prohibit-password
    PermitRootLogin yes
    
  2. restart ssh service
    1
    
    $ service ssh restart
    

prevent ssh from disconnecting

~/.ssh/config

1
2
Host *
  ServerAliveInterval 60

System is booting up. See pam_nologin

remove /var/tun/nologin /etc/nologin

set language support

  • export LC_ALL=en_US.UTF-8 or
  • export LANG=en_US.UTF-8

add language package for linux:

https://perlgeek.de/en/article/set-up-a-clean-utf8-environment

1
2
3
4
5
6
7
8
9
10
11
$ dpkg-reconfigure locales

(Enter the items you want to select, separated by spaces.)
Locales to be generated: 149 471

Many packages in Debian use locales to display text in the correct language for the user. You can choose a default
locale for the system from the generated locales.
This will select the default language for the entire system. If this system is a multi-user system where not all
users are able to speak the default language, they will experience difficulties.
  1. None  2. C.UTF-8  3. en_US.UTF-8  4. zh_CN.UTF-8
Default locale for the system environment: 3

no space in /boot

1
2
3
4
5
6
7
$ dpkg -l | grep linux-image
$ dpkg -l | grep linux-headers

$ apt-get purge linux-image-2.6.31-17-server
$ dpkg --purge linux-image-2.6.28-11-server

$ apt-get autoremove

netstat

1
$ netstat -atulpn

find

-o more arguments

1
$ find . -name "java" -o -name "resources"

-not

1
$ find . -not -name "java"

\(\)

1
$ find . -not \( -name "java" -o -name "resources" \)

test linux interactive mode

1
$ [[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive'

留下评论