Linux Tips

  • 修改 hostname
$ sudo hostnamectl set-hostname [NEW-HOSTNAME]
$ sudo vim /etc/hosts
127.0.0.1 [NEW-HOSTNAME]
$ sudo vim /etc/cloud/cloud.cfg
preserve_hostname: true
$ sudo reboot
  • 显示库的所在位置
$ dpkg -L libsox-dev
/.
/usr
/usr/include
/usr/include/sox.h
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libsox.a
/usr/lib/x86_64-linux-gnu/pkgconfig
/usr/lib/x86_64-linux-gnu/pkgconfig/sox.pc
/usr/lib/x86_64-linux-gnu/sox
/usr/lib/x86_64-linux-gnu/sox/libsox_fmt_alsa.a
...
/usr/share
/usr/share/bug
/usr/share/bug/libsox-dev
/usr/share/bug/libsox-dev/presubj
/usr/share/doc
/usr/share/doc/libsox-dev
/usr/share/doc/libsox-dev/copyright
/usr/share/man
/usr/share/man/man3
/usr/share/man/man3/libsox.3.gz
/usr/lib/x86_64-linux-gnu/libsox.so
/usr/share/doc/libsox-dev/changelog.Debian.gz
  • 查询某个程序的依赖
$ ldd `which nvidia-smi`
        linux-vdso.so.1 =>  (0x00007ffcfb5a2000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb7378f4000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fb7376f0000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb737326000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fb73711e000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fb737b11000)
  • 挂载Windows共享的目录
sudo apt-get install cifs-utils
mount –t cifs //192.168.1.100/share /mnt/share [–o username=USER,password=PWD]
  • iptables rules
iptables -L INPUT --line-numbers
Chain INPUT (policy ACCEPT) 
    num  target prot opt source destination
    1    ACCEPT     udp  --  anywhere  anywhere             udp dpt:domain 
    2    ACCEPT     tcp  --  anywhere  anywhere             tcp dpt:domain 
    3    ACCEPT     udp  --  anywhere  anywhere             udp dpt:bootps 
    4    ACCEPT     tcp  --  anywhere  anywhere             tcp dpt:bootps

Add

sudo iptables -I INPUT -p tcp -m state --state NEW -m tcp -m multiport --dports 1200:1210 -j ACCEPT

Update

sudo iptables -t nat -D PREROUTING 1