ar command in Linux with examples - GeeksforGeeks

04 Apr, 2019
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.
Syntax:
ar [OPTIONS] archive_name member_files
Options:
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 *star1This will create an archive with member star1. With modifier it looks like as:ar rv super.a *star1.txtNote: The modifier v gives a line or output with letter a or r indicating if the file is appended or not.
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.txtIn our previous case, we used star1.txt in archive super.a, now we will delete that file from thereIn that we had super.a archive storing star1.txt, after using d without modifier it just deleted the filenow lets see the same example with modifier var dv super.a star1.txtWith using modifier v it listed module as they are 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 filenow 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.aHere 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.aWith the use of the modifier, first get the file name and then content written inside it.
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.aThis time with the use of modifier we get 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.
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.
linux-command
Linux-file-commands
Picked
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
TCP Server-Client implementation in C
ZIP command in Linux with examples
SORT command in Linux/Unix with examples
tar command in Linux with examples
curl command in Linux with Examples
'crontab' in Linux with Examples
Tail command in Linux with examples
UDP Server-Client implementation in C
diff command in Linux with examples
Cat command in Linux with examples