strip

strip是Linux下的一个命令。可以用于给应用脱衣服,帮助我们抹除一些调试信息。(虽然不知道具体是什么,但是会用就好了

在嵌入式开发领域用到的应该比较多

首先,先写一个示例看看

//hello.cpp
#include <iostream> using namespace std;
int main() {
int i = 10;
for(;i > 0;i--) {
cout<<"hello,i = "<<(10 - i)<<endl;
}
return 0;
}

好了,编译一下,看下大小

 $ g++ hello.cpp -o hello.out
$ ls -l
total 16
-rw-r--r-- 1 root root 171 Jul 12 3:00 hello.cpp
-rwxr-xr-x 1 root root 8968 Jul 12 3:00 hello.out
$

我们可以看到大小是8k左右,那么我们来strip看下

 $ strip hello.out -o hello.strip.out
$ ls -l
total 24
-rw-r--r-- 1 root root 171 Jul 12 3:00 hello.cpp
-rwxr-xr-x 1 root root 8968 Jul 12 3:00 hello.out
-rwxr-xr-x 1 root root 6120 Jul 12 3:10 hello.strip.out
$

很好,我们可以看到文件明显减少了许多,现在是一个6k左右的文件

6120÷8968≈0.6824=68.24%

1-68.24%=31.76%

减少了大概31.76%

嗯... 应该是加的库越多可以减少的越多吧。

那么我们来看看能不能正常运行

 $ ./hello.strip.out
hello,i = 0
hello,i = 1
hello,i = 2
hello,i = 3
hello,i = 4
hello,i = 5
hello,i = 6
hello,i = 7
hello,i = 8
hello,i = 9
$

我们看下strip都有那些用法。

 $ strip --help
Usage: strip <option(s)> in-file(s)
Removes symbols and sections from files
The options are:
-I --input-target=<bfdname> Assume input file is in format <bfdname>
-O --output-target=<bfdname> Create an output file in format <bfdname>
-F --target=<bfdname> Set both input and output format to <bfdname>
-p --preserve-dates Copy modified/access timestamps to the output
-D --enable-deterministic-archives
Produce deterministic output when stripping archives (default)
-U --disable-deterministic-archives
Disable -D behavior
-R --remove-section=<name> Also remove section <name> from the output
--remove-relocations <name> Remove relocations from section <name>
-s Remove all symbol and relocation information
-g -S -d --strip-debug Remove all debugging symbols & sections
--strip-dwo Remove all DWO sections
--strip-unneeded Remove all symbols not needed by relocations
--only-keep-debug Strip everything but the debug information
... #此处省略

那么我们可以看到,常见的有-I和-O,也就是输入和输出啦。发现一个不对的地方,它这里的O应该是小写的,大写的O会报错

然后是 -F format,设置输入和输出文件的格式

-p 保护日期,那么这个应该是不修改原来文件的modified的日期的吧

-D 和-U 需要一起讲,D应该就是它这个deterministic的意思吧,确定性的。那么-D就是产生确定性输出,-U就是不产生确定性输出。

-R 可以删除指定的section

-s 表示可以strip-all。

后面太多了,大家可以自行琢磨

嗯,大概就这些吧。正常使用的strip filename -o output_filename 就应该完全够用。

以上就是本文的全部内容,有什么疑问欢迎来一起探讨。

那么我们来看下加了s之后的文件大小是多少

 $ strip hello.out -p -s -o hello.s.out
$ ls -l
total 32
-rw-r--r-- 1 root root 171 Jul 12 3:00 hello.cpp
-rwxr-xr-x 1 root root 8968 Jul 12 3:00 hello.out
-rwxr-xr-x 1 root root 6120 Jul 12 3:00 hello.s.out
-rwxr-xr-x 1 root root 6120 Jul 12 3:10 hello.strip.out
$

哈哈,看来默认就是有-s的了

Linux下的strip命令学习的更多相关文章

  1. Linux下的upx命令学习

    upx学习 今天我们来学习一款给应用加壳的软件,叫做upx(the Ultimate Packer for eXecutables) 首先我们先看下它**百科的释义: UPX (the Ultimat ...

  2. linux下文件搜索命令学习笔记

    1. locate:按照文件名搜索文件 locate filename 与find在整个操作系统中遍历搜索不同,locate命令在/var/lib/mlocate这个后台数据库中按照文件名搜索,所以优 ...

  3. Linux下使用mail命令发送邮件

    因为需要经常备份网站的数据,所以了解并学习了下linux下如何通过shell来发送邮件,这里以CentOS为例,使用mail命令来进行外部邮件的发送.mail命令的语法如下: Usage: mail ...

  4. Linux下的Make命令实例详解

    众所周知在Linux系统下的make 命令是系统管理员和程序员用的最频繁的命令之一.管理员用它通过命令行来编译和安装很多开源的工具,程序员用它来管理他们大型复杂的项目编译问题.下面这 篇文章我们将用一 ...

  5. linux下显示dd命令的进度:

    linux下显示dd命令的进度: dd if=/dev/zero of=/tmp/zero.img bs=10M count=100000 想要查看上面的dd命令的执行进度,可以使用下面几种方法: 比 ...

  6. [转] 关于linux下通过shell命令(自动)修改用户密码

    关于linux下通过shell命令(自动)修改用户密码 2012-04-23 18:47:39 分类: 原文地址:关于linux下(自动)修改用户密码 作者:ubuntuer 本文章总结了如何手动.自 ...

  7. linux下安装7z命令及7z命令的使用

    本文主要介绍了在linux下安装7z命令的方法,同时介绍了7z命令的使用.7z压缩格式拥有众多优点,具有极高的压缩比率,如果你还不了解,请看文章:7z格式.LZMA压缩算法和7-Zip详细介绍. re ...

  8. 将linux下的rm命令改造成移动文件至回收站【转】

    转自:http://blog.csdn.net/a3470194/article/details/16863803 [-] 将linux下的rm命令改造成移动文件至回收站 将AIX下的rm命令改造成移 ...

  9. linux下常用FTP命令

    linux下常用FTP命令 1. 连接ftp服务器 1. 连接ftp服务器格式:ftp [hostname| ip-address]a)在linux命令行下输入: ftp 192.168.1.1b)服 ...

