How to check if a specific font is installed in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to check if a specific font is installed on your Linux system. We will explore three key methods to achieve this.

First, you will use the fc-list command to list all fonts known to the Fontconfig system. Next, you will examine the standard system font directory /usr/share/fonts using the ls command to see the font files stored there. Finally, you will learn how to verify and update the font cache using fc-cache -v, which is crucial for ensuring that newly installed fonts are recognized by the system. By completing these steps, you will gain practical skills in managing and verifying font installations in a Linux environment.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/BasicSystemCommandsGroup(["Basic System Commands"]) linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux/BasicSystemCommandsGroup -.-> linux/echo("Text Display") linux/BasicFileOperationsGroup -.-> linux/ls("Content Listing") subgraph Lab Skills linux/echo -.-> lab-558756{{"How to check if a specific font is installed in Linux"}} linux/ls -.-> lab-558756{{"How to check if a specific font is installed in Linux"}} end

List fonts with fc-list

In this step, you will learn how to list the fonts available on your Linux system using the fc-list command. Fonts are essential for displaying text on your screen, and knowing how to list them can be useful for various tasks, such as troubleshooting display issues or selecting specific fonts for applications.

The fc-list command is part of the Fontconfig library, which is a system for configuring and customizing font access.

To list all available fonts, open your terminal and type the following command:

fc-list

Press Enter.

You will see a long list of output, similar to this:

/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf: Liberation Sans,Sans:style=Regular
/usr/share/fonts/truetype/dejavu/DejaVuSansMono-BoldOblique.ttf: DejaVu Sans Mono:style=Bold Oblique
/usr/share/fonts/truetype/ubuntu/Ubuntu-R.ttf: Ubuntu:style=Regular
... (many more lines)

Each line in the output represents a font file and provides information about the font, such as its name and style. The output format is generally filename: family,family,...:style=style,....

This command lists all fonts that Fontconfig knows about, which includes fonts installed system-wide and potentially user-specific fonts.

Don't worry if the output is overwhelming. For now, the goal is just to see that the command works and understand that it provides a list of available fonts.

Check font directory with ls /usr/share/fonts

In the previous step, you used fc-list to see all the fonts Fontconfig knows about. Now, let's look at one of the common directories where system-wide fonts are stored: /usr/share/fonts.

The /usr/share/fonts directory is a standard location on many Linux distributions for installing fonts that are available to all users on the system. Inside this directory, you'll often find subdirectories organized by font type (like truetype, opentype) or by font family.

We will use the ls command to list the contents of this directory. The ls command is used to list files and directories.

Open your terminal and type the following command:

ls /usr/share/fonts

Press Enter.

You will see a list of directories and files within /usr/share/fonts, similar to this:

X11  cmap  encodings  opentype  truetype  type1

This output shows the subdirectories within /usr/share/fonts. These subdirectories contain the actual font files (.ttf, .otf, etc.).

You can explore further by listing the contents of one of these subdirectories, for example, the truetype directory:

ls /usr/share/fonts/truetype

Press Enter.

You might see output like this:

dejavu  liberation  ubuntu  wqy

This shows the font families installed within the truetype format directory. You can continue navigating deeper into these directories to see the individual font files.

Understanding where fonts are stored helps you manage them and understand how the system accesses them.

Verify font cache with fc-cache -v

In the previous steps, you listed fonts using fc-list and explored font directories with ls. Fontconfig uses a cache to quickly access information about the installed fonts. When you add or remove fonts, you often need to update this cache so that applications can find the new or removed fonts.

The fc-cache command is used to build and maintain the font information cache files. Running fc-cache without any options will update the cache for the standard font directories.

To see the process of updating the cache and verify which directories are being scanned, you can use the -v option for verbose output.

Open your terminal and type the following command:

fc-cache -v

Press Enter.

You will see output indicating which directories are being scanned and where the cache files are being written. The output will look similar to this:

/usr/share/fonts: caching, new cache contents: 100 fonts, 100 dirs
/usr/share/fonts/X11: caching, new cache contents: 0 fonts, 0 dirs
/usr/share/fonts/X11/Type1: caching, new cache contents: 0 fonts, 0 dirs
... (many more lines)
/var/cache/fontconfig: cleaning cache directory
/home/labex/.cache/fontconfig: cleaning cache directory
fc-cache: succeeded

The -v option shows you the directories being processed and provides details about the caching process. This is helpful for confirming that Fontconfig is looking in the correct places for fonts.

Running fc-cache -v is a good way to ensure that your system's font cache is up-to-date after making changes to your font collection.

Summary

In this lab, you learned how to check for installed fonts on a Linux system. You began by using the fc-list command to display all fonts known to the Fontconfig library, which provides a comprehensive list of available fonts and their details.

Following this, you explored the /usr/share/fonts directory using the ls command to examine a standard location where system-wide fonts are stored, understanding how fonts are organized within the file system. Finally, you verified the font cache using fc-cache -v, ensuring that Fontconfig's internal list of fonts is up-to-date and reflecting the fonts present in the system's font directories.