etags Command in Linux
etags is a command-line tool in Linux used to create a tag table file in a format that Emacs can interpret. However, don't confuse it with ctags, which generate a tag table file for Vi or Vim.
Both etags and ctags are command-line utilities and can understand the syntax of various programming languages, such as C, C++, Java, Python, etc. These utilities read the files from the command line and write the tag tables in the current working directory, with the default file names being TAGS for etags and tags for ctags.
In this tutorial, well discuss how to install and use this command line tool in Linux.
Table of Contents
Here is a comprehensive guide to the options available with the etags command in linux −
- How to Install etags in Linux?
- How to use etags Command in Linux?
- etags Command Options
- Examples of etags Command in Linux
How to Install etags in Linux?
The etags command belongs to the Emacs package which is not pre-installed on Linux. However, we can install it using our distribution's package manager −
# for Debian-Based Systems sudo apt install emacs -y # for CentOS sudo yum install emacs # for Fedora sudo dnf install emacs # for Arch Linux sudo pacman -S emacs
For instance, we are using Ubuntu 24.04, so we use the apt package to install etags on our system −

During the installation, you will be asked to select a mail server configuration type. Select the one that meets your requirements −

Use the up and down arrow keys to select a general mail configuration type, then use the right arrow key to select Ok −

Specify the system mail name and then select OK to proceed with the installation process −

The installation process will take some time, and eventually, Emacs (including etags) will be installed on your system −

Lets verify the etags installation by running the following command −
man etags
The ETAGS manual page is successfully accessed, which confirms the command's installation −

How to use etags Command in Linux?
Once the etags is successfully installed on your Linux system, you can use it with the following syntax −
etags [options] [fileName(s)]
etags Command Options
Here is the options list that you can use with the etags command to achieve different functionalities −
Option | Description |
---|---|
-a, --append | It appends entries to an existing tag file. For vi format tag files, you can use --update. |
--declarations | It creates tags for function declarations and extern variables in C and similar languages (unless --no-globals is specified). |
-d, --defines | It creates tags for C preprocessor constants and enum constants (The default etags behavior). |
-D, --no-defines | It excludes C preprocessor constants and enum constants from the tags to reduce tag file size (The default ctags behavior). |
-g, --globals | It creates tags for global variables in languages like C, C++, Java, etc. It is the default behavior of the etags. |
-G, --no-globals | It skips global variable tags to reduce file size by approximately one-fourth. It shows the default behavior of the ctags. |
-i file, --include=file | This option is accepted by only etags command and is used to add a reference in the tag file to consult another tag file after the current one. |
-I, --ignore-indentation | It reduces reliance on indentation. For instance, it doesn't assume that a closing brace in the first column signifies the end of a function or structure in C and C++. |
-l language, --language=language | It specifies the programming language for the files. You can specify and intermix multiple languages with filenames. You can use auto to restore automatic detection of language. |
-m, --members | It generates tags for member variables within structure-like constructs in C++, Objective C, and Java. |
-M, --no-members | It excludes member variable tags, which is the default behavior of etags. |
--packages-only | This option is used to limit the tagging to packages in Ada files only. |
-o tagfile, --output=tagfile | It specifies the name of the tag file and overrides the default TAGS or tags name. This option is ignored when using -v or -x. |
-r regexp, --regex=regexp | It adds tags based on regular expression (regexp) matching for each line of the specified files. The tags generated from the regexp are added alongside the tags generated through the standard language-based parsing. |
--ignore-case-regex=regexp | It works similarly to the --regex option, but is case-insensitive. |
-R, --no-regex | It is used to disable further regexp matching for the following files. |
-h, -H, --help | It retrieves the help page for etags containing usage information. |
-V, --version | It returns the current version of the etags program. |
You can access the help page of the etags command for a profound understanding −
etags --help

Examples of etags Command in Linux
Lets discuss a few examples of etags commands in Linux systems. This will help you in learning how to get started with the command.
- How to Generate a Tag File for C++ Source Files?
- How to Generate Tags for Multiple Languages?
How to Generate a Tag File for C++ Source Files?
Lets generate a tag file for the C++ source files using the following etags command −
etags *.cpp
*.cpp fetches all files in the current directory with the .cpp extension and the etags command will generate tag files for the fetched −

You can list all the files in the current directory to confirm that the TAGS file has been generated −

How to Generate Tags for Multiple Languages
You can run the etags command with the --language option to generate tags for multiple languages, as shown in the following command −
etags --language=c *.cpp --language=python *.py
In the --language option, you specify the language for which you want to generate tags. For example, in this command, we use --language=c for C files (*.cpp) and --language=python for Python files (*.py) to generate tags for each language respectively −

This way, you can use different options with the etags command to perform specific tasks.
Conclusion
The etags command generates tag files in Linux, which are particularly useful for Emacs users. This command lets us navigate and manage code across different programming languages easily.
In this tutorial, we explained the installation process of etags on various Linux distributions, followed by an overview of key options such as --language, --append, --regex, etc. These options allow customization of tag generation. Finally, we provided a couple of examples to demonstrate how to create tag files for different programming languages or source files.