by Howard Fosdick, fully rewritten in 2025 © RexxInfo.org
Do you store image, audio, and video files on your computer? You can probably reclaim tons of disk space by converting that data in more space-efficient file formats.
For example, I reduced 500 megabytes of image files down to 120 megabytes with a single command.
You could get similar savings, depending on what kinds of media files you store, their formats, and how you use them.
This article shows you how. It introduces Linux commands that make it simple to quickly convert image, audio, and video files to free up disk space.
We focus on the most useful space-saving conversions. We use line commands because they give you complete control over format conversion and compression.
Plus, you can use them in scripts for mass conversions of hundreds or even thousands of files at one go.
Or, you can just copy the commands from this article and paste them into a command line window.
While this article covers line commands, be aware that there are other ways to compress and convert files. For example, if you don't mind the loss of privacy, you could send your files through websites that offer conversion capabilities. You could even convert file formats using the save as and export functions of many common applications.
Before you do anything else, identify and then delete any big unwanted files you have on your computer. Deleting just a handful of space hogs can yield huge benefits.
This command string lists the subdirectories under the current directory that use the most disk space. Run it by copying and pasting it into a line command window:
$ du -a . | sort -n -r | head -n 50
This command string identifies the 50 biggest files in the directory in which you run it, and all its subdirectories. It lists the biggest files sorted by size:
$ find -type f -exec du -Sh {} + | sort -rh | head -n 50
Run this command in your HOME directory to see what your biggest files are.
You'll immediately see when you have large files stored in more than one location. Delete the duplicates to reclaim some significant space.
The output also helps you identify any big files you no longer need. Delete them!
Media files hold images, audio, and video. They use dozens of different file formats. There's often a trade-off between their data quality versus the storage space they consume.
Some file formats are lossless: They preserve all the originally captured data. Lossless file formats can either be compressed or uncompressed. They vary in size by this and other factors.
Other file formats are lossy. They save storage space by cleverly eliminating some of the least useful data. They're ideal if your use of the data is such that you can tolerate some minor data loss. Lossy files consume less storage space and stream faster across the web.
For example, capturing a digital image in a lossless format like PNG, BMP, GIF, RAW, or TIFF creates a big file. Converting that image to a lossy alternative like JPG, or lossy WEBP or AVIF formats saves lots of space.
Is it worth it? That depends on your intended use of the image.
If you're a professional photographer who prints a photograph in a high-quality book, you probably want to keep your original lossless file. You likely require the highest quality image for your artwork. Your lossless file also means you can perform extensive image editing without losing quality.
If you're a website developer, you might make the opposite choice. Smaller lossy JPG, WEBP, or AVIF files download to users' computers much faster than lossless images, making your webpages load more quickly. This conversion works because few users can tell whether the image they view on their computer or cellphone screen is lossless or lossy.
Keep in mind that after you convert from a lossless format to a lossy one, you've removed some data. You can't convert back to regain that data (although new AI tools can sometimes help).
If you do convert back to the original format, you do so without the data you've already sacrificed. Only delete the original file once you're satisfied that the converted file meets all your needs.
Sometimes a good strategy is to retain the original big file by placing it into inexpensive backup storage. For example, you may not need lossless WAV audio files on your working computer every day, but you might be happy to access them later from your backup media.
Several popular lossless file formats present great opportunities for saving space, including PNG, BMP, GIF, RAW, and TIFF.
One possible conversion target for images is the lossy JPG format. With its quality settings, JPG allows you to specify a smaller file size with greater data loss or a larger file size with less loss. It might give you a compression ratio of up to 10:1 over some lossless formats.
Yet if you display a JPG image on a computer or phone screen, the eye can rarely tell that conversion and compression have occurred.
WEBP and AVIF files look just as good on screens as JPG files, but they save even more space. That's why they're becoming more popular than JPG, and are supported by all up-to-date browsers and apps. (WEBP and AVIF also support lossless compression, but you most often encounter them in their lossy versions on the internet.)
I converted most of my PNG and JPG files to WEBP format and reclaimed loads of storage space. On one disk, 500 megabytes of PNG files melted down to about 120 meg of WEBP. If you're certain that your images are only ever going to be displayed on a screen, converting to WEBP offers clear benefits.
The open source ImageMagick utility gives you Linux terminal commands to convert images. It's available in nearly all Linux repositories.
You may need to install it first:
$ sudo apt install imagemagick
ImageMagick line commands help you reduce image file sizes through three techniques:
Here's the syntax of the ImageMagick convert command that performs file format conversions:
convert [input options] input_file [output options] output_file
These examples show how to run the command. You can see that potential space savings are huge:
$ convert image.bmp new_image.jpg # 7.4 MB down to 1.1 MB $ convert image.tiff new_image.jpg # 7.4 MB down to 1.1 MB $ convert image.png new_image.webp # 4.8 MB down to 515 KB $ convert image.png new_mage.webp # 1.5 MB down to 560 KB $ convert image.jpg new_image.webp # 769 KB down to 512 KB $ convert image.gif new_image.jpg # 13.2 MB down to 10.9 MB $ convert image.gif new_image.webp # 13.2 MB down to 4.1 MB
You can convert RAW images, too. When converting a RAW image, its filename must not have an extension for the convert command to process it correctly:
$ convert image new_image.png # 67.1 MB down to 45.3 MB
You can gain some major space savings by converting images -- but only if the output is acceptable for your use case.
This next example saves space by resizing a JPG image to as near as 800x600 as possible while still retaining the proper aspect ratio. It converts a 285 KB input file at 1277x824 pixels to a 51 KB output file at 800x600 pixels. That's close to a 6 to 1 ratio in space savings:
$ convert image.jpg -resize 800x600 new_image.jpg
The convert command can change images however you like.
For example, you can specify the trade-off between image quality and size. But you'll have to wade through convert's many options to understand all its capabilities. I mainly use it just to convert images between lossless and lossy file formats, which is very simple.
For more information on convert, visit the ImageMagick website.
Like image files, audio files come in lossless uncompressed, lossless compressed, and lossy formats.
The trade-off between lossless and lossy is one of data quality versus saving space.
If you require the highest quality audio, stick with lossless files. That might be the case if you edit digitized music, for example.
If you want listenable music that consumes far less space, most of the world has decided that lossy formats like MP3 and M4A are the best choice. These smaller files download far faster when streaming from the web.
Here are the most popular audio formats. Note that file extensions often refer to containers that can support more than one audio encoding format and that most technologies claim more than a single file extension. These are the most common scenarios you'll see:
If your goal is to save disk space, try converting from a lossless format to a lossy one. Don’t convert from one lossy format to another. That will likely degrade the sound quality too much.
A very flexible Linux terminal command to convert audio files is ffmpeg. To install it:
$ sudo apt install ffmpeg
Like the ImageMagick convert command, ffmpeg supports a staggering range of file formats and codecs. View them all by entering:
$ ffmpeg -encoders
Using ffmpeg is straightforward for our purposes. Here's the standard syntax. The -i flag identifies the input file, and the -vn flag tells ffmpeg not to invoke any video-related code that might alter the audio output:
$ ffmpeg -i audiofile_input.ext -vn audiofile_output.new
These examples all convert lossless WAV files into lossy formats:
$ ffmpeg -i audio.wav -vn audio.ogg # 38.3 MB to 3.3 MB $ ffmpeg -i audio.wav -vn audio.mp3 # 38.3 MB to 3.5 MB $ ffmpeg -i audio.wav -vn audio.m4a # 38.3 MB to 3.6 MB $ ffmpeg -i audio.wav -vn audio.webm # 38.3 MB to 2.9 MB
You can use the same commands to convert AIFF files (just replace .wav with .aiff or .aif in the command).
These commands reduced the size of the lossless input files by a factor of 10. That's huge! The big question is: Do the outputs sound different from the originals?
To most people listening on most consumer devices, the difference is negligible. That's why MP3, M4A, and other lossy compressed formats are so popular, especially for streaming.
Even though they're not technically the best, the audio is quite listenable, and they consume a fraction of storage space and bandwidth.
Video conversion presents another chance to save lots of space. Your goal should be to find the video format that best balances playback quality and file size to meet your needs.
A video format is the combination of a container file format and a codec. A codec is software that encodes and decodes a data stream as it moves to and from the container file.
Containers can be paired with multiple codecs. In practice, there are often only one or two or three popular codecs paired with a particular container.
For example, with audio files, WAV files can be encoded as either lossless or lossy. But lossless encoding so predominates in the format such that most people assume that any WAV file is lossless.
These are some of today's most widely used open source video formats:
The main factors that determine video file size and quality are:
The ffmpeg command can change all three parameters. Here's a simple conversion example:
$ ffmpeg -i input_video.mov output.webm
This conversion converted a 39 MB input down to 1.8 MB output.
Because I didn't specify any parameters, ffmpeg copies most of the existing attributes of the input file.
In this example, my input file was a MOV file containing MJPEG video with a resolution of 1280x720, a frame rate of 23.98, and a bitrate of 40,219 kilobytes per second (kbps). The resulting output file contains VP9 video with the same resolution and frame rate. However, the bitrate is only 1,893 kbps.
As with audio conversions, video compression offers the potential for enormous space savings. On my PC, most conversions viewed so much like the original that it was difficult to tell any difference. Converting saved lots of space for no discernable loss in the viewing experience.
Whether the output quality is acceptable to you depends on your intended use of the video, your viewing devices, and your expectations. Never erase your original file until you’ve reviewed the converted file and found it satisfactory.
Archiving takes multiple input files and collects them into a single output file. The input files may be of different file types.
Compression is optional. A compressed archive is useful for sending files across the internet and for long-term data storage. It's a great way to save space and reduce data transmission times.
The downside is that you're limited in how you can process archived files until you extract them out of the archive (though some tools are now pretty sophisticated in their manipulation of files within archives).
Among the many archive file formats, the most popular compressed formats include GZ, BZ2, XZ, ZIP, and 7Z.
The tar command handles many archive formats. It supports compression commands including gzip, bzip2, xz, and others.
The following command takes two different kinds of input files -- bigfile.xcf and bigfile.tiff -- and produces the output archive file named myarchive.tar.xz. It reduced 56 MB down to a 28 MB compressed archive.
$ tar --xz --create --file myarchive.tar.xz bigfile.xcf bigfile.tiff
How much compression occurs varies widely by the files involved. Files that are already in a compressed format will compress little or not at all.
To unarchive a TAR file, use the --extract option:
$ tar --extract --file myarchive.tar.xz
The tar command bundles many files into one (sometimes called a tarball).
You can alternatively compress a single file with commands like gzip, bzip2, xz, zip, or 7z.
This example uses the xz command to compress a single file named bigfile.xcf into the compressed output file named bigfile.xcf.xz:
$ xz bigfile.xcf $ ls bigfile.xcf.xz
To uncompress a compressed file, you can usually use an "un" version of the command you used to compress the file:
$ unxz bigfile.xcf.xz
Sometimes there's also a --decompress option:
$ xz --decompress bigfile.xcf.xz
In this series of commands, the xz and unxz commands compress, and then uncompress, all the files in a directory:
$ ls a.pdf b.pdf $ xz * $ ls a.pdf.xz b.pdf.xz $ unxz * $ ls a.pdf b.pdf $
Not all Linux distributions include all the commands we've described, so you may have to install some of them.
Sometimes you can convert many files with a single command, as shown in the above archiving examples.
Other times, you'll need to write a script to convert many files in one go. Here's how.
To convert all the files in a directory, simply embed your conversion command within a for loop.
Place double quotes around the filename variable to handle any filenames that contain embedded spaces. This script converts all PNG files in a directory to WEBP files:
#!/bin/bash for file_name in *.png ; do convert "$file_name" "$file_name".webp done
To process all the files in a directory and all its subdirectories, your script needs to traverse the directory structure.
My article How to Traverse Directories in Scripts shows an easy way to do this. The article includes example code you can easily plug any conversion command into.
Many people aren't aware that they're wasting gigabytes of disk space they could easily reclaim. All it takes is converting files to more space-efficient formats.
With the information in this article, you now know how to reclaim all that space.