ar command is used to create, modify and extract the files from the archives. An archive is a collection of other files having a particular structure from which the individual files can be extracted. Individual files are termed as the members of the archive.
ar [OPTIONS] archive_name member_files
- r: This is used to create archive, insert files in archive. This is different from q as it deletes any previously existing members. If any member filename does not exist it throws an error. By default, it adds a new member at end of the file.
Example: Assume there is a file named star1 and you want to create archive named “super” without modifier then you can use the following command:
ar r super.a *star1
This will create an archive with member star1. With modifier it looks like as:
ar rv super.a *star1.txt
Note: The modifier v gives a line or output with letter a or r indicating if the file is appended or not.
- d: Deletes modules from archive. Specify names of the modules as member…; When you add modifier v, ar lists each module as it is deleted.
ar d super.a star1.txt
In our previous case, we used star1.txt in archive super.a, now we will delete that file from there
In that we had super.a archive storing star1.txt, after using d without modifier it just deleted the file
now lets see the same example with modifier v
ar dv super.a star1.txt
With using modifier v it listed module as they are deleted.
- p: This option is used to print the specified members of a archive in a standard output file if you do not use modifier it will print member as it is an output file whereas if you use modifier v then it will show member name before it is copied to output file.
ar p super.a
Here it gave the output which was written in our files stat1.txt and star2.txt, now let us check what happens when we use modifier v in it.
ar pv super.a
With the use of the modifier, first get the file name and then content written inside it.
- t: It displays the contents of the archive in a listed manner, usually, it shows the contents of the archive but if we use modifier O then it also shows the corresponding offset of each member.
ar t super.a (taking our old files and examples)
Here t displayed the members of the archive, now lets see what it shows when we use modifier.
ar tO super.a
This time with the use of modifier we get the corresponding offset of each member.
- x: It extracts each named member from the archive if you do not name the member to be extracted it extracts the whole archive. We can use v modifier to list name of each member which is extracted.
The modifier v displays each file which is extracted and also we did not specify a name so it extracted the whole archive if we specify names of the member it extracts only that member.
This command does not extract thin files as in our case, it just displays that it has extracted the archive.
The above image shows extraction based on specified member name, and v modifier lists file is extract.
- wc command in Linux with examples
- ZIP command in Linux with examples
- env command in Linux with Examples
- fg command in Linux with examples
- ssh command in Linux with Examples
- cd command in Linux with Examples
- gcc command in Linux with examples
- dir command in Linux with examples
- id command in Linux with examples
- atd command in Linux with examples
- Cat command in Linux with examples
- fmt command in Linux with examples
- arp command in Linux with examples
- top command in Linux with Examples
- yes command in Linux with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.