分类 Linux 相关 下的文章

linux find command 命令

  1. find ~/ -name a.txt
  2. find . -type f -name tech //find file named tech
  3. find . -type d -name tech //find dir named tech
  4. find . -iname tech //ignore case, find both TECH, tech, Tech, etc
  5. find /var -name "*.log"
  6. find . -type f -perm 0777 -print //find all files whose permission is 777
  7. find / -type f ! -perm 777 //find all the files without permission 777
  8. find / -perm /u=r // find read only file
  9. find / -perm /a=x // find executable file
  10. find / -name foo.bar -print 2>/dev/null //"Permission Denied" send to null
  11. find . -name *.bar -maxdepth 2 -print //only search 2 directories deep
  12. find ./dir1 ./dir2 -name foo.bar -print //search 2 dirs
  13. find /some/directory -type l -print // search link file
    type:
b    block (buffered) special 
c    character (unbuffered) special 
d    directory 
p    named pipe (FIFO) 
f     regular file 
l     symbolic link 
s    socket 

There are, however, other expressions you can use as follows:

-amin n - The file was last accessed n minutes ago
-anewer - The file was last accessed more recently than it was modified
-atime n - The file was last accessed more n days ago
-cmin n - The file was last changed n minutes ago
-cnewer - The file was last changed more recently than the file was modified
-ctime n - The file was last changed more than n days ago
-empty - The file is empty
-executable - The file is executable
-false - Always false
-fstype type - The file is on the specified file system
-gid n - The file belongs to group with the ID n
-group groupname - The file belongs to the named group
-ilname pattern - Search for a symbolic line but ignore case
-iname pattern - Search for a file but ignore case
-inum n - Search for a file with the specified node
-ipath path - Search for a path but ignore case
-iregex expression - Search for a expression but ignore case
-links n - Search for a file with the specified number of links
-lname name - Search for a symbolic link
-mmin n - File's data was last modified n minutes ago
-mtime n - File's data was last modified n days ago
-name name - Search for a file with the specified name
-newer name - Search for a file edited more recently than the file given
-nogroup - Search for a file with no group id
-nouser - Search for a file with no user attached to it
-path path - Search for a path
-readable - Find files which are readable
-regex pattern - Search for files matching a regular expression
-type type - Search for a particular type
-uid uid - Files numeric user id is the same as uid
-user name - File is owned by user specified
-writable - Search for files that can be written to

linux 本地端口 使用

今天查问题 遇到如下异常:
java.net.ConnectException: Cannot assign requested address

看到网上大多数是说 本地往外连接的端口已经被占用完.

  1. 首先查看本地的 ulimit 设置, 是否过小
    _$ ulimit -a
  2. 如果不是很小, 查看当前的 端口使用情况
    _$ ss -s
  3. 查看本地往外连接端口的设置:
    _$ cat /proc/sys/net/ipv4/ip_local_port_range

更多的 linux 网络配置参数:https://www.tldp.org/HOWTO/Adv-Routing-HOWTO/lartc.kernel.obscure.html#AEN1252

参考:
https://ma.ttias.be/linux-increase-ip_local_port_range-tcp-port-range/

关于 linux PS 命令

虽然经常用, 但是不是那么熟悉它竟然能提供那么多的信息. PS 是 Process Status 的缩写. top 命令的输出和 PS 很类似, 只不过是实时刷新.

ps --help all //显示所有的命令行参数
ps L //显示输出格式
ps H 16705 //显示特定进程的线程信息

ps -o ppid,pid,lwp,nlwp,%cpu,%mem,cputime,cmd,args k -%cpu H 16705 //输出一个进程的所有线程, 并且自定义格式, 按照 cpu 使用时间倒序排列.

关于格式中的nlwp: Number of Lightweight Processes. This basically amounts to the number of threads a program has running

一般结合 https://www.pslinux.online/index.php & ps --help all 就能找到想用的参数.

tcpdump

tcpdump - dump traffic on a network

tcpdump [ -AbdDefhHIJKlLnNOpqStuUvxX# ] [ -B buffer_size ]

  • -w 写入文件
  • -r 从文件读入 -F 读入的文件
  • -V 从一批文件读入
  • -c 处理多少 package
  • -D or --list-interfaces 列出接口列表
  • -i --interface= 制定接口
  • -K --dont-verify-checksums 不验证 checksum 加快速度
  • -n 不转换数字为地址
  • -Q --direction=in|out|inout

samples here
sudo tcpdump host 10.102.196.239 -w /tmp/tcpdump.log.cap

ping:
sudo tcpdump -e icmp[icmptype] == 8 //ping echo request
sudo tcpdump -e icmp[icmptype] == 0 //ping echo reply

network diagnosis commands 网络诊断命令

  1. wget
    -- wget -S --spider -T 1 -t 2 sellerprof.vip
    -- wget -S --spider -T 1 -t 2  --no-check-certificate https://esams.vip

  2. curl
    -- curl -I --retry 2 --connect-timeout 1 sellerprof.vip
    -- curl -I --retry 2 --connect-timeout 1 -k https://esams.vip

  3. telnet

  4. nslookup
    -- nslookup -query=hinfo  -timeout=1 -retry=1 esams.vip

  5. ping
    -- ping -c 10 -W 1 sellerprof.vip

  6. traceroute/tracert
    -- traceroute esams.vip

  7. mtr
    -- mtr -w --timeout=1 esams.vip

  8. dig 由 BIND(互联网上最广泛使用的 DNS 软件) 提供的查询 DNS 的辅助工具,替换原来老的 nslookup 和 host

    dig //不带任何参数查询root dns .
    dig -h //help
    dig +short www.tianxiaohui.com // 简化输出
    dig +trace www.tianxiaohui.com //输出迭代式所有来回
    dig @8.8.8.8 tianxiaohui.com
    dig -x 54.222.60.252 //反向查询
    dig -f query.txt +short //从文件读
    dig google.com ANY //查询所有记录

  9. netstat
    -- netstat -t --wide
    -- netstat -t -l

  10. ss
    -- ss -t -l

  11. routetable
    -- netstat -r

  12. ifconfig/ipconfig