ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

Linux开发常用命令

Linux开发常用命令

Linux开发常用命令

  • 系统
    • whereis
    • ps
    • ls
    • du (查看文件大小)
    • find
    • grep
    • ln
    • ld
    • ldconfig
    • pkg-config
    • nm
    • xxd
    • objcopy
    • objdump
    • elfedit
    • readelf
    • readlink
    • lsof
    • ss
  • 网络
    • netstat
    • iptables
    • tcpdump
    • curl
      • IP地址归属查询
  • 应用
    • upnpc
  • module操作相关命令
    • lsmod
    • insmod
    • remod
    • modinfo
    • modprobe
  • ARM Linux
    • df -h
    • cat /proc/mtd 查看分区信息
    • tail
  • Linux 脚本
    • ubuntu 清零CACHE

系统

whereis

查找命令或文件位置
$ whereis ls # 查找ls命令位置
$ whereis libupnpp.so # 查找libupnpp.so动态库所在位置

ps

查找指定进程名称
$ ps aux | grep <进程名称>
$ ps aux | grep mpd

ls

$ ls
$ ls -i
$ ls -l
$ ls -h
$ ls -lh
$ ls -ilh

du (查看文件大小)

du
du -l
du --max-depth=1
du -lh --max-depth=1

find

$ find ./ -type f -name “mpd.conf”

grep

$ grep -rn “mpd” ./

ln

软链接
$ ln -s <现有文件> <软链接名>

ld

检查链接器是否能找到库
$ ld -lupnp --verbose

ldconfig

$ sudo ldconfig # 加载
$ sudo ldconfig -p # 输出当前信息
$ sudo ldconfig -p | grep upnp # 输出libupnp相关信息

pkg-config

模块信息文件*.pc 文件通常位于
/usr/lib/pkgconfig/
/usr/share/pkgconfig/
/usr/local/lib/pkgconfig
/usr/local/lib/x86_64-linux-gnu/pkgconfig

  • $ pkg-config --exists <模块名称> && echo “找到输出的信息”
  • $ pkg-config --modversion <模块名称>
  • $ pkg-config --cflags <模块名称>
  • $ pkg-config --libs <模块名称>

nm

查看库文件信息
$ nm /usr/local/lib/x86_64-linux-gnu/libupnpp.so

查找库文件是否有指定的内容
$ nm -D /usr/lib/x86_64-linux-gnu/libjsoncpp.so | c++filt | grep “Json::Value::get”

xxd

$ xxd -l 1024 <文件名> # 以16进制查看 文件 开头1024字节数据

objcopy

objdump

elfedit

readelf

readlink

lsof

查找端口号被哪些进程占用
$ sudo lsof -i :<端口号>
COMMAND:命令
PID:命令进程ID
sudo kill <进程ID> # 杀掉指定PID的进程

ss

查找端口占用
ss tulpn | grep <端口号>

网络

netstat

查找端口占用

iptables

tcpdump

sudo tcpdump -i any port 80 -A -s 0

curl

IP地址归属查询

$curl -s ip-api.com

应用

upnpc

$ sudo apt install miniupnpc

# 查找设备 upnpc-l # 调用 SetAVTransportURI(需手动构造 DIDL) upnpc-a<renderer-ip><port>\"SetAVTransportURI"\"InstanceID=0"\"CurrentURI=http://example.com/song.mp3"\"CurrentURIMetaData=<DIDL-Lite xmlns=...></DIDL-Lite>"

module操作相关命令

lsmod

insmod

remod

modinfo

modprobe

ARM Linux

df -h

cat /proc/mtd 查看分区信息

cat /proc/mtd

tail

  • tail /var/log/xxx.log # 打印日志文件最后10行数据
  • tail -n 50 /var/log/xxx.log # 打印日志文件最后50(可自定义)行数据
  • tail -f /var/log/xxx.log # 打印日志文件增长数据
# tail --helpBusyBox v1.27.2()multi-call binary. Usage:tail[OPTIONS][FILE]... Print last10lines of each FILE(or stdin)to stdout. Withmorethan one FILE, precede each with a filename header.-fPrint data asfilegrows-c[+]N[kbm]Print last N bytes-nN[kbm]Print last N lines-n+N[kbm]Start on Nth line and print the rest-qNever print headers-sSECONDSWaitSECONDSbetween reads with-f-vAlways print headers-FSame as -f, but keep retrying N may be suffixed by k(x1024), b(x512), or m(x1024^2).

Linux 脚本

ubuntu 清零CACHE

#!/bin/bashsync&&echo1|sudotee/proc/sys/vm/drop_cachessync&&echo2|sudotee/proc/sys/vm/drop_cachessync&&echo3|sudotee/proc/sys/vm/drop_caches
返回列表