ptar Command in Linux



The ptar command in Linux is a Perl-based tar-like utility used for handling tar archives, including creating, extracting, and listing the contents of tar files using the Archive::Tar module. It is particularly useful in Perl-based environments or when scripting with Perl modules, offering better integration with Perl than tar.

Table of Contents

Here is a comprehensive guide to the options available with the ptar command in Linux −

Syntax of ptar Command

The syntax of the ptar command in Linux is as follows −

ptar [options] [file...]

The [options] field in the above syntax is used to specify the options such as -c for creating, -x for extracting, -t for listing, and additional parameters like the archive name. The [file] field is used to specify the files or directories to include in or extract from the tar archive.

ptar Command Options

The options for the Linux ptar command are listed below −

Option Description
-c Create an archive file or output to STDOUT (-) from specified files
-x Extract files from the archive or from STDIN (-)
-t Display the contents of the archive or from STDIN (-)
-f Specify the archive file name to use (default is ./default.tar)
-z Handle zlib-compressed archive files (may not be available)
-v Show filenames as they are added to or extracted from the archive
-h Display the help message
-C Enable CPAN mode, which drops the 022 permission mask
-T Read filenames from a file to create the archive

Examples of ptar Command in Linux

In this section, the usage of the ptar command in Linux will be discussed with examples −

Creating a Tar Archive

To create a tar archive, use the -c option with the ptar command in the following way −

ptar -c file1.txt file2.txt
ptar Command in Linux1

The above command generates a tar file with the name default.tar in the current working directory as shown in the output image.

Creating a Tar Archive with a Custom Name

By default, the tar archive file is generated with the default.tar name. To set a custom name, use the -f option. For example, to archive the contents with the archive.tar name, use the following command −

ptar -c -f archive.tar file1.txt file2.txt
ptar Command in Linux2

Creating a Tar Archive by Getting File Names from a File

To create an archive using the file name specified in a text file, use the -T option −

ptar -c -T files.txt -f new_archive.tar
ptar Command in Linux3

Setting CPAN Mode for Permission Handling

To create an archive with the CPAN mode which removes the 022 permission mask, use the -C option. The 022 permission mask restricts the write access.

ptar -c -C -f archive.tar file1.txt file2.txt

Extracting a Tar Archive

To extract the tar archive, use the -x option with the Linux ptar command −

ptar -x -f archive.tar
ptar Command in Linux4

Extracting a Compressed Tar File

To extract a compressed tar file, use the -z option −

ptar -x -z -f archive.tar.gz

Getting Verbose Output

To get the file names printed as they are archived or extracted, use the -v option with the command −

ptar -c -v file1.txt file2.txt
ptar Command in Linux5

During extracting the contents −

ptar -x -v -f default.tar
ptar Command in Linux6

Listing the Contents of a Tar File

To list the contents in a tar file, use the -t option −

ptar -t -f archive.tar
ptar Command in Linux7

Displaying the Usage Help

To display the usage help of the ptar command, use the -h option −

ptar -h

Conclusion

The ptar command in Linux offers functionality for managing tar archives in Perl-based environments. It supports various operations such as creating, extracting, and listing files from archives, with options for compression handling and verbose output. It also offers advanced features like CPAN mode for permission handling and the ability to specify filenames from external files, making it a powerful tool for efficient archive management.

Advertisements