ctags command in Linux with examples

ctags command in Linux system is used for the with the classic editors. It allows quick access across the files (For example quickly seeing definition of a function). A user can run tags or ctags inside a directory to create a simple index of the source files while working on. Tags-capable editors like vi/vim can then refer to these tags index file to allow you to follow references. Basically, this command generates the tag files for source code. It is also used to create a cross reference file which lists and contain the information about the various source objects found in a set of human-readable language files.

Syntax:

ctags [options] [file(s)]

Options:

  • –help: It will print the general syntax of the command along with the various options that can be used with the ctags command as well as gives a brief description about each option.

  • ctags -a: This option used to append the tags to an existing tag file. Equivalent to –append. [Ignored with -e]
  • ctags -B: This option used for backward searching patterns (e.g. ?regexp?). [Ignored with -e]
  • ctags -e: This option used for output a tag file for use with Emacs. If this program is being executed by the name etags, this option is already enabled by default.
  • ctags -F: This option used for searching patterns (e.g. /regexp/)(default). [Ignored with -e]
  • ctags -i: This option is similar to the –c-types option and is retained for all the compatibility with earlier versions.
  • ctags -n: This option is Equivalent to –excmd=number.
  • ctags -N: This option is Equivalent to –excmd=pattern.
  • ctags -o: This option is Equivalent to -f tagfile.
  • ctags -p: This option is Used path as the default directory for each supplied source file, unless the source file is already specified as an absolute path.
  • ctags -R: This option is Equivalent to –recurse=yes.
  • ctags -u: This option is Equivalent to –sort=no (i.e. “unsorted”).
  • ctags -V: This option Enables the verbose mode. This prints out a brief message describing that what action is being taken for each of the file considered by ctags.

ctags with Vim: