Linux ar Command
The Linux ar command is used to create, modify, or extract files from an archive.
ar allows you to combine multiple files into a single archive. All member files retain their original attributes and permissions within the archive.
Syntax
ar [-dmpqrtx] [cfosSuvV] [a<member_file>] [b<member_file>] [i<member_file>] [archive_file] [member_file]
Parameters:
Required Parameters:
- -d Delete member files 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 included in the archive.
- -x Extract member files from the archive.
Optional Parameters:
- a<member_file> Insert files after the specified member file in the archive.
- b<member_file> Insert files before the specified member file in the archive.
- c Create an archive.
- f Truncate long member file names to avoid compatibility issues with other systems' ar commands.
- i<member_file> Insert files before the specified member file in the archive.
- o Preserve the dates of files in the archive.
- s Create a symbol table if the archive contains object patterns.
- S Do not generate a symbol table.
- u Insert only newer files into the archive.
- v Display detailed information during execution.
- V Display version information.
Examples
Packaging files
[[email protected] ~]# ls // Display current directory files
a.c b.c d.c install.log qte
anaconda-ks.cfg c.c Desktop
[[email protected] ~]# ar rv one.bak a.c b.c // Package a.c b.c files
ar: Creating one.bak
a - a.c
a - b.c
[[email protected] ~]#
Packaging multiple files
[[email protected] ~]# ar rv two.bak *.c // Package files ending with .c
ar: Creating two.bak
a - a.c
a - b.c
a - c.c
a - d.c
[[email protected] ~]#
Displaying the contents of a packaged file
[[email protected] ~]# ar t two.bak
a.c
b.c
c.c
d.c
[[email protected] ~]#
Deleting member files from a packaged file
[[email protected] ~]# ar d two.bak a.c b.c c.c
[[email protected] ~]# ar t two.bak
d.c