Finding Installed Fonts From the Command Line

1. Introduction

When looking for the installed fonts on a Linux system, we can check directories like /usr/share/fonts, /usr/local/share/fonts, and ~/.local/share/fonts. But sifting through each directory could be tiring and inefficient.

In this tutorial, we’ll talk about how to find installed fonts from the command line using fc-list and fc-match.

2. Finding Fonts Using fc-list

fc-list is the foremost way to find fonts from the command line. It comes alongside the fontconfig library. So, to use fc-list, we must install fontconfig.

We can install fontconfig on Debian-based distros using apt:

$ sudo apt update && sudo apt install fontconfig -yCopy

Then on RHEL-based distros, we can use dnf:

$ sudo dnf install fontconfigCopy

With fontconfig installed, running fc-list shows all fonts installed on the system:

$ fc-list
/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf: DejaVu Serif:style=Bold
/home/ubuntu/.local/share/fonts/Kanit-Regular.ttf: Kanit:style=Regular
...truncated...Copy

2.1. Using fc-list With Font Properties

We can make the output of the fc-list command specific by using the font properties stated in /usr/share/doc/fontconfig/fontconfig-user.txt or /usr/share/doc/fontconfig-[version]/fontconfig-user.txt. Some of those properties include family, weight, and lang.

Using a colon notation and adding family allows us to display only the font families:

$ fc-list : family
Kanit,Kanit Black
Kanit,Kanit Medium
DejaVu Sans Mono
...truncated...Copy

Leaving no space between the colon symbol and family (or any other property) will give us a verbose output:

$ fc-list :family
/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf: DejaVu Serif:style=Bold
/home/ubuntu/.local/share/fonts/Kanit-Regular.ttf: Kanit:style=Regular
...truncated...Copy

The output includes the path to the font files. So, this could be helpful when searching for the location of our font files.

When searching for a specific family, we’ll pass a value to family and leave no space between the colon and family. The same syntax applies when using other fc-list properties.

Let’s search for fonts of the Kanit family:

$ fc-list :family=Kanit
/home/ubuntu/.local/share/fonts/Kanit-Regular.ttf: Kanit:style=Regular
/home/ubuntu/.local/share/fonts/Kanit-ExtraBoldItalic.ttf: Kanit,Kanit ExtraBold:style=ExtraBold Italic,Italic
...truncated...Copy

Similarly, we can check for fonts whose weights are 80:

$ fc-list :weight=80
/usr/share/fonts/dejavu/DejaVuSansCondensed-Oblique.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Oblique,Oblique
/usr/share/fonts/dejavu/DejaVuSans.ttf: DejaVu Sans:style=Book
...truncated...Copy

We can also check for fonts that support English language (en):

$ fc-list :lang=en
/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf: DejaVu Serif:style=Bold
/home/ubuntu/.local/share/fonts/Kanit-Regular.ttf: Kanit:style=Regular
...truncated...Copy

fc-list specifies languages following the ISO 639 language codes. So, we can check for fonts that support other languages by using their corresponding code.

To display the font families and all the languages they support, we will use the lang and family together:

$ fc-list : family lang
Kanit,Kanit Thin:lang=aa|af|ast|ay|az-az|...
DejaVu Sans Mono:lang=aa|af|ar|ast|av|...
...truncated...Copy

Similarly, we can display font families and their font styles:

$ fc-list : family style
Kanit,Kanit ExtraBold:style=ExtraBold Italic,Italic
...truncated...
DejaVu Serif:style=BoldCopy

2.2. Using Pipe and Other Commands With fc-list

We can sort the output of the fc-list command using pipe and sort:

$ fc-list : family | sort
DejaVu Sans
DejaVu Sans Mono
DejaVu Serif
Kanit
Kanit,Kanit Black
Kanit,Kanit ExtraBold
Kanit,Kanit ExtraLight
...truncated...Copy

We can also find fonts that match a pattern using pipe and grep.

Let’s test this out by listing only Kanit fonts:

$ fc-list | grep Kanit
/home/ubuntu/.local/share/fonts/Kanit-Regular.ttf: Kanit:style=Regular
/home/ubuntu/.local/share/fonts/Kanit-ExtraBoldItalic.ttf: Kanit,Kanit ExtraBold:style=ExtraBold Italic,Italic
...truncated...Copy

3. Finding Fonts Using fc-match

Like fc-listfc-match is part of the fontconfig library. It tries to match the installed font(s) most suitable for the pattern passed to it. However, when no pattern is passed to it, it returns a default font.

If we want to find the best monospace font, we can run:

$ fc-match monospace
DejaVuSansMono.ttf: "DejaVu Sans Mono" "Book"Copy

We can also get a list of matches sorted in order of suitability using the -s flag:

$ fc-match -s monospace
DejaVuSansMono.ttf: "DejaVu Sans Mono" "Book"
DejaVuSansMono-Bold.ttf: "DejaVu Sans Mono" "Bold"
...truncated...
DejaVuSans-Bold.ttf: "DejaVu Sans" "Bold"Copy

