linux中的file命令简介
2015-07-26 20:22
585 查看
我们先来看看三个文件,
test.h文件:
main.c文件:
test.h和test.c, main.c很简单, 我就不说了。
test.o和main.o都是目标文件, ELF 32-bit LSB relocatable, not stripped
a.out是可执行文件, 我们可以看到,ELF 32-bit LSB executable, dynamically linked (uses shared libs), not stripped
libtest.a是静态链接库, 我们可以看到, current ar archive
libtest.so是动态链接库, 我们可以看到,ELF 32-bit LSB shared object, dynamically linked, not stripped
注意到, 目标文件、可执行文件、静态链接库、动态链接库都是ELF文件, 且暂时都是not stripped, 那么什么是ELF文件, 什么是not stripped呢? 后续我们会介绍。
OK, 本文主要说说file命令, 很简单, 先到此为止吧。
test.h文件:
void print();test.c文件:
#include <stdio.h> #include "test.h" void print() { printf("rainy days\n"); }
main.c文件:
#include "test.h" int main() { print(); return 0; }下面, 我们来生成目标文件、静态链接库、动态链接库、可执行文件, 然后用file命令来玩玩, 如下:
[taoge@localhost learn_file]$ ls main.c test.c test.h [taoge@localhost learn_file]$ gcc -c test.c main.c [taoge@localhost learn_file]$ ls main.c main.o test.c test.h test.o [taoge@localhost learn_file]$ gcc test.o main.o [taoge@localhost learn_file]$ ls a.out main.c main.o test.c test.h test.o [taoge@localhost learn_file]$ ./a.out rainy days [taoge@localhost learn_file]$ ar rcs libtest.a test.o [taoge@localhost learn_file]$ gcc -shared -fPIC -o libtest.so test.o [taoge@localhost learn_file]$ ls a.out libtest.a libtest.so main.c main.o test.c test.h test.o [taoge@localhost learn_file]$ ls -l total 36 -rwxrwxr-x 1 taoge taoge 4703 Jul 26 00:23 a.out -rw-rw-r-- 1 taoge taoge 990 Jul 26 00:23 libtest.a -rwxrwxr-x 1 taoge taoge 4025 Jul 26 00:24 libtest.so -rw-rw-r-- 1 taoge taoge 55 Jul 26 00:15 main.c -rw-rw-r-- 1 taoge taoge 764 Jul 26 00:22 main.o -rw-rw-r-- 1 taoge taoge 80 Jul 26 00:12 test.c -rw-rw-r-- 1 taoge taoge 14 Jul 26 00:12 test.h -rw-rw-r-- 1 taoge taoge 848 Jul 26 00:22 test.o [taoge@localhost learn_file]$ ls -l total 36 -rwxrwxr-x 1 taoge taoge 4703 Jul 26 00:23 a.out -rw-rw-r-- 1 taoge taoge 990 Jul 26 00:23 libtest.a -rwxrwxr-x 1 taoge taoge 4025 Jul 26 00:24 libtest.so -rw-rw-r-- 1 taoge taoge 55 Jul 26 00:15 main.c -rw-rw-r-- 1 taoge taoge 764 Jul 26 00:22 main.o -rw-rw-r-- 1 taoge taoge 80 Jul 26 00:12 test.c -rw-rw-r-- 1 taoge taoge 14 Jul 26 00:12 test.h -rw-rw-r-- 1 taoge taoge 848 Jul 26 00:22 test.o [taoge@localhost learn_file]$ file * a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped libtest.a: current ar archive libtest.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (GNU/Linux), dynamically linked, not stripped main.c: ASCII C program text main.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped test.c: ASCII C program text test.h: ASCII text test.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped [taoge@localhost learn_file]$我们看到, 虽然ls -l能大概看到文件的类型, 但是, 那结果太粗略了。 还是用file命令吧, 它可以比ls -l更详细地显示文件的类型信息。 我们知道, 在Windows中, 系统根据文件的后缀名来判断文件类型, 一个test.exe文件如果改名为test.xxx, 那就不能运行了。 而在linux中, 实际并不存在文件扩展名一说, 系统是根据文件本身的信息来判断文件类型的。
test.h和test.c, main.c很简单, 我就不说了。
test.o和main.o都是目标文件, ELF 32-bit LSB relocatable, not stripped
a.out是可执行文件, 我们可以看到,ELF 32-bit LSB executable, dynamically linked (uses shared libs), not stripped
libtest.a是静态链接库, 我们可以看到, current ar archive
libtest.so是动态链接库, 我们可以看到,ELF 32-bit LSB shared object, dynamically linked, not stripped
注意到, 目标文件、可执行文件、静态链接库、动态链接库都是ELF文件, 且暂时都是not stripped, 那么什么是ELF文件, 什么是not stripped呢? 后续我们会介绍。
OK, 本文主要说说file命令, 很简单, 先到此为止吧。
相关文章推荐
- centos7.1 QT5编译出现:cannot find -lGL 和 collect2:error:ld returned 1 exit status 错误
- Centos7.1安装CUDA7.0
- ftp工具root登入linux设置
- linux安装mysql
- Linux使用Java将C++程序发布为webservice(wsdl)
- linux内核bootsect.S和setup.S流程
- linux查看jar包内文件命令
- Linux下如何安全退出线程
- 解决linux下set_loginuid failed opening loginuid报错问题
- linux ssh 别名登录小技巧
- 【Vbox】centos虚拟机安装usb网卡驱动
- 【Vbox】centos虚拟机安装usb网卡驱动
- Linux md raid
- linux多线程驱动中调用udelay()对整个系统造成的影响(by liukun321咕唧咕唧)
- SecureCRT 连接本地linux虚拟机(二)
- Linux devive mapper multipath
- linux系统编程:线程同步-信号量(semaphore)
- 本地虚拟机下的centOS安装jdk1.7
- Linux Min装机--配置JDK替换OpenJDK
- Linux监控和安全运维---zabbix安装及部署