Convert File Formats Linux: Tools & Commands
Converting file formats on Linux is done with command-line tools like ffmpeg for media, pandoc for documents, and ImageMagick for images, or with GUI apps like HandBrake and LibreOffice. You pick the tool based on the source and target formats, then run a simple command that specifies the input file and the desired output extension. This guide covers the most common conversion tasks, the exact commands to use, and how to avoid the pitfalls that trip up new users.
Why Linux Uses Separate Tools for Each Format
Unlike Windows or macOS, where a single program often handles many conversions, Linux follows the Unix philosophy: each tool does one thing well. This means there is no universal “convert everything� utility. Instead, you use specialized programs that are optimized for their format family. The advantage is that each converter is powerful and scriptable, but the learning curve is steeper because you must remember which tool handles which format.
The most frequently used converters are:
- ImageMagick (
convertormagick) – for images (PNG, JPEG, WebP, TIFF, etc.) - ffmpeg – for audio and video (MP4, MKV, MP3, WAV, etc.)
- pandoc – for documents (Markdown, HTML, DOCX, PDF, LaTeX, etc.)
- LibreOffice – for office suites (ODT, DOCX, XLSX, PPTX) and PDF
- epub-convert (from Calibre) – for e-books (EPUB, MOBI, AZW3, PDF)
How to Convert Images with ImageMagick
ImageMagick is the Swiss Army knife for image conversion. To convert a PNG to JPEG, open a terminal and run:
convert image.png image.jpg
The output format is determined by the file extension. You can also set quality, resize, or convert multiple files at once. For a batch of PNG files to WebP:
for file in *.png; do convert "$file" "${file%.png}.webp"; done
If you have ImageMagick 7, use magick instead of convert. To check your version: convert --version.
Converting Audio and Video with ffmpeg
ffmpeg is the most powerful media converter. It handles virtually any audio or video format. To convert an MP4 video to an AVI:
ffmpeg -i input.mp4 output.avi
For audio, converting MP3 to WAV:
ffmpeg -i input.mp3 output.wav
You can also extract audio from video:
ffmpeg -i video.mp4 -vn audio.mp3
ffmpeg is extremely flexible; you can set bitrate, codec, and even resize video. However, it does not convert DRM-protected files, and some formats require proprietary codecs that must be installed separately.
Document Conversion with Pandoc and LibreOffice
Pandoc is a command-line tool that converts between dozens of markup formats. For example, to convert a Markdown file to HTML:
pandoc input.md -o output.html
To convert to DOCX:
pandoc input.md -o output.docx
Pandoc does not handle PDF directly; you need a LaTeX engine or use --pdf-engine=wkhtmltopdf (which requires an extra package). For office documents like DOCX to PDF, LibreOffice is more reliable. Run:
libreoffice --headless --convert-to pdf document.docx
This works for ODT, DOCX, XLSX, PPTX, and more. The command creates a PDF with the same base name in the current directory.
How to Choose the Right Converter
Choosing the right tool depends on the file types you are working with:
- Images: ImageMagick or GraphicsMagick (a lighter alternative). For simple format changes, both work.
- Audio/Video: ffmpeg is the only serious choice. HandBrake is a GUI alternative for video.
- Documents: Pandoc for markup-to-markup (Markdown, HTML, LaTeX, reStructuredText). LibreOffice for office formats and PDF.
- E-books: Calibre’s
ebook-converttool handles EPUB, MOBI, AZW3, and PDF. - Archives:
tar,zip,7z– but these are not really “conversions,� they are compression.
If you are unsure about a format, use file command to identify it:
file mysteryfile
That tells you the actual format, which helps you pick the right converter.
Common Problems and How to Fix Them
New users often hit the same issues:
- “Command not found� – The tool is not installed. Install it with your package manager:
sudo apt install imagemagick,sudo apt install ffmpeg, etc. - “No such file or directory� – You are not in the right folder. Use
cdto navigate to the directory containing the file, or provide the full path. - “Permission denied� – The output file location is not writable. Use a folder you own, like your home directory, or add
sudo(but be careful with sudo – it can overwrite system files). - Wrong output quality – For images, set quality with
-quality 90. For audio, use-b:a 192kto set bitrate. - Unsupported codec – ffmpeg may need extra packages like
libx264. Install them via your package manager.
Batch Conversion and Automation
One of Linux’s strengths is scripting. You can convert hundreds of files with a simple loop. For example, converting all JPGs to PNG:
for file in *.jpg; do convert "$file" "${file%.jpg}.png"; done
For video, you can use a similar loop with ffmpeg. You can also use find to process files in subdirectories:
find . -name "*.mp3" -exec ffmpeg -i {} {}.wav \;
This converts every MP3 in the current directory tree to WAV. Always test on a single file first to avoid wasting time on a broken command.
Safety and Accuracy Tips
Converting files is generally safe, but there are a few things to keep in mind:
- Back up original files – If the conversion fails, you could lose data. Copy files to a temp folder first.
- Check output with
file– After conversion, runfile output.jpgto confirm it is actually the format you wanted. - Be careful with overwriting – If you convert
image.jpgtoimage.jpg(same name), you will overwrite the original. Use a different output name. - Don’t convert DRM-protected files – Tools like ffmpeg will refuse or produce garbage. It is also legally questionable.
- Lossy vs lossless – Converting a lossy format (like MP3) to another lossy format (like AAC) degrades quality. Always keep the original lossless source (FLAC, WAV) if you plan to convert again.
Frequently Asked Questions
How do I convert a PDF to a Word document on Linux?
Use LibreOffice: libreoffice --headless --convert-to docx input.pdf. The result is not perfect – complex layouts may shift – but it works for most text-based PDFs. For scanned PDFs, you need OCR software like Tesseract first.
What is the fastest way to convert a video file?
ffmpeg with the -preset veryfast option speeds up encoding: ffmpeg -i input.mkv -preset veryfast output.mp4. The trade-off is a larger file size and slightly lower quality. For maximum speed, use -preset ultrafast, but the file will be much larger.
Can I convert files without installing anything?
Some online converters work in a browser, but they require uploading your files, which is a privacy risk. On a Linux system, you can also use Python with libraries like Pillow (for images) or pydub (for audio) if you have Python installed, but installing the dedicated tools is simpler.
Why does my converted image look blurry?
If you convert from a vector format (SVG) to a raster format (PNG), the default resolution may be low. Use -density 300 to increase the DPI: convert -density 300 input.svg output.png. Also, avoid converting a small image to a larger one – it will always be blurry.
Is there a GUI tool for converting files on Linux?
Yes. HandBrake is a popular GUI for video, and GIMP can export images in many formats. For documents, LibreOffice has a “Save As� dialog that lets you pick the target format. For batch conversions, converseen is a simple GUI for ImageMagick.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.