linux常用命令及一些静态动态库相关知识
1 查找然后grep,最后在复制到特定目录
find . -depth -name *.java | xargs grep -i lijiangtao | awk -F ":" '{print $1}' | xargs -i cp {} . # 注意,awk -F制定分割符'
2 查找当前系统所打开的所有线程数量
pstree -p | wc -l
3 查看文件夹的总大小
**du -s -h [path] : **
-s 查看总大小
-h 以人类可读的方式显示,以m,g为单位
4 top
按照顺序g2,切换显示模式,例如g2模式可以显示ppid
按c可以显示完整的命令
按P按照cpu来排名
按e将内存单位切换为m
top -H -p [pid]:以线程模式显示信息
5 sed
删除文件中包含某些字符的特定行
sed -i '/0,0,0,0/d' jmx_trace.csv
在第12行后面追加hello.txt文件里面的内容
sed -i '12 r hello.txt' file
在查找到的helloworld前面添加insert content
sed -i '/helloworld/i\inesrt content' file
在查找的hellworld后面添加insert content
sed -i '/helloworld/a\insert content' file
6 统计各个文件夹占用的空间大小
sh du -s -h /* | sort -nr
查看当前目录下所有文件/文件夹所占的空间大小:
sh du -h --max-depth=1 .
7 查看二进制文件符号的相关命令
ldd file : 查看当前二进制文件所依赖的所有动态库
nm *.a/*.so:查看当前动态/静态文件里面的所有符号
其中-D选项指定只查看动态符号表
ldconfig -p : 查看当前ld命令可以链接的所有路径
readelf: 可以查看当前so或者a文件里面的信息,包括rpath等
8 perf一些使用技巧
监控进程/线程耗费性能情况,可以监控的事件有很多:cpu,cache-miss,branch预测等,使用perf list可以查看所有的可监控项
perf record -e cpu-clock -t 4882 :捕捉cpu特定线程的cpu使用率
perf report:显示perf record的结果
9 pidstat
用来监控进程后所有线程的cpu占用率(结合java的jstack,通过nid可以查找出对应的线程)
10 dstat
一个用来监控系统资源利用率的工具stat,常用参数dstat -tlcdnm,比普通的top更好用
11 taskset
taskset -apc: 查看某个进程下面所有线程绑定的cpu核
14 关于virtual memory和swap
Virtual memory is a layer of abstraction provided to each process. The computer has, say, 2GB of physical RAM, addressed from 0 to 2G. A process might see an address space of 4GB, which it has entirely to itself. The mapping from virtual addresses to physical addresses is handled by a memory management unit, which is managed by the operating system. Typically this is done in 4KB "pages".
This gives several features:
A process can not see memory in other processes (unless the OS wants it to!)
Memory at a given virtual address may not be located at the same physical address
Memory at a virtual address can be "paged out" to disk, and then "paged in" when it is accessed again.
15 将编译输出文件合并为一个静态库
ar -rv libgtest.a gtest-all.o gtest_main.o
16 LIBRARY_PATH和LD_LIBRARY_PATH的区别
LIBRARY_PATH is used by gcc before compilation to search directories containing static and shared libraries that need to be linked to your program.
LD_LIBRARY_PATH is used by your program to search directories containing shared libraries after it has been successfully compiled and linked.
rpath: gcc编译的选项,把需要寻找的库文件的所在路径编译在elf中,这样子就多了一条寻找so库或者a库的路径
17 ldd **.so
可以尝试解析该so中的所有符号,如果未定义符号无法找到,则在运行的时候才会尝试自己去找,如果找到了,那么说明是当前操作系统的相关路径帮助其找到了so
5 ld在链接静态库的时候,一些没有用到的符号会丢失,可以用--whole-archive解决,详细情况如下
#force all symbols
gcc -fPIC -shared -Wl,-soname,libb.so -o libb.so b.o -Wl,--whole-archive liba.a -Wl,--no-whole-archive
#后面--no-whole-archive表示后面的库不需要在这样子了,否则会出bug
#force just a specific symbol
gcc -fPIC -shared -Wl,-soname,libb.so -o libb.so b.o -u foobarize liba.a
Why you need it?
A static library is a simple collection of object files. The one major difference from a bunch of object files is the following: when an undefined symbol needs to be resolved, the library is searched and only the object file that actually defines the symbol is linked. No undefined symbols? Nothing is searched, nothing is linked. To override this default behaviour, the GNU linker implements --whole-archive. Most linkers implement -u to force a particular symbol to be treated as undefinmed.
linux常用命令及一些静态动态库相关知识的更多相关文章
- Linux环境下c语言静态链接库和动态链接库创建和使用
库有动态与静态两种,动态通常用.so为后缀,静态用.a为后缀. 面对比一下两者: 静态链接库:当要使用时,连接器会找出程序所需的函数,然后将它们拷贝到执行文件,由于这种拷贝是完整的,所以一旦连接成功, ...
- Linux常用命令手册
Linux常用命令手册 NO 分类 PS1 命令名 用法及参数 功能注解 对应章节 1 文件管理 # ls ls -a 列出当前目录下的所有文件,包括以.头的隐含文件 文件管理 # ls ls ...
- Linux常用命令语法+示例
原文出自:https://blog.csdn.net/seesun2012 Linux常用命令:Linux查看日志命令总结:Tomcat相关:Linux配置网卡,连接外网:Linux下安装JDK:Li ...
- Linux 常用命令:系统状态篇
前言 Linux常用命令中,有些命令可以用于查看系统的状态,通过了解系统当前的状态,能够帮助我们更好地维护系统或定位问题.本文就简单介绍一下这些命令. 1. 查看系统运行时间--uptime 有时候我 ...
- linux常用命令--开发调试篇
前言 Linux常用命令中有一些命令可以在开发或调试过程中起到很好的帮助作用,有些可以帮助了解或优化我们的程序,有些可以帮我们定位疑难问题.本文将简单介绍一下这些命令. 示例程序 我们用一个小程序,来 ...
- Linux 常用命令:开发调试篇
前言 Linux常用命令中有一些命令可以在开发或调试过程中起到很好的帮助作用,有些可以帮助了解或优化我们的程序,有些可以帮我们定位疑难问题.本文将简单介绍一下这些命令. 示例程序 我们用一个小程序,来 ...
- Linux常用命令英文全称与中文解释 (pwd、su、df、du等)
https://blog.csdn.net/qq_40334837/article/details/83819735 Linux常用命令英文全称与中文解释 apt: Advanced Packagin ...
- 来不及解释!Linux常用命令大全,先收藏再说
摘要:Linux常用命令,很适合你的. 一提到操作系统,我们首先想到的就是windows和Linux.Windows以直观的可视化的方式操作,特别适合在桌面端PC上操作执行相应的软件.相比较Windo ...
- Linux常用命令详解上
Linux常用命令详解上 目录 一.shell 二.Linux命令 2.1.内部命令与外部命令的区别 2.2.Linux命令行的格式 2.3.编辑Linux命令行的辅助操作 2.4.获得命令帮助的方法 ...
随机推荐
- SpringBoot简明教程
一.SpringBoot简介 1.什么是SpringBoot SpringBoot用来简化spring应用开发,约定大于配置,去繁从简,是J2EE一站式解决方案 2.SpringBoot的优点 快速创 ...
- 面向对象JML系列作业总结
面向对象JML系列作业总结 一.综述 本单元作业,由简到难地迭代式实现了三种JML需求,主要学习了面向规格的编程方法. 第一次:实现Path类和PathContainer类 第二次:继承PathCon ...
- Jenkins 基础篇 - 任务分类
从前面的小节中我们看到在创建 Jenkins 任务的时候有好几种类型,如果你专门安装了 Maven 相关插件,可能还会有一个[构建一个 maven 项目]的任务类型,那这些任务类型究竟有何区别,以及我 ...
- [bug] IDEA springboot项目 访问静态资源 html页面 报404
原因 复制的静态资源目录没有编译 解决 检查target目录中,是否有static目录,若没有,重新右键项目install即可 若还不能解决,尝试浏览器缓存和IDEA编译设置,详见参考链接 参考 ht ...
- [刷题] 350 Intersection of Two Arrays
要求 给定两个数组nums,求两个数组交集 输出结果与元素在两个数组中出现的次数一致 不考虑输出结果的顺序 举例 nums1=[1,2,2,1] nums2=[2,2] 结果:[2,2] 思路 使用m ...
- Scala 关键字
Java关键字 Java 一共有 50 个关键字(keywords),其中有 2 个是保留字,目前还不曾用到:goto 和 const.true.false 和 null 看起来很像关键字,但实际上只 ...
- MyBatis 映射文件详解(六)
MyBatis 配置文件类型 MyBatis配置文件有两种类型,如下: 全局配置文件(如 mybatis-config.xml) Mapper XML 映射文件(如 UserMapper.xml) 上 ...
- 10.14 ssh:安全地远程登录主机
ssh命令 是openssh套件中的客户端连接工具,可以使用ssh加密协议实现安全的远程登录服务器,实现对服务器的远程管理,Windows中的替代工具为Xshell.putty.SecureCRT等. ...
- 并发王者课-青铜5:一探究竟-如何从synchronized理解Java对象头中的锁
在前面的文章<青铜4:synchronized用法初体验>中,我们已经提到锁的概念,并指出synchronized是锁机制的一种实现.可是,这么说未免太过抽象,你可能无法直观地理解锁究竟是 ...
- Angular环境搭建及简单体验
一.安装开发环境 npm install -g typescript npm install -g @angular/cli 二.创建hello-world项目 创建项目 ng new angular ...