Ugacomp

How to convert various file types to different formats in Linux

Where necessary, you may need to have access to a VPS server so you can follow how to implement the steps in this article.  You can get a cheaper VPS Server from Contabo with 4vCPU cores, 8GM RAM, and 32TB Bandwidth for less than $5.50 per month. Get this deal here now

Table of Contents

Cloud VPS S

$5.50 Monthly
  • 4 vCPU Cores | 8GB RAM

CLOUD VPS M

$15.50 Monthly
  • 6 vCPU Cores | 16GB RAM

CLOUD VPS L

$17.50 Monthly
  • 8 vCPU Cores | 24GB RAM

Linux provides a powerful command-line interface that allows users to perform a variety of tasks, including converting file types. Whether you need to convert documents, images, or audio files, Linux offers a range of tools to handle the job efficiently. In this article, we will explore how to convert various file types to different formats using command-line examples.

Converting a Word Document to PDF

To convert a Microsoft Word document to PDF, you can use the libreoffice command.

To install LibreOffice on Ubuntu Linux, run the following commands:

sudo apt update
sudo apt install libreoffice

For Red Hat, Fedora, and related distributions, use the following commands:

sudo dnf install libreoffice

Now, we can use libreofice to convert Word Document to PDF using this command:

libreoffice --convert-to pdf input.docx

Replace “input.docx” with the name of your Word document.

Batch Converting DOCX to PDF

For bulk conversion of multiple Word documents to PDF, you can use a for loop along with libreoffice:

for file in *.docx; do
    libreoffice --convert-to pdf "$file"
done

This script iterates through all DOCX files in the current directory and converts each to PDF.

Converting a PDF to Text

If you need to extract text from a PDF file, the pdftotext command comes in handy:

pdftotext input.pdf output.txt

This command converts “input.pdf” to a plain text file named “output.txt.”

Converting PDFs in a Directory to Text

To convert all PDF files in a directory to text files, you can use a similar loop with pdftotext:

for file in *.pdf; do
    pdftotext "$file" "${file%.pdf}.txt"
done

This script extracts text from each PDF and saves it with the same name but a TXT extension.

Converting PNG to JPEG

To convert a PNG image to JPEG, you can use the convert command from the ImageMagick package.

To install ImageMagick on Ubuntu, you can use the following commands in the terminal. Open a terminal window and type the following:

sudo apt update
sudo apt install imagemagick

To convert an image from one format to another

convert input.png output.jpg

Adjust the filenames accordingly.

Converting Multiple PNGs to JPEG

For converting multiple PNG images to JPEG, you can leverage the power of convert:

for file in *.png; do
    convert "$file" "${file%.png}.jpg"
done

This script iterates through all PNG files, converting each to JPEG.

Resizing Images

The mogrify command is useful for resizing images. mogrify is part of the ImageMagick suite, so if you’ve already installed ImageMagick, you should have access to the mogrify command as well.

For example, to resize an image to a specific width:

mogrify -resize 800x input.jpg

Replace “input.jpg” with the name of your image.

Batch Resizing Images

When dealing with a collection of images, resizing them becomes efficient using the mogrify command:

mogrify -resize 800x600 *.jpg

This command resizes all JPEG images in the current directory to a width of 800 pixels and a height of 600 pixels.

Converting MP3 to WAV

To convert an MP3 audio file to WAV format, you can use the ffmpeg command: To install FFmpeg on Ubuntu, you can use the following commands in the terminal:

sudo apt update
sudo apt install ffmpeg

Now, you convert audio files using ffmpeg:

ffmpeg -i input.mp3 output.wav

Ensure you have the FFmpeg tool installed.

Changing Bitrate

Adjusting the bitrate of an audio file is easy with the ffmpeg command. For instance, to change the bitrate to 192 kbps:

ffmpeg -i input.wav -b:a 192k output.wav

Bulk MP3 to WAV Conversion

To convert a batch of MP3 files to WAV, combine ffmpeg with a loop:

for file in *.mp3; do
    ffmpeg -i "$file" "${file%.mp3}.wav"
done

This script processes all MP3 files in the directory, producing corresponding WAV files.

Changing Bitrate for Multiple Audio Files

For adjusting the bitrate of several audio files simultaneously, modify the ffmpeg loop:

for file in *.wav; do
    ffmpeg -i "$file" -b:a 192k "${file%.wav}_192kbps.wav"
done

This script changes the bitrate of each WAV file to 192 kbps.

It’s important to note that scripts for bulk conversion tasks are bash scripts. This means that you will have to save and run them as bash scripts

Hire us to handle what you want

Hire us through our Fiverr Profile and leave all the complicated & technical stuff to us. Here are some of the things we can do for you:

  • Website migration, troubleshooting, and maintenance.
  • Server & application deployment, scaling, troubleshooting, and maintenance
  • Deployment of Kubernetes, Docker, Cloudron, Ant Media, Apache, Nginx,  OpenVPN, cPanel, WHMCS, WordPress, and more
  • Everything you need on AWS, IBM Cloud, GCP, Azure, Oracle Cloud, Alibaba Cloud, Linode, Contabo, DigitalOcean, Ionos, Vultr, GoDaddy, HostGator, Namecheap, DreamHost, and more.
 

We will design, configure, deploy, or troubleshoot anything you want. Starting from $10, we will get your job done in the shortest time possible. Your payment is safe with Fiverr as we will only be paid once your project is completed.