本文依据目前工作场景中经常用的指令罗列至此,后续持续更新。
(一)系统相关
1、压缩与解压缩指令
xz -d /home/a.xz #打开xz打包文件
tar -xvf /home/a.tar #打开tar打包文件
tar -zxvf /home/a.tar.gz #解压以gzip压缩的文件
tar -jxvf /home/a.tar.bz2 #解压以bzip压缩的文件
tar -cvf /home/a.tar /home #打包/home下所有文件
unzip ile.zip #打开zip打包文件
2、清除buff/cache占用的内存
echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches
drop_caches的值可以是0-3之间的数字,代表不同的含义:
0:不释放(系统默认值)
1:释放页缓存
2:释放dentries和inodes
3:释放所有缓存
3、wacth
#每隔一秒高亮显示http连接数的变化情况
watch -n 1 -d 'pstree | grep http'
#十秒一次输出系统的平均负载
watch -n 10 'cat /proc/loadavg'
4、查看进程运行时间
root@ubuntu:~# ps -eO lstart,etime | grep sshd
1200 Wed Aug 9 11:07:30 2023 05:39:32 S ? 00:00:00 /usr/sbin/sshd -D
3280 Wed Aug 9 15:47:16 2023 59:46 S ? 00:00:05 sshd: root@pts/1
3282 Wed Aug 9 15:47:17 2023 59:45 S ? 00:00:00 sshd: root@notty
13309 Wed Aug 9 16:44:51 2023 02:11 S ? 00:00:00 sshd: root@pts/15
13311 Wed Aug 9 16:44:51 2023 02:11 S ? 00:00:00 sshd: root@notty
14182 Wed Aug 9 16:47:02 2023 00:00 S pts/15 00:00:00 grep --color=auto sshd
root@ubuntu:~# ps -o lstart,etime -p 608
STARTED ELAPSED
Wed Aug 9 11:07:24 2023 05:39:41
root@ubuntu:~#
5、查看系统进程层级
# /home/work/ps -ef --forest
UID PID PPID C STIME TTY TIME CMD
root 2 0 0 15:41 ? 00:00:00 [kthreadd]
root 1 0 0 15:41 ? 00:00:03 init
root 102 1 0 15:41 ? 00:00:00 /sbin/syslogd -n
root 105 1 0 15:41 ? 00:00:00 /sbin/klogd -n
root 152 1 0 15:41 ? 00:00:01 /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf
root 153 152 0 15:41 ? 00:00:01 \_ /usr/bin/php-cgi
root 170 153 0 15:41 ? 00:00:00 \_ /usr/bin/php-cgi
root 157 1 0 15:41 ? 00:00:00 /usr/sbin/sshd
root 408 157 0 15:45 ? 00:00:30 \_ sshd: root@pts/0
root 421 408 0 15:45 pts/0 00:00:00 | \_ -sh
root 16422 421 99 16:54 pts/0 00:00:00 | | \_ /home/work/ps -ef --forest
root 15731 408 0 16:52 ? 00:00:01 | \_ sh -c while [ -d /proc/$PPID ]; do sleep 1;head -v -n 8 /proc/meminfo; head -v -n 2 /proc/stat /proc/version /proc/uptime /proc/loadavg /proc/sys/fs/file
root 414 157 0 15:45 ? 00:00:00 \_ sshd: root@notty
root 418 414 0 15:45 ? 00:00:00 \_ sh -c /usr/libexec/sftp-server
root 419 418 0 15:45 ? 00:00:00 \_ /usr/libexec/sftp-server
root 163 1 0 15:41 ? 00:00:00 /usr/sbin/telnetd -F
root 167 1 0 15:41 ? 00:00:00 vsftpd
root 187 1 0 15:41 ? 00:00:11 sysrunled
root 188 1 0 15:41 ? 00:00:00 reset_ip
6、 类型长度-ILP32模型-LIP64模型
char 8 8
shor 16 16
int 32 32
longint 32 64
longlong 64 64
char* 32 64
float 32 64
double 32 64
size_t 32 64
99、杂项信息
cat /proc/version #查看系统内核版本信息
cat /proc/cpuinfo #查看CPU信息
ps H -C xxx -o 'pid tid cmd comm' #查看主进程、子线程信息
echo 7 7 7 7 > /proc/sys/kernel/printk #修改内核显示打印级别
export LD_LIBRARY_PATH=/user/local/lib/:$LD_LIBRARY_PATH #设置库环境变量
(二)文件相关
1、查看编译后程序的各个内存区域大小:
root@ubuntu:/work# size uart_test
text data bss dec hex filename
6244 852 4192 11288 2c18 uart_test
2、确定文件类型
root@ubuntu:/work# file uart_test
uart_test: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=4c80d927cef0416b5b0d7fc0ca5614c7c6292e73, not stripped
3、替换中文换行符^M
sed -i 's/\r$//' /home/vendor/bin/startup.sh
4、获取文件行数
wc -l test1.sh
sed -n '$=' test1.sh
cat test1.sh |wc -l
5、列出所有库文件的OS,ABI,架构信息,类别(32/64位)等等
root@ubuntu:/work# readelf -h liblog.so
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: ARM
Version: 0x1
Entry point address: 0x113c
Start of program headers: 52 (bytes into file)
Start of section headers: 40608 (bytes into file)
Flags: 0x5000402, has entry point, Version5 EABI, hard-float ABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 5
Size of section headers: 40 (bytes)
Number of section headers: 36
Section header string table index: 33
6、查看文件夹及文件大小信息
#列出当前文件以及文件夹的大小
root@ubuntu:/tmp# du -sh --max-depth=1 *
0 config-err-FzOEWL
0 qipc_sharedmemory_qtsingleapplicationeb627ff76c86c35cef65e9d56a6787508544e60e6c
0 qipc_systemsem_qtsingleapplicationeb627ff76c86c35cef65e9d56a6787508544e60e6c
0 QtCreator.Ko2637
0 qtsingleapplication-2d3a-0
0 qtsingleapplication-2d3a-0-lockfile
36K systemd-generator.wKHrBK
0 unity_support_test.0
4.0K vmware-root
#列出tmp目录所有文件大小的总和
root@ubuntu:/tmp# du -sh --max-depth=1 /tmp
56K /tmp
7、打印共享对象依赖关系
root@ubuntu:/# ldd /bin/ls
linux-vdso.so.1 => (0x00007fff413e7000)
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f10b0c67000)
libacl.so.1 => /lib/x86_64-linux-gnu/libacl.so.1 (0x00007f10b0a5f000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f10b0696000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f10b0457000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f10b0253000)
/lib64/ld-linux-x86-64.so.2 (0x000055ee2b459000)
libattr.so.1 => /lib/x86_64-linux-gnu/libattr.so.1 (0x00007f10b004e000)
(三)网络相关
1、添加默认路由
route add default gw 10.0.0.1
route del default gw 192.168.1.1
2、查看当前网络监听与网络连接情况:
# netstat -tunl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 :::22 :::* LISTEN
tcp 0 0 :::23 :::* LISTEN
# netstat -tun
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 48 192.168.1.101:22 192.168.1.217:55229 ESTABLISHED
(四)硬件设备相关
1、串口重定向:修改/etc/rc.d/rc_mxc.S重定向到串口1
if grep -sq ttymxc0 /proc/cmdline; then
# /sbin/getty -L ttymxc0 115200 vt100
#elif grep -sq ttymxc1 /proc/cmdline; then
/sbin/getty -L ttymxc1 115200 vt100
2、设置GPIO
echo 117 >/sys/class/gpio/export
echo out > /sys/class/gpio/gpio117/direction
echo 0 > /sys/class/gpio/gpio117/value