Linux ar Command
The Linux ar command is used to create or modify archives, or to extract files from archives.
ar lets you collect many files into a single archive. Within the archive, all member files retain their original attributes and permissions.
Syntax
ar[-dmpqrtx][cfosSuvV][a<成员文件>][b<成员文件>][i<成员文件>][备存文件][成员文件]
Parameters:
Required Parameters:
- -d Delete a member file from the archive.
- -m Change the order of member files in the archive.
- -p Display the contents of member files in the archive.
- -q Append files to the end of the archive.
- -r Insert files into the archive.
- -t Display the files contained in the archive.
- -x Extract member files from the archive.
Optional Parameters:
- a
Insert files after the specified member file in the archive. - b
Insert files before the specified member file in the archive. - c Create an archive.
- f To avoid incompatibility of overly long file names with ar on other systems, this option truncates member file names that are too long to be placed in the archive.
- i
Insert files before the specified member file in the archive. - o Preserve the dates of files in the archive.
- s If the archive contains object modules, this option can be used to create a symbol table for the archive.
- S Do not generate a symbol table.
- u Insert only files with more recent dates into the archive.
- v Display detailed information during execution.
- V Display version information.
Example
Create an archive
[root@runoob.com ~]# ls //显示当前目录文件
a.c b.c d.c install.log qte
anaconda-ks.cfg c.c Desktop
[root@runoob.com ~]# ar rv one.bak a.c b.c //打包 a.c b.c文件
ar: 正在创建 one.bak
a - a.c
a - b.c
[root@runoob.com ~]#
Archive multiple files
[root@runoob.com ~]# ar rv two.bak *.c //打包以.c结尾的文件
ar: 正在创建 two.bak
a - a.c
a - b.c
a - c.c
a - d.c
[root@runoob.com ~]#
Display the contents of an archive
[root@runoob.com ~]# ar t two.bak
a.c
b.c
c.c
d.c
[root@runoob.com ~]#
Delete a member file from an archive
[root@runoob.com ~]# ar d two.bak a.c b.c c.c
[root@runoob.com ~]# ar t two.bak
d.c
Linux Command Reference