Linux 指令总结(持续更新)

Linux 命令

1. 查看系统信息

1.uname uname (1) - print system information uname (2) - get name and information about current kernel
2.cat /proc/version

2. 查询可用内存

free (1) - 显示系统中已用和未用的内存空间总和.

3. 确定文件类型(信息包括系统位数)

file - determine file type

4. 解压缩

``` 1. .tar.gz 和 .tgz tar zxvf FileName.tar.gz 解压 tar zcvf FileName.tar.gz DirName 压缩
  1. 其余借鉴该链接博客: https://www.jianshu.com/p/ca41f32420d6
<p style="font-size: 15px;font-weight: bold;text-indent:2em;letter-spacing:1px; font-family: '微软雅黑';">5. 查看ELF文件信息</p>
    readelf (1)          - Displays information about ELF files.

    如果只是查看库的依赖情况,可使用ldd:
    ldd (1)              - 显示共享库的依赖情况

<p style="font-size: 15px;font-weight: bold;text-indent:2em;letter-spacing:1px; font-family: '微软雅黑';">6. 列出目标文件中的符号</p>
    nm (1)               - list symbols from object files
    例:查看可执行程序中变量所在内存区域:nm -f sysv HelloWorld ; nm -n -C HelloWorld

    利用该指令查看elf文件中数据节(.data)和代码节(.bss)变量:
    data: nm --format=sysv yourlib | grep -w .data
    bss:  nm --format=sysv yourlib | grep -w .bss

<p style="font-size: 15px;font-weight: bold;text-indent:2em;letter-spacing:1px; font-family: '微软雅黑';"> 7. 列出二进制文件信息</p>
    objdump (1)          - display information from object files.
    例: objdump -s HelloWorld

<p style="font-size: 15px;font-weight: bold;text-indent:2em;letter-spacing:1px; font-family: '微软雅黑';">8. 列出打开的文件</p>
    Linux下一切皆文件:
    lsof (8)             - list open files

<p style="font-size: 15px;font-weight: bold;letter-spacing:1px;text-indent:2em; font-family: '微软雅黑';">9. 进程查看器</p>
    ps (1)               - report a snapshot of the current processes.
    ps (1p)              - report process status

<p style="font-size: 15px;font-weight: bold;letter-spacing:1px;text-indent:2em; font-family: '微软雅黑';">10. 跟踪进程栈</p>
    pstack (1)           - print a stack trace of a running process

<p style="font-size: 15px;font-weight: bold;letter-spacing:1px;text-indent:2em; font-family: '微软雅黑';">11. 查询进程间通信状态</p>
    ipcs (1)             - provide information on IPC facilities
    ipcs (1p)            - report XSI interprocess communication facilities status
    
    例:
    bash-4.2$ ipcs

    --------- 消息队列 -----------
    键        msqid      拥有者  权限     已用字节数 消息      

    ------------ 共享内存段 --------------
    键        shmid      拥有者  权限     字节     nattch     状态      
    0x00000000 131072     willy      600        524288     2          目标       
    0x00000000 229377     willy      600        4194304    2          目标       
    0x00000000 327682     willy      600        4194304    2          目标       
    0x00000000 393220     willy      600        4194304    2          目标       

    --------- 信号量数组 -----------
    键        semid      拥有者  权限     nsems  

<p style="font-size: 15px;font-weight: bold;letter-spacing:1px;text-indent:2em; font-family: '微软雅黑';">12. Linux下的任务管理器</p>
    top (1)              - display Linux processes

<p style="font-size: 15px;font-weight: bold;letter-spacing:1px;text-indent:2em; font-family: '微软雅黑';">13. 监视内存使用情况</p>
    vmstat (8)           - 报告虚拟内存的统计信息

<p style="font-size: 15px;font-weight: bold;letter-spacing:1px;text-indent:2em; font-family: '微软雅黑';">14. 监视I/O子系统</p>
    iostat (1)           - Report Central Processing Unit (CPU) statistics and in...

<p style="font-size: 15px;font-weight: bold;letter-spacing:1px;text-indent:2em; font-family: '微软雅黑';">15. 文件下载</p>
    wget (1)             - The non-interactive network downloader.

<p style="font-size: 15px;font-weight: bold;letter-spacing:1px;text-indent:2em; font-family: '微软雅黑';">16. 资源限制</p>


ulimit:显示(或设置)用户可以使用的资源的限制(limit),这限制分为软限制(当前限制)和
硬限制(上限),其中硬限制是软限制的上限值,应用程序在运行过程中使用的系统资源不超过相应
的软限制,任何的超越都导致进程的终止。

[yejy@applycompiled /home/yejy]$ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 63077
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 63077
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

输出的每一行由资源名字、(单位,ulimit命令的参数)、软限制组成。详细解释:

参数 描述
core file size core 文件的最大值为100 blocks,
data seg size 进程的数据段可以任意大
file size 文件可以任意大
pending signals 最多有63077个待处理的信号
max locked memory 一个任务锁住的物理内存的最大值为64kB
max memory size 一个任务的常驻物理内存的最大值
open files 一个任务最多可以同时打开1024的文件
pipe size 管道的最大空间为4096字节
POSIX message queues POSIX的消息队列的最大值为819200字节
stack size 进程的栈的最大值为8192字节
cpu time 进程使用的CPU时间
max user processes 当前用户同时打开的进程(包括线程)的最大个数为63077
virtual memory 没有限制进程的最大地址空间
file locks 所能锁住的文件的最大个数没有限制


<p style="font-size: 15px;font-weight: bold;letter-spacing:1px;text-indent:2em; font-family: '微软雅黑';">17. 查看磁盘分区</p>

df - report file system disk space usage

[root@yejy binaryTree]# df -ah
文件系统 容量 已用 可用 已用% 挂载点
rootfs - - - - /
sysfs 0 0 0 - /sys
proc 0 0 0 - /proc
devtmpfs 473M 0 473M 0% /dev
securityfs 0 0 0 - /sys/kernel/security
tmpfs 489M 84K 489M 1% /dev/shm
devpts 0 0 0 - /dev/pts
tmpfs 489M 7.1M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
cgroup 0 0 0 - /sys/fs/cgroup/systemd
pstore 0 0 0 - /sys/fs/pstore
cgroup 0 0 0 - /sys/fs/cgroup/cpu,cpuacct
cgroup 0 0 0 - /sys/fs/cgroup/hugetlb
cgroup 0 0 0 - /sys/fs/cgroup/net_cls,net_prio
cgroup 0 0 0 - /sys/fs/cgroup/memory
cgroup 0 0 0 - /sys/fs/cgroup/devices
cgroup 0 0 0 - /sys/fs/cgroup/freezer
cgroup 0 0 0 - /sys/fs/cgroup/perf_event
cgroup 0 0 0 - /sys/fs/cgroup/blkio
cgroup 0 0 0 - /sys/fs/cgroup/cpuset
cgroup 0 0 0 - /sys/fs/cgroup/pids
configfs 0 0 0 - /sys/kernel/config
/dev/mapper/cl-root 17G 14G 3.9G 78% /
systemd-1 - - - - /proc/sys/fs/binfmt_misc
mqueue 0 0 0 - /dev/mqueue
hugetlbfs 0 0 0 - /dev/hugepages
debugfs 0 0 0 - /sys/kernel/debug
sunrpc 0 0 0 - /var/lib/nfs/rpc_pipefs
nfsd 0 0 0 - /proc/fs/nfsd
/dev/sda1 1014M 173M 842M 18% /boot
tmpfs 98M 16K 98M 1% /run/user/42
fusectl 0 0 0 - /sys/fs/fuse/connections
gvfsd-fuse 0.0K 0.0K 0.0K - /run/user/42/gvfs
tmpfs 98M 0 98M 0% /run/user/1001
binfmt_misc 0 0 0 - /proc/sys/fs/binfmt_misc


<p style="font-size: 15px;font-weight: bold;letter-spacing:1px;text-indent:2em; font-family: '微软雅黑';">18. 还原C++符号</p>

c++filt (1) - Demangle C++ and Java symbols.

[root@yejy binaryTree]# c++filt ZSt12__miter_baseIPPP8TreeNodeENSt11_Miter_baseIT_E13iterator_typeES5
std::_Miter_base<TreeNode>::iterator_type std::__miter_base<TreeNode>(TreeNode***)


<p style="font-size: 15px;font-weight: bold;letter-spacing:1px;text-indent:2em; font-family: '微软雅黑';">19. 报告磁盘空间使用情况</p>

du (1) - 报告磁盘空间使用情况

[root@yejy binaryTree]# du -ah
16K ./.main.cpp.swp
4.0K ./!
16K ./.tree.h.swp
16K ./.tree.h.swo
8.0K ./tree.h
4.0K ./main.cpp
36K ./a.out
100K .


<p style="font-size: 15px;font-weight: bold;letter-spacing:1px;text-indent:2em; font-family: '微软雅黑';">20. 去除相邻重复行 (可结合sort使用,去重)</p>

uniq - report or omit repeated lines

yejy@applycompiled:~$ cat /proc/cpuinfo | grep "cpu cores" | uniq
cpu cores : 10


<p style="font-size: 15px;font-weight: bold;letter-spacing:1px;text-indent:2em; font-family: '微软雅黑';">21. 打印每个文件的行、字母和字节数 </p>

wc - print newline, word, and byte counts for each file

yejy@applycompiled:~$ cat /proc/cpuinfo | grep "processor" | wc -l
20

原文地址:https://www.cnblogs.com/blog-yejy/p/9588489.html