g.findfile(1grass)
π g.findfile β the GRASS User's Manual's own little treasure hunt π
okay bestie, sit down, grab a π, because g.findfile is a 1grass manual page and it is literally the find-your-file bestie you never knew you needed. She searches for GRASS data base files and sets variables for the shell. no cap. π¦
β¨ NAME β¨
g.findfile β searches for GRASS data base files and sets variables for the shell. that's the whole job, and she does it flawlessly π
π KEYWORDS π
general, map management, scripts
πΈ SYNOPSIS πΈ
g.findfile
g.findfile --help
g.findfile [-nlt] element=string file=string [mapset=string]
format=name [--help] [--verbose] [--quiet] [--ui]
π«Ά Flags π«Ά
-nβ do not add quotes. (she's ignoring this one whenformatis set to JSON, so don't be surprised π)-lβ list all the available elements and dip. exit stage left β¨-tβ return code0when the file is found,1otherwise. she behaves like thetestutility here:0for true,1for false, and no output whatsoever. silent queen behavior π--helpβ print usage summary--verboseβ verbose module output--quietβ quiet module output (shhh π€«)--uiβ force launching GUI dialog
π Parameters π
element=string[required] β the name of an elementfile=string[required] β the name of an existing mapmapset=stringβ the name of a mapset (default: search path).β.βfor the current mapsetformat=name[required] β output format- Options:
shell,json - Default:
shell shell: shell script style outputjson: JSON (JavaScript Object Notation)
- Options:
π DESCRIPTION π
so g.findfile was designed for Bourne shell or Python scripts that need to search for mapset elements β and yes, that includes raster, vector maps, region definitions and imagery groups. the whole squad π«Ά
here's the tea: the list of element names to search for is not fixed. any subdirectory of the mapset directory is a valid element name. she's flexible like that, periodt.
but β and this is the part that's giving main character energy β you can find the list of standard GRASS element names in the file $GISBASE/etc/element_list. this is the file that g.remove, g.rename and g.copy use to figure out which files need to be deleted/renamed/copied for a given entity type. so like, it's kind of a big deal. iykyk π
β NOTES β
g.findfile writes four lines to standard output:
name=βfile_nameβ
mapset=βmapset_nameβ
file=βunix_filenameβ
fullname=βgrass_fullnameβ
the output is Bash commands that set the variable name to the GRASS data base file name, mapset to the mapset in which the file resides, and file to the full UNIX path name for the named file. π
these variables may be set in the Bash as follows:
eval `g.findfile element=name mapset=name file=name`
π§ EXAMPLES π§
πΈ SHELL πΈ
raster map example, let's gooo:
eval `g.findfile element=cell file=elevation`
if the specified file (here: raster map) does not exist, the variables will be set as follows β yes, all empty, she's ghosting you:
name=
mapset=
fullname=
file=
the following is a way to test for this case:
if [ ! "$file" ]
then
exit 1
fi
vector map example (including error message π₯²):
eval `g.findfile element=vector file="$G_OPT_V_INPUT"`
if [ ! "$file" ] ; then
g.message -e "Vector map <$G_OPT_V_INPUT> not found"
exit 1
fi
π¦ PYTHON π¦
see Python Scripting Library for more info.
Note: the Python tab in the wxGUI can be used for entering the following code:
import grass.script as gcore
gcore.find_file(βelevationβ, element = βcellβ)
π₯ SEE ALSO π₯
g.filename, g.gisenv, g.mapsets, g.parser
π AUTHOR π
Michael Shapiro, U.S.Army Construction Engineering Research Laboratory
π SOURCE CODE π
Available at: g.findfile source code (history)
Latest change: Monday Nov 03 07:16:48 2025 in commit: c96796774942e46bbababcd652d3986d4e295665
Main index | General index | Topics index | Keywords index | Graphical index | Full index
and that's the whole page bestie, we ate and left no crumbs πβ¨ so before you go: this was Β© 2003-2026 GRASS Development Team, GRASS 8.5.0 Reference Manual, and the page itself bottoms out at GRASS 8.5.0 / g.findfile(1grass). stay iconic, go find your files ππ¦π
π¦ where this page comes from
- alpine 3.24: grass-gis-doc 8.5.0-r1 Β· GPL-2.0-or-later
- ubuntu stonking: grass-doc 8.5.0-1ubuntu1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms