offer jobs schedule amazon media file explorer download upload index folder image licenses menu widget Play Pause profile-settings more dots-two-horizontal dots-two-vertical more-vertical pending google-plus hangouts facebook instagram whatsapp spotify telegram twitter vine renren rss youtube twitch vimeo flickr dribble behance deviantart 500px steam github soundcloud skype reddit linkedin lastfm delicious stackoverflow pinterest xing flattr foursquare yelp World

What is ar Command in Linux and How Do I Use It?

ar is a command on a UNIX-Like system, we would be covering the one on Linux Based Distro a.k.a, the GNU ar command.

So...

GNU ar is a command line tool used for creating, modifying, and extracting files from archives. An archive is a single file that contains multiple files, often in a compressed format. GNU ar is part of the GNU Compiler Collection (GCC) and is commonly used on Linux and other Unix-like operating systems.

Using GNU ar

To use GNU ar, you must first open a terminal window on your system. From there, you can use the following commands:

  • ar -q <archive name> <file1> <file2> ...: This command creates a new archive with the specified name and adds the specified files to it.
  • ar -x <archive name>: This command extracts the contents of the specified archive into the current directory.
  • ar -t <archive name>: This command displays a list of the files in the specified archive.
  • ar -d <archive name> <file1> <file2> ...: This command deletes the specified files from the specified archive.
  • ar -m <archive name> <file1> <file2> ...: This command moves the specified files within the specified archive.


By default, GNU ar uses the .a file extension for archives. However, you can specify a different file extension by using the -f flag, like this:

ar -f <file extension>.

GNU ar also provides some additional options that you can use when creating or modifying archives.

For example, you can use the -c flag to create an archive without adding any files to it, or the -s flag to include a symbol table in the archive. You can view the full list of available options by using the man command to view the GNU ar manual.

GNU ar Command Examples

Here are some examples of using GNU ar:

Creating an Archive Using ar Command

To create a new archive called "myfiles.a" and add the "file1.txt" and "file2.txt" files to it, you would use the following command:

ar -q myfiles.a file1.txt file2.txt

Extracting Content Using ar Command

To extract the contents of the "myfiles.a" archive into the current directory, you would use the following command:

ar -x myfiles.a

Display Files in an Archive Without Extraction it Using the ar Command

To display a list of the files in the "myfiles.a" archive, you would use the following command:

ar -t myfiles.a

Deleting Files From Archive Using The ar Command

To delete the "file1.txt" and "file2.txt" files from the "myfiles.a" archive, you would use the following command:

ar -d myfiles.a file1.txt file2.txt

Move Files Within Archive Using the ar Command

To move the "file1.txt" and "file2.txt" files within the "myfiles.a" archive, you would use the following command:

ar -m myfiles.a file1.txt file2.txt

Create an Empty Archive Using the ar Command

To create an archive without adding any files to it, you would use the -c flag, like this:

ar -c -q myfiles.a

Specify Different Extensions for an Archive

To specify a different file extension for the archive, you would use the -f flag, like this:

ar -f .tar -q myfiles.tar file1.txt file2.txt

Verbose Output with ar Command

The command below enables verbose output, which will display additional information about the progress of the operation:

ar -v

Replace File in an Archive with the ar Command

The command below replaces the specified files in the specified archive with new versions of the files.

ar -r <archive name> <file1> <file2> ...

Append To Archive Without Deleting or Replacing Existing File

The below command appends the specified files to the specified archive, without deleting or replacing any existing files.

ar -A <archive name> <file1> <file2> ...

Get the Current ar Version

To display the version number of the GNU ar tool, you would use the --version flag, like this:

ar --version

View ar Manual

To view the manual for the GNU ar tool, you would use the man command, like this:

man ar

These examples demonstrate some cool uses of GNU ar. You can use these commands and options to create more complex and flexible archives on your system.

You are welcome.

Related Post(s)

  • The ac Command in Unix & Linux

    The ac command is a Unix utility that is used to display statistics about users' connect time. It displays the total connect time for all users or for a specific user. The connect time is the amount o

  • What is Linux adduser and addgroup commands

    The adduser and addgroup commands are Linux utilities that are used to create new user and group accounts on a Linux system. The adduser command is used to create a new user account, while the addgrou

  • What is alias and How Do I Use It in Linux?

    The alias command can be used to represent a longer command or series of commands in Linux. Aliases allow you to type a shorter and easier-to-remember name instead of the full command, which can save

  • What is unlias & How Do I Use It in Linux?

    The unalias command is a Linux utility that is used to remove an alias that has been defined on the system. To use the unalias command, you simply need to specify the name of the alias that you want

  • What is apt-get and How Do I Use It?

    apt-get is a command line tool used for managing packages on a Debian-based Linux system. It is a part of the Advanced Packaging Tool (apt) system, which is used to manage the installation, removal, a

  • What is as Command in Linux and How Do I Use It?

    The as command in Linux is a tool for assembling (compiling) assembly language source code into machine code that can be executed on a computer. Assembly language is a low-level programming language