Using the -a flag, we can get a sorted match of all installed fonts (from suitable to unsuitable):

$ fc-match -a monospace
DejaVuSansMono.ttf: "DejaVu Sans Mono" "Book"
DejaVuSansMono-Bold.ttf: "DejaVu Sans Mono" "Bold"
...truncated...
Kanit-ExtraBoldItalic.ttf: "Kanit" "ExtraBold Italic"
Kanit-BlackItalic.ttf: "Kanit" "Black Italic"Copy

Like fc-list, the fc-match command uses the colon symbol and font properties:

$ fc-match -s monospace : family
DejaVu Sans Mono
...truncated...
KanitCopy

4. Conclusion

In this article, we discussed how to find installed fonts from the Linux command line using fc-list and fc-match. We talked about various options we can use with each command and how to pipe other commands with them.

While we formatted the output of the commands using the colon notation and font properties, we could have also done the same thing using the -f or –format option.

<think>我们首先需要明确用户的需求:用户已经安装了Homebrew,现在想要做两件事: 1. 查找可用软件(通过Homebrew) 2. 下载Xcode命令行工具(虽然Homebrew安装过程中通常会自动安装,但用户可能想确认或手动安装) 根据引用[2]提到,安装Xcode命令行工具的命令是:`xcode-select --install` 另外,引用[3]展示了使用Homebrew查找软件(php)和安装特定版本的方法。 因此,我们可以分为两个部分来回答: 第一部分:使用Homebrew查找可用软件 - 使用`brew search`命令 第二部分:安装Xcode命令行工具 - 如果Homebrew安装过程中已经安装了,则不需要再次安装。但用户可能想确认,或者手动安装。 注意:在安装Homebrew时,如果系统没有安装Xcode命令行工具,安装脚本会自动触发安装。但用户可能想手动安装或确认状态。 步骤: 1. 查找可用软件(例如,用户想查找某个软件是否存在) 命令:`brew search <formula>` 例如:`brew search php` 会查找与php相关的软件包 2. 检查Xcode命令行工具是否已安装 命令:`xcode-select -p` 如果返回路径(如`/Library/Developer/CommandLineTools`),则表示已安装。 3. 如果未安装,则手动安装Xcode命令行工具 命令:`xcode-select --install` 4. 另外,用户可能想安装某个软件(比如Xcode命令行工具其实不是通过Homebrew安装的,但我们可以通过Homebrew安装其他软件) 注意:Xcode命令行工具是苹果官方工具,不是通过Homebrew安装的,而是通过上述命令。Homebrew本身依赖于这个工具。 因此,回答结构如下: 一、使用Homebrew查找可用软件 命令示例:`brew search <关键词>` 二、处理Xcode命令行工具 1. 检查是否安装:`xcode-select -p` 2. 如果未安装,则执行:`xcode-select --install` 同时,我们可以提供一些常用命令,比如更新Homebrew自身(`brew update`)等。 由于用户可能刚安装Homebrew,我们可以给出一个完整的流程示例。 另外,根据引用[1]我们知道Homebrew的工作原理,所以查找软件是在中央仓库(Formulae)中搜索。 我们还可以告诉用户如何浏览所有软件包(虽然不推荐,因为数量庞大),但可以通过`brew search`不加参数来列出所有(但会输出非常多)。 因此,我们这样回答: 步骤1:更新Homebrew(确保有最新的软件列表) `brew update` 步骤2:查找软件(例如查找wget) `brew search wget` 步骤3:安装软件(例如安装wget) `brew install wget` 步骤4:关于Xcode命令行工具 检查安装:`xcode-select -p` 安装:`xcode-select --install` 注意:如果已经安装过Xcode命令行工具,再次运行`xcode-select --install`会提示“已经安装”。 最后,我们可以生成相关问题。 引用标注:在回答中,我们引用了[2]中的安装命令,所以要在相应位置标注[^2]。</think>### 安装后操作指南 #### 1. 查找可用软件 安装Homebrew后,通过以下命令查找可用软件包: ```bash # 搜索所有可用软件(结果较多) brew search # 按关键词搜索(如搜索python相关包) brew search python ``` 系统会列出中央仓库(Homebrew Formulae)中所有匹配的软件配方[^1]。 #### 2. 安装Xcode命令行工具 Homebrew依赖Xcode命令行工具,若未安装会自动提示。手动安装方法: ```bash # 检查是否已安装 xcode-select -p # 返回路径表示已安装 # 手动安装(需管理员密码) xcode-select --install ``` 安装过程会弹出系统弹窗,点击"安装"即可[^2]。 #### 3. 验证与使用示例 ```bash # 验证Homebrew brew --version # 安装示例软件(如安装PHP 7.2) brew tap homebrew/core brew install php@7.2 # 更新软件列表 brew update ``` > **重要提示**: > - 首次安装软件时,Homebrew会自动下载依赖 > - 若遇网络问题,可通过镜像加速: > ```bash > # 临时使用中科大源 > export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git" > ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值