I did not know anything about pax, until I read a very nice written article in the linux journal magazine about this great command-line utility. Now you guys may ask, what is pax?
pax is a command-line tool that can be used to read, write, and list the members of an archive file. You will completly understand what I am talking about if you have used or use cli tools to create and extract archives.
Do you use the tar utility?
Learn To Perform Basic Operations With pax
pax has many options that are very easy to understand and remember. It operates in four modes: list, read, write and copy.
What options are used for each one of the operating modes?
The options used by pax make sense to me. The -r option is used to extract the archive specified from the standard input and the -w option is used to write an archive.
Note: Make sure to combine them with the -f option.
Lets take a look at a simple practical example that will demonstrate two things:
1. How to create a tarball with the pax utility
2. How to extract a tar archive with the pax utility
Ok, now open a new terminal and run the following commands to create a testing environment that we need to practise the usage of pax utility.
Now lets create the tarball by running the following command.
pax -wf test.tar test
After the tarball is created, run the following command and see what happens.
pax -f test.tar
The following console output shows the result of the above command.
[email protected]:~/Desktop$ pax -f test.tar
When the pax command is used only with the -f option it lists the contents of the archive that is passed as argument. You can clearly see it in the above output.
Now that we created the tar archive, how can we extract its content? I am very familiar with the tar utility and i can use the tar -xf test.tar command, but from now on I prefer to use pax.
The following command can be used to extract the contents of an archive.
pax -rf test.tar
The pax utility supports many archive formats such as ar, bcpio, tar, ustar, sv4crc and many others that I will not share here.
Is there anything that pax can do, but tar can't? To be honest with you guys I am not completly sure but I don't think that the tar utility can be used to copy files.
pax can do it!
In order to copy files with the pax utility you need to learn how to use it with the -rw options. Run the following command and see if it copies the file you want to copy.
Make sure you are in Desktop because we will try to copy a file to the test folder.
pax -rw file_you_want_to_copy test
Should You Switch To pax?
I can't tell anything about it, it is up to you. I have been using pax for a week now and it has been very cool so far. The -r and -w options in pax make more sense to me than their equivalents in the tar command-line utility.
I can say only one thing: if you like to work in terminal and you are familiar with the tar command-line tool it will be very easy for you to switch.
Are you going to like pax as much as I do? I don't know, but I would like to know about that, so don't hesitate to share your opinions about your experience with this amazing tool in the comments.