GLOBAL(1)

πŸ’… GLOBAL(1) β€” bestie, it's the global manual πŸ’…

so this is GLOBAL(1), filed under General Commands Manual, and it's the whole vibe guide to global β€” the tool that finds where your symbols live. buckle up, it's long, but we're getting through it together 🫢


πŸŽ€ NAME πŸŽ€

global β€” print locations of given symbols ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

global [-adEFGilMnNqrstTvx][-S dir][-e] pattern
global -c[dFiIMoOPqrsTv] prefix
global -f[adlnqrstvx][-L file-list][-S dir] files
global -g[aEGilMnoOqtvVx][-L file-list][-S dir][-e] pattern [files]
global -I[ailMnqtvx][-S dir][-e] pattern
global -P[aEGilMnoOqtvVx][-S dir][-e] pattern
global -p[qrv]
global -u[qv]

✨ DESCRIPTION ✨

global finds locations of given symbols in C, Yacc, Java, PHP and assembly source files, and it prints the path name, the line number and the line image of those locations. and no, it's not just definitions β€” global can locate references and other symbols too. versatile queen πŸ‘‘

global can treat a source tree β€” that's a directory that has sub-directories and source files β€” as a project. but listen: before you use this command, you must run gtags(1) at the root directory of the project you want to investigate, to make tag files. do that first, fr fr. after that you can use the global command anywhere in the project β€” you don't have to tell it where the tag file is, it locates it by itself. self-sufficient icon πŸ’…

you can specify a regular expression for pattern. global understands two different versions of regular expression syntax: basic and extended (that one's the default). iykyk 🌈


πŸ’– COMMANDS πŸ’–

the following commands are available:

  • <no command> pattern β€” no command means the tag search command. prints tags which match pattern. by default, it prints definition tags.
  • -c, --completion[=limit] [prefix] β€” print symbols which start with prefix. if prefix isn't given, print all symbols. if limit is given, print up to limit lines. ✨
  • -f, --file files β€” print all tags in the files. this command implies the -x option.
  • -g, --grep pattern [files] β€” print all lines which match the pattern. if files are given, this command searches in those files. πŸ”
  • --help β€” print a usage message.
  • -I, --idutils pattern β€” print all lines which match to pattern. this function uses idutils(1) as a search engine. to use this command, you need to install idutils(1) in your system and execute gtags(1) with the -I option. (yes, both. no shortcuts 🫠)
  • -P, --path [pattern] β€” print path names which match to pattern. if no pattern is given, print all paths in the project.
  • -p, --print-dbpath β€” print location of GTAGS.
  • --print name β€” print location of name, which may be one of: root, dbpath or conf. root means project's root directory. dbpath means a directory where tag databases exist. conf means configuration file.
  • -u, --update β€” update tag files incrementally. this command internally invokes gtags(1). you can execute this command anywhere in the project β€” differing from gtags(1). iconic behaviour honestly πŸ’…
  • --version β€” show version number.

🌸 OPTIONS 🌸

the following options are available:

  • -a, --absolute β€” print absolute path names. by default, it prints relative path names.
  • --color when β€” use color to highlight the pattern within the line; when may be one of: never, always or auto (default). the default color is bold red text on current background; the environment variable GREP_COLORS (only mt and ms are effective at present) or GREP_COLOR defines it. this option is effective to the following commands: <no command>, -f, -g, -I, -P. 🌈
  • -C, --directory dir β€” change the directory before doing all the work, including parameter analysis.
  • -d, --definition β€” print locations of definitions.
  • -e, --regexp pattern β€” use pattern as the pattern; useful to protect patterns starting with -. (protect her πŸ₯Ί)
  • -E, --extended-regexp β€” interpret pattern as a extended regular expression. this is the default.
  • --encode-path chars β€” convert path characters in chars into a % symbol, followed by the two-digit hexadecimal representation of the character. a blank will be converted to %20.
  • -F, --first-match β€” end the search without going through all the tag files listed in GTAGSLIBPATH when tags are found in a tag file. this is the default.
  • --from-here context β€” decide tag type by context. its syntax should be lineno:path. if the context is a definition of the pattern then use -r, else if there is at least one definition of the pattern then use -d, else use -s. if this option is specified then -d, -r and -s on the command line are ignored. regular expression is not allowed for pattern. this option assumes use in conversational environments such as editors and IDEs. 🧠
  • -G, --basic-regexp β€” interpret pattern as a basic regular expression. the default is an extended regular expression.
  • --gtagsconf file β€” set environment variable GTAGSCONF to file.
  • --gtagslabel label β€” set environment variable GTAGSLABEL to label.
  • -i, --ignore-case β€” ignore case distinctions in the pattern.
  • -L, --file-list file β€” obtain files from file in addition to the arguments. the argument file can be set to - to accept a list of files from the standard input. file names must be separated by newline.
  • -l, --local β€” print only tags which exist under the current directory.
  • --literal β€” execute literal search instead of regular expression search. this option works with the tag search command, -g command, -P command and -I command.
  • -M, --match-case β€” search is case-sensitive. this is the default.
  • --match-part part β€” specify how path name completion should match, where part is one of: first, last or all (default). this option is valid only with the -c command in conjunction with -P.
  • -n, --nofilter β€” suppress sort filter and path conversion filter.
  • -N, --nearness[=start] β€” use Nearness sort method (sorting by closest from start) for the output. by default, alphabetical sort method is used. this option is effective for the tag search command, -P command and -g command. as an exception, -g command ignores this option when files are specified by arguments. the nearness is defined by how many parent directories to go up to reach the target. the result of nearness sort is concatenation of the following ([0]-[n]) in this order. the default of start is the current directory.
    • [0] If the start is a file, output of local search in the file.
    • [1] Output of local search in the start directory except for [0].
    • [2] Output of local search in the parent directory except for [0]-[1].
    • [3] Output of local search in the grandparent directory except for [0]-[2].
    • ... (repeat until the project root directory)
    • [n] Output of local search in the project root directory except for [0]-[n-1].

in each directory, they are sorted by alphabetical order.

  • -O, --only-other β€” treat only text files other than source code, like README. this option is valid only with the -g or -P command. this option overrides the -o option. 🚨
  • -o, --other β€” treat not only source files but also text files other than source code, like README. this option is valid only with the -g or -P command.
  • --path-style format β€” print path names using format, which may be one of: relative, absolute, shorter, abslib or through. relative means relative path. absolute means absolute path. shorter means the shorter one of relative and absolute path. abslib means absolute path for libraries (GTAGSLIBPATH) and relative path for the rest. through means the relative path from the project root directory (internal format of GPATH). when this style is used, GTAGSLIBPATH is ignored. the default is relative. the --path-style option is given more priority than the -a option.
  • --print0 β€” print each record followed by a null character instead of a newline.
  • -q, --quiet β€” quiet mode. 🀫
  • -r, --reference, --rootdir β€” print reference tags. reference means the reference to a symbol which has definitions. with the -p option, print the root directory of the project.
  • --result format β€” print out using format, which may be one of: path (default), ctags, ctags-x, grep or cscope. the --result=ctags and --result=ctags-x options are equivalent to the -t and -x options respectively. the --result option is given more priority than the -t and -x options.
  • --single-update file β€” update tag files using gtags(1) with the --single-update option. it is considered that file was added, updated or deleted, and there is no change in other files. this option implies the -u option.
  • -s, --symbol β€” print other symbol tags. other symbol means the reference to a symbol which has no definition.
  • -S, --scope dir β€” print only tags which exist under dir directory. it is similar to the -l option, but you need not change directory. πŸ’«
  • -T, --through β€” go through all the tag files listed in GTAGSLIBPATH. by default, stop searching when tag is found. this option is ignored when either -s, -r or -l option is specified.
  • -t, --tags β€” use standard ctags format.
  • -V, --invert-match β€” invert the sense of matching, to select non-matching lines. this option is valid only with the -g or -P commands.
  • -v, --verbose β€” verbose mode. (she's chatty πŸ’¬)
  • -x, --cxref β€” use standard ctags cxref (with -x) format.

✨ EXAMPLES ✨

Okay bestie, storytime πŸ“–βœ¨ here's the whole vibe in action. Imagine a project with Makefile, src/, lib/ β€” you run gtags, and boom πŸ’₯ tag files appear. Watch:

$ ls -F
Makefile      src/    lib/
$ gtags
$ ls G*
GPATH   GRTAGS  GTAGS
$ global main
src/main.c
$ (cd src; global main)
main.c
$ global -x main
main              10 src/main.c  main (argc, argv) {
$ global -f src/main.c
main              10 src/main.c  main (argc, argv) {
func1             55 src/main.c  func1() {
func2             72 src/main.c  func2() {
func3            120 src/main.c  func3() {
$ global -x '^[sg]et'
set_num           20 lib/util.c  set_num(values) {
get_num           30 lib/util.c  get_num() {
$ global -rx set_num
set_num          113 src/op.c            set_num(32);
set_num          225 src/opop.c               if (set_num(0) > 0) {
$ global strlen
$ (cd /usr/src/sys; gtags)
$ export GTAGSLIBPATH=/usr/src/sys
$ global -a strlen
/usr/src/sys/libkern/strlen.c
$ (cd /usr/src/lib; gtags)
$ GTAGSLIBPATH=/usr/src/lib:/usr/src/sys
$ global -a strlen
/usr/src/lib/libc/string/strlen.c

Like, the way it searches from a subdir and then uses GTAGSLIBPATH for library functions? Obsessed, fr fr 🫢


πŸ“ FILES πŸ“

  • GTAGS β€” tag file for definitions. The main character of the tag trio πŸ‘‘
  • GRTAGS β€” tag file for references.
  • GPATH β€” tag file for source files.
  • GTAGSROOT β€” if environment variable GTAGSROOT is not set and file GTAGSROOT exists in the same directory as GTAGS then global sets GTAGSROOT to the contents of the file.
  • gtags.conf, $HOME/.globalrc β€” configuration data for GNU Global. See gtags.conf(5).

🌱 ENVIRONMENT 🌱

The following environment variables affect the execution of global:

  • GREP_COLOR β€” the color to use for --color; GREP_COLORS has precedence.
  • GREP_COLORS β€” the color (mt or ms) to use for --color; see grep(1).
  • GTAGSBLANKENCODE β€” if this variable is set, the --encode-path=" <TAB>" option is specified.
  • GTAGSCACHE β€” the size of the B-tree cache. The default is 50000000 (bytes).
  • GTAGSCONF β€” configuration file.
  • GTAGSDBPATH β€” the directory in which the tag files exist. This value is ignored when GTAGSROOT is not defined. Use of this variable is not recommended πŸ™…β€β™€οΈ
  • GTAGSFORCECPP β€” if this variable is set, each file whose suffix is .h is treated as a C++ source file.
  • GTAGSLABEL β€” configuration label. The default is default.
  • GTAGSLIBPATH β€” if this variable is set, it is used as the path to search for library functions. If the given symbol is not found in the current project, global also searches in these paths. Since only GTAGS is targeted in the retrieval, this variable is ignored when -r or -s is specified.
  • GTAGSLOGGING β€” if this variable is set, $GTAGSLOGGING is used as the path name of a log file. There is no default value.
  • GTAGSROOT β€” the root directory of the project. Usually, it is recognized by existence of GTAGS. Use of this variable is not recommended πŸ™…β€β™€οΈ
  • GTAGSTHROUGH β€” if this variable is set, the -T option is specified.
  • GTAGSOBJDIR, MAKEOBJDIR β€” if eigher of the two variable is set, it is used as the name of BSD-style objdir. The former is given priority. The default is obj.
  • GTAGSOBJDIRPREFIX, MAKEOBJDIRPREFIX β€” if eigher of the two variable is set, it is used as the prefix of BSD-style objdir. The former is given priority. The default is /usr/obj.

βš™οΈ CONFIGURATION βš™οΈ

The following configuration variables affect the execution of global:

  • icase_path (boolean) β€” ignore case distinctions in pattern.

🩺 DIAGNOSTICS 🩺

Global exits with a non-0 value if an error occurred, 0 otherwise. So zero is the slay, non-zero is the "bestie we have a problem" πŸ’€


πŸ‘€ SEE ALSO πŸ‘€


πŸ‘‘ AUTHOR πŸ‘‘

Shigio YAMAGUCHI, Hideki IWAMOTO and others.


πŸ“œ HISTORY πŸ“œ

The global command appeared in FreeBSD 2.2.2.


That's the whole page, bestie! This gem is from the GNU Project, dated May 2015, and it's GLOBAL(1) β€” periodt πŸ’…βœ¨

πŸ“¦ where this page comes from
  • arch rolling: global 6.7-1 Β· BSD-3-Clause AND GPL-2.0-only AND GPL-3.0-or-later AND LGPL-2.0-or-later AND LicenseRef-CALDERA AND LicenseRef-PD AND MIT
  • epel 10: global 6.6.15-1.el10_3 Β· GPL-3.0-or-later and LGPL-2.0-or-later and LGPL-2.1-or-later and BSD-3-Clause and MIT and LicenseRef-Fedora-Public-Domain and blessing and GFDL-1.2-or-later
  • fedora 43: global 6.6.15-1.fc43 Β· GPL-3.0-or-later and LGPL-2.0-or-later and LGPL-2.1-or-later and BSD-3-Clause and MIT and LicenseRef-Fedora-Public-Domain and blessing and GFDL-1.2-or-later
  • fedora 44: global 6.6.15-1.fc44
  • fedora 44: global 6.7-1.fc44 Β· GPL-3.0-or-later and LGPL-2.0-or-later and LGPL-2.1-or-later and BSD-3-Clause and MIT and LicenseRef-Fedora-Public-Domain and blessing and GFDL-1.2-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms