Linux ar command

Linux 命令大全Linux Command Reference

The Linux ar command is used to create or modify archive files, or to extract files from archive files.

ar allows you to collect many files into a single archive file. In the archive file, all member files retain their original attributes and permissions.

Syntax

ar[-dmpqrtx][cfosSuvV][a<成员文件>][b<成员文件>][i<成员文件>][备存文件][成员文件]

Parameters:

Required parameters:

  • -d Delete member files from the archive file.
  • -m Change the order of member files in the archive file.
  • -p Display the contents of member files in the archive file.
  • -q Append files to the end of the archive file.
  • -r Insert files into the archive file.
  • -t Display the files contained in the archive file.
  • -x Extract member files from the archive file.

Option parameters:

  • a<member file> Insert the file after the specified member file in the archive file.
  • b<member file> Insert the file before the specified member file in the archive file.
  • c Create an archive file.
  • f To avoid incompatibility of overly long filenames with other systems' ar command, use this parameter to truncate overly long member filenames to be placed in the archive file.
  • i<member file> Insert the file before the specified member file in the archive file.
  • o Preserve the dates of files in the archive file.
  • s If the archive file contains object modules, use this parameter to create a symbol table for the archive file.
  • S Do not generate a symbol table.
  • u Only insert files with newer dates into the archive file.
  • v Display detailed information during program execution.
  • V Display version information.

Examples

Package files

[root@example.com ~]# ls   //显示当前目录文件   
a.c    b.c d.c   install.log      qte
anaconda-ks.cfg c.c Desktop 

[root@example.com ~]# ar rv one.bak a.c b.c //打包 a.c b.c文件 
ar: 正在创建 one.bak
a - a.c
a - b.c
[root@example.com ~]# 

Package multiple files

[root@example.com ~]# ar rv two.bak *.c  //打包以.c结尾的文件  
ar: 正在创建 two.bak
a - a.c
a - b.c
a - c.c
a - d.c
[root@example.com ~]# 

Display the contents of the packaged files

[root@example.com ~]# ar t two.bak    
a.c
b.c
c.c
d.c
[root@example.com ~]# 

Delete member files from the packaged file

[root@example.com ~]# ar d two.bak a.c b.c c.c  
[root@example.com ~]# ar t two.bak       
d.c

Linux 命令大全Linux Command Reference

Other Extensions