Duplo is a command-line utility for detecting the duplicated sections of source code. It can scan files, identify repeated blocks, and report the locations and number of duplicate lines. Duplo supports C, C++, C#, Java, and other programming languages. This tutorial shows how to install Duplo duplicate code finder on Ubuntu 26.04.
Prepare environment
Duplo release is distributed as a ZIP archive, so the unzip package is required before installation.
sudo apt update
sudo apt install -y unzip
Install Duplo
Download the latest archive from the GitHub releases page:
curl -sSLo duplo.zip https://github.com/dlidstrom/Duplo/releases/latest/download/duplo-linux.zip
Extract the Duplo executable into /usr/local/bin:
sudo unzip -q duplo.zip duplo -d /usr/local/bin
The downloaded archive is no longer needed after extraction and can be removed:
rm -rf duplo.zip
Testing Duplo
A small C source file containing two identical functions provides a straightforward test. Create a test.c file:
nano test.c
Add the following content:
#include <stdio.h>
void process_user(const char *name, const int age, const char *email) {
printf("Processing user...\n");
printf("User: %s\n", name);
printf("Age: %d\n", age);
printf("User: %s\n", email);
}
void process_customer(const char *name, const int age, const char *email) {
printf("Processing user...\n");
printf("User: %s\n", name);
printf("Age: %d\n", age);
printf("User: %s\n", email);
}
Duplo accepts two positional arguments: the first specifies where the list of files comes from, while the second specifies where the analysis results are written. A hyphen (-) represents standard input or standard output, depending on its position. Run Duplo with the filename supplied through standard input and writing results to standard output:
echo 'test.c' | duplo - -
The output should look the following:
Loading and hashing files ... 1 done.
test.c(11)
test.c(4)
printf("Processing user...\n");
printf("User: %s\n", name);
printf("Age: %d\n", age);
printf("User: %s\n", email);
test.c found: 1 block(s)
Configuration:
Number of files: 1
Minimal block size: 4
Minimal characters in line: 3
Ignore preprocessor directives: 0
Ignore same filenames: 0
Results:
Lines of code: 11
Duplicate lines of code: 4
Total 1 duplicate block(s) found.
The report indicates that Duplo found one duplicated block. Four lines of code are identified as duplicates, confirming that the duplicate-code scanner is operating correctly.
Uninstall Duplo
When Duplo is no longer required, remove its executable:
sudo rm -rf /usr/local/bin/duplo
Leave a Comment
Cancel reply