# info > ctags

---
type: CommandReference
command: ctags
mode: man
section: 1
source: man-pages
---

## Quick Reference

- `ctags *` — generate tags for all recognized source files in current directory
- `ctags -R` — recursively generate tags from current directory
- `ctags -f tags file.c` — write tags to a specific file
- `ctags -x --c-kinds=f file.c` — print human-readable cross reference of functions
- `ctags -e -R` — generate Emacs-style TAGS file recursively
- `ctags -I ARGDECL4 file.c` — ignore macro `ARGDECL4` during parsing
- `ctags --exclude='*.test' -R` — exclude files matching pattern
- `ctags --language-force=python *.py` — force language for all files

## Name

`ctags` — Generate tag files for source code

## Synopsis

ctags [options] [file(s)]
etags [options] [file(s)]
## Options

### General Options

- `-a` — equivalent to `--append`
- `-B` — use backward searching patterns (`?pattern?`) [ignored in etags mode]
- `-e` — enable etags mode (Emacs tag file). Must appear before first file name.
- `-F` — use forward searching patterns (`/pattern/`) (default) [ignored in etags mode]
- `-f tagfile` — use specified tag file name (default `tags` or `TAGS` in etags mode). If `-`, write to stdout.
- `-h list` — specify include file extensions (default `.h.H.hh.hpp.hxx.h++.inc.def`). Use `+` prefix to append.
- `-I identifier-list` — list of identifiers to ignore or replace during C/C++ parsing. Use `@file` to read from file.
- `-L file` — read file names from file (`-` for stdin). Options also accepted.
- `-n` — equivalent to `--excmd=number`
- `-N` — equivalent to `--excmd=pattern`
- `-o tagfile` — equivalent to `-f`
- `-R` — equivalent to `--recurse`
- `-u` — equivalent to `--sort=no`
- `-V` — equivalent to `--verbose`
- `-w` — silently ignored (SVR4 compatibility)
- `-x` — print cross-reference to stdout instead of tag file. Must appear before first file name.
- `--append[=yes|no]` — append tags to existing tag file (default no). Must appear before first file name.
- `--etags-include=file` — include reference to another tag file (Emacs). Only in etags mode.
- `--exclude=pattern` — exclude files/directories matching pattern. May be repeated. Default excludes: `EIFGEN`, `SCCS`, `RCS`, `CVS`.
- `--excmd=type` — type of EX command: `number`, `pattern`, `mixed` (default). `mixed` uses line numbers for macro definitions and Fortran common blocks.
- `--extra=[+|-]flags` — include extra tag entries:
  - `f` — base file name entry
  - `q` — class-qualified tag entry
- `--fields=[+|-]flags` — extension fields to include:
  - `a` — access (export) of class members
  - `f` — file-restricted scoping (enabled)
  - `i` — inheritance
  - `k` — kind as single letter (enabled)
  - `K` — kind as full name
  - `l` — language of source file
  - `m` — implementation
  - `n` — line number
  - `s` — scope (enabled)
  - `S` — signature
  - `z` — include `kind:` key
  - `t` — type/name as `typeref:` field (enabled)
  Default: `fkst`.
- `--file-scope[=yes|no]` — include file-scoped tags (static) (default yes)
- `--filter[=yes|no]` — filter mode: read file names from stdin, output tags to stdout. Ignores `-f`, `-o`, `--totals`. Must appear before first file name.
- `--filter-terminator=string` — string printed after each file's tags in filter mode.
- `--format=level` — tag file format: `1` (original) or `2` (extended, default). Must appear before first file name. [Ignored in etags mode]
- `--help` — print usage and exit
- `--if0[=yes|no]` — examine code inside `#if 0` branches (default no)
- `--langdef=name` — define a new user-defined language
- `--langmap=map[,map...]` — map file extensions/patterns to languages. Use `+` to append, `default` to restore.
- `--language-force=language` — force language for all files (case-insensitive). Use `auto` to reset.
- `--languages=[+|-]list` — enable/disable languages. Default `all`.
- `--license` — print license summary and exit
- `--line-directives[=yes|no]` — recognize `#line` directives (default no)
- `--links[=yes|no]` — follow symbolic links (default yes)
- `--list-kinds[=language|all]` — list tag kinds for language(s) and exit
- `--list-maps[=language|all]` — list file name mappings for language(s) and exit
- `--list-languages` — list supported languages and exit
- `--options=file` — read additional options from file. `--options=NONE` as first option disables automatic configuration.
- `--recurse[=yes|no]` — recurse into directories (default no). If no files given, current directory assumed.
- `--regex-<LANG>=/regexp/replacement/[kind-spec/][flags]` — define regex-based tag generation for language. Options: `b` (basic regex), `e` (extended, default), `i` (case-insensitive).
- `--sort[=yes|no|foldcase]` — sort tag file by name (default yes). `foldcase` for case-insensitive sorting.
- `--tag-relative[=yes|no]` — file paths relative to tag file directory (default yes in etags mode, no otherwise)
- `--totals[=yes|no]` — print statistics (default no). Must appear before first file name.
- `--verbose[=yes|no]` — verbose mode (default no). If first argument, takes effect before config files.
- `--version` — print version identifier and exit

## Examples

- Generate tags for all C files in current directory:
  ```shell
  ctags *.c
  
- Recursively generate tags for all source files under current directory:
  ```shell
  ctags -R
  
- Generate cross-reference listing of functions in a file:
  ```shell
  ctags -x --c-kinds=f file.c
  
- Create Emacs TAGS file recursively:
  ```shell
  ctags -e -R
  
- Handle macro `ARGDECL4` that would otherwise be mistaken for a function name:
  ```shell
  ctags -I ARGDECL4 file.c
  
- Ignore macro invocation `MODULE_VERSION` and its arguments:
  ```shell
  ctags -I MODULE_VERSION+ file.c
  
- Replace macro `CLASS` with `class` for correct parsing:
  ```shell
  ctags -I CLASS=class file.c
  
- Exclude directories `test` and `build` during recursion:
  ```shell
  ctags -R --exclude=test --exclude=build
  
- Use line numbers only in tag file (reduces size, but sensitive to line changes):
  ```shell
  ctags -n file.c
  
- Jump to a tag in vi:
  ```shell
  vi -t tag_name
  
- In Emacs, after loading the tag file (`M-x visit-tags-table`), use `M-.` to find a tag.

## See Also

- Official Exuberant Ctags website: <http://ctags.sourceforge.net>
- [ex(1)](http://localhost/phpMan.php/man/ex/1/markdown)
- [vi(1)](http://localhost/phpMan.php/man/vi/1/markdown)
- [vim](http://www.vim.org/)