Home » Linux Command Reference » UNIX/LINUX Command – ctags

UNIX/LINUX Command – ctags


ctags—Generates tags and (optionally) refs files


ctags [-BSstvraT] filesnames…


ctags generates the tags and refs files from a group of C source files. The tags file is used by the elvis :tag command, control-] command, and -t option. The refs file is sometimes used by the ref(1) program.

Each C source file is scanned for #define statements and global function definitions. The name of the macro or function becomes the name of a tag. For each tag, a line is added to the tags file that contains the following:

  • The name of the tag
  • A tab character
  • The name of the file containing the tag
  • A tab character
  • A way to find the particular line within the file
  • The filenames list will typically be the names of all C source files in the current directory, like this:

$ ctags –stv *.[ch]


Options Description
-B Normally, ctags encloses regular expressions in slashes (/regexp/), which causes elvis to search from the top of the file. The -B flag causes ctags to enclose the regular expressions in question marks (?regexp?) so elvis will search backward from the bottom of the file. This rarely matters.
-t Include typedefs. A tag will be generated for each user-defined type. Also tags will be generated for struct and enum names. Types are considered to be global if they are defined in a header file, and static if they are defined in a C source file.
-v Include variable declarations. A tag will be generated for each variable, except for those that are declared inside the body of a function.
-s Include static tags. ctags will normally put global tags in the tags file, and silently ignore the static tags. This flag causes both global and static tags to be added. The name of a static tag is generated by prefixing the name of the declared item with the name of the file where it is defined, with a colon in between. For example, static foo(){} in bar.c results in a tag named bar.c:foo.
-S Include static tags, but make them look like global tags. Most tags-aware programs don’t like the filename:tagname tags produced by the -s flag, so -S was added as an alternative. If elvis and ref are the only programs that read the tags file, then you don’t need -S; otherwise, you do.
-r This causes ctags to generate both tags and refs. Without -r, it would only generate tags.
-a Append to tags, and maybe refs. Normally, ctags overwrites these files each time it is invoked. This flag is useful when you have too many files in the current directory for you to list them on a single command line; it allows you to split the arguments among several invocations.
-T This flag isn’t available on all systems. UNIX has it, but most others don’t. The -T flag prevents ctags from generating a tags file. This is useful when you want to generate a refs without changing tags.

Related Posts

UNIX/LINUX Command – rsync

UNIX/LINUX Command – rsync

NAME rsync – a fast, versatile, remote (and local) file-copying tool rsync Command SYNOPSIS Local: rsync [OPTION…] SRC… [DEST] Access via remote shell:Pull: rsync [OPTION…] [[email protected]]HOST:SRC… [DEST]Push: rsync [OPTION…] SRC… [[email protected]]HOST:DEST Access via rsync...

UNIX/LINUX Command – strip

UNIX/LINUX Command – strip

NAME strip—Discard symbols from object files. SYNOPSIS strip [ -Fbfdname|–target=bfdname ] [ -Ibfdname|–input-target=bfdname ] [ -Obfdname|–output-target=bfdname ] [-Rsectionname|–remove-section=sectionname ] [ -s|–strip-all ] [-S|-g|–strip-debug ][-x|–discard-all...

UNIX/LINUX Command – expand

UNIX/LINUX Command – expand

NAME expand—Convert tabs to spaces SYNOPSIS expand [–tab1[,tab2[,…]]] [–t tab1[,tab2[,…]]] [–i] [—tabs=tab1[,tab2[,…]]] [–initial] [–help] [–version] [file…] DESCRIPTION This manual page documents the GNU version of expand. expand writes the contents of each given...

UNIX/LINUX Command – uuencode

UNIX/LINUX Command – uuencode

NAME uuencode—Encode a binary fileuudecode—Decode a file created by uuencode SYNOPSIS uuencode [-m] [ file ] nameuudecode [-o outfile] [ file ]… DESCRIPTION uuencode and uudecode are used to transmit binary files over transmission mediums that do not support other...

Follow Us

Our Communities

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!



Submit a Comment

Your email address will not be published.

one + nineteen =