ar command in Linux is an important tool which is used to extract, modify and create files from archives. Archives can be defined as a collection of other files having a particular structure from which the individual files can be extracted. Individual Files are known as a member of the archive.
Syntax to use with ar command
ar [OPTIONS] archive_name member_files
Available options to use with ar commands
- r: Used for creating archive and inserting files in it. It’s a bit similar to q, however it deletes any previous existing members. In case if it notice a member filename is non-existing, it will throw error on screen. Also it adds a new member at the end of file by default.
- d: Used for deleting modules from archive, specifying names of the modules as member. In case if a modifier v is added, ar lists each of the module as deleted.
- p: Used for printing the specified member of an archive in standard output file. In case if no modifier is added, will print member as an output file. However in case if modifier is added, will print member name before copying it to output.
- t: Used for displaying contents of archive in a listed form.
- x: Used for extracting each named member from the archive, however if no member name is specified, it will extract the whole archive. With the use of v modifier, it will list the name of each member that is extracted.
Examples of ar command
1: Creating an archive named servonode with a specified file tutorial.txt
ar r servonode.a *tutorial.txt
2: Deleting a module tutorial.txt from servonode.a
ar d servonode.a tutorial.txt