
ptardiff Command in Linux
The ptardiff command in Linux is a Perl-based tool that compares the contents of the extracted archive in the current directory to the files within the tar archive. It simplifies tracking changes by comparing tar archive contents with files in the current directory. It helps generate patch files, ensuring efficient workflows for validating updates or creating versioned changes.
Table of Contents
Here is a comprehensive guide to the options available with the ptardiff command in Linux −
- Prerequisites of ptardiff Command
- Syntax of ptardiff Command
- ptardiff Command Options
- Examples of ptardiff Command in Linux
Prerequisites of ptardiff Command
While using the ptardiff command, it may throw the following missing Text::Diff module error −

To fix this error, install the Perl Text::Diff module on Linux. It can be installed using the Perl package manager CPAN. To install Text::Diff using CPAN, use the following command −
sudo cpan Text::Diff
Ensure the CPAN is installed.
To Text::Diff module can also be installed using the Linux native package manager. To install it on Ubuntu, Kali Linux, Raspberry Pi OS, Debian, and other Debian-based distributions, use the following command −
sudo apt install libtext-diff-perl
To install it on Fedora, run the following commands −
sudo dnf install perl-Text-Diff
To find out if it is installed or not use the following command −
cpan -l | grep "Text::Diff"

Syntax of ptardiff Command
The syntax of the ptardiff command in Linux is as follows −
ptardiff [archive_file]
In the above syntax, the [archive_file] field is used to specify the path to the tar archive file that will be compared against files in the current directory. Replace [archive_file] with the actual file name, such as sample.tar.gz.
ptardiff Command Options
The options of the Linux ptardiff command are listed below −
Option | Description |
---|---|
-h | Displays help message |
Examples of ptardiff Command in Linux
This section demonstrates the usage of the ptardiff command in Linux with examples −
Using ptardiff Command to Compare Files
The current directory contains a tar file with the name of test.tar and its extracted contents file1.txt and file2.txt as shown in the image below −

Let's execute the ptardiff command −
ptardiff test.tar
Since the contents of the files in the current directory and the archive file are the same (no difference), there will be no output, as shown in the following image.

Now, let's open file1.txt in the nano editor and modify it by adding some text.
sudo nano file1.tx
The updated contents of the file1.txt and file2.txt are shown below −

Now, execute the ptardiff command again.
ptardiff test.tar
This time it will show the following output.

This output shows a difference between the two versions of file1.txt. The - line is the original content, and the + line highlights the updated content where "Hello" was added.
Creating a Patch using ptardiff Command
To save the difference in a patch file, use the ptardiff command in the following way −
ptardiff test.tar > file1.patch
The above command redirects (>) the output to the file1.patch file.
Displaying Usage Help
To display the usage help of the ptardiff tool, use the -h option −
ptardiff -h
Conclusion
The ptardiff command in Linux is a useful tool for comparing the contents of a tar archive with its extracted files in the current directory. It helps identify changes by generating patch files, which can streamline workflows for validating updates or managing versioned changes. The command requires the Perl Text::Diff module, which can be installed via CPAN or a native package manager.
Through simple syntax and options, such as displaying help or generating patches, ptardiff ensures efficient comparison and tracking of modifications in tar archives.
In this tutorial, we covered the ptardiff command, its syntax, options, and usage in Linux with examples.