随机推荐

  1. 步步为营,打造CQUILib UI框架库

    步步为营,打造CQUILib UI框架库 UI框架包括如下几个方面:: 丰富的UI控件 窗口管理 主题 多语言 托盘 视图与业务解耦 登录框效果如下:: 提示框效果如下:: 后续讲解如何步步为营,打造 ...

  2. 【题解】「UVA1149」装箱 Bin Packing

    做法显然:贪心,但是怎么贪? 首先从大到小或从小到大排序,窝这次是从大到小排,这样更容易理解(从小到大更方变) 然后设置两个变量 front 和 after 作为前指针和后指针. 循环判断: 当前后两 ...

  3. 题解-CF677D Vanya and Treasure

    CF677D Vanya and Treasure 有一个 \(n\times m\) 的矩阵 \(a(1\le a_{i,j}\le p)\),求从起点 \((1,1)\) 出发依次遍历值为 \(1 ...

  4. Excel-HLOOKUP函数匹配查找②

    问题场景 绩效奖金评定发放,针对表中的考核员工,先按考核总分评级,再根据根据分级评定绩效奖金. 场景一 在考核员工表中,根据员工的考核总分将其分为四个等级(可根据业务场景和实际情况分析):A级分数区间 ...

  5. Springboot mini - Solon详解(七)- Solon Ioc 的注解对比Spring及JSR330

    Springboot min -Solon 详解系列文章: Springboot mini - Solon详解(一)- 快速入门 Springboot mini - Solon详解(二)- Solon ...

  6. Unity状态机(Animator)

    状态机的状态(State) 每个Animator Controller都会自带三个状态:Any State, Entry和 Exit.  

  7. Ajax相关基础知识总结

    URL:统一资源定位符 网络的七层协议:网卡 驱动  网络层(ip)  传输层(tcp udp) 会话层( )  应用层(http.) restful表征状态转移(一种表征架构) CURD 增删改查 ...

  8. remmina 软件rdp协议链接windows失败

    remmina 1.42  链接 win10 提示失败......其他版本win还没有测试过. 忘记了在那个论坛有是说加密问题,照着改确实可以.具体原因是默认设置加密方式这一项不知道为什么不起作用,手 ...

  9. IO流(03)--序列化流、打印流

    序列化流 Java提供了一种对象序列化的机制,用一个字节序列可以表示一个对象,该字节序列包含该对象的数据.对象的类型和对象中存储的属性等信息.字节序列写入到文件中后,就相当于在文件中保存了一个对象信息 ...

  10. [C#] (原创)一步一步教你自定义控件——05,Label(原生控件)

    一.前言 技术没有先进与落后,只有合适与不合适. 自定义控件可以分为三类: 一类是"无中生有".就如之前文章中的的那些控件,都是继承基类Control,来实现特定的功能效果: 一类 ...