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-xoption.-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 usesidutils(1)as a search engine. to use this command, you need to installidutils(1)in your system and executegtags(1)with the-Ioption. (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 ofGTAGS.--print nameβ print location of name, which may be one of:root,dbpathorconf.rootmeans project's root directory.dbpathmeans a directory where tag databases exist.confmeans configuration file.-u,--updateβ update tag files incrementally. this command internally invokesgtags(1). you can execute this command anywhere in the project β differing fromgtags(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,alwaysorauto(default). the default color is bold red text on current background; the environment variableGREP_COLORS(onlymtandmsare effective at present) orGREP_COLORdefines 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 inGTAGSLIBPATHwhen tags are found in a tag file. this is the default.--from-here contextβ decide tag type by context. its syntax should belineno: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,-rand-son 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 variableGTAGSCONFto file.--gtagslabel labelβ set environment variableGTAGSLABELto 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,-gcommand,-Pcommand and-Icommand.-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,lastorall(default). this option is valid only with the-ccommand 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,-Pcommand and-gcommand. as an exception,-gcommand 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, likeREADME. this option is valid only with the-gor-Pcommand. this option overrides the-ooption. π¨-o,--otherβ treat not only source files but also text files other than source code, likeREADME. this option is valid only with the-gor-Pcommand.--path-style formatβ print path names using format, which may be one of:relative,absolute,shorter,absliborthrough.relativemeans relative path.absolutemeans absolute path.shortermeans the shorter one of relative and absolute path.abslibmeans absolute path for libraries (GTAGSLIBPATH) and relative path for the rest.throughmeans the relative path from the project root directory (internal format ofGPATH). when this style is used,GTAGSLIBPATHis ignored. the default isrelative. the--path-styleoption is given more priority than the-aoption.--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-poption, print the root directory of the project.--result formatβ print out using format, which may be one of:path(default),ctags,ctags-x,greporcscope. the--result=ctagsand--result=ctags-xoptions are equivalent to the-tand-xoptions respectively. the--resultoption is given more priority than the-tand-xoptions.--single-update fileβ update tag files usinggtags(1)with the--single-updateoption. it is considered that file was added, updated or deleted, and there is no change in other files. this option implies the-uoption.-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-loption, but you need not change directory. π«-T,--throughβ go through all the tag files listed inGTAGSLIBPATH. by default, stop searching when tag is found. this option is ignored when either-s,-ror-loption 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-gor-Pcommands.-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 variableGTAGSROOTis not set and fileGTAGSROOTexists in the same directory asGTAGSthen global setsGTAGSROOTto the contents of the file.gtags.conf,$HOME/.globalrcβ configuration data for GNU Global. Seegtags.conf(5).
π± ENVIRONMENT π±
The following environment variables affect the execution of global:
GREP_COLORβ the color to use for--color;GREP_COLORShas precedence.GREP_COLORSβ the color (mtorms) to use for--color; seegrep(1).GTAGSBLANKENCODEβ if this variable is set, the--encode-path=" <TAB>"option is specified.GTAGSCACHEβ the size of the B-tree cache. The default is50000000(bytes).GTAGSCONFβ configuration file.GTAGSDBPATHβ the directory in which the tag files exist. This value is ignored whenGTAGSROOTis not defined. Use of this variable is not recommended π ββοΈGTAGSFORCECPPβ if this variable is set, each file whose suffix is.his treated as a C++ source file.GTAGSLABELβ configuration label. The default isdefault.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,globalalso searches in these paths. Since onlyGTAGSis targeted in the retrieval, this variable is ignored when-ror-sis specified.GTAGSLOGGINGβ if this variable is set,$GTAGSLOGGINGis 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 ofGTAGS. Use of this variable is not recommended π ββοΈGTAGSTHROUGHβ if this variable is set, the-Toption 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 isobj.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 π
gtags(1),htags(1),less(1),gtags.conf(5).- GNU Global source code tag system (
http://www.gnu.org/software/global/).
π 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