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 when format is set to JSON, so don't be surprised 😌)
  • -l β€” list all the available elements and dip. exit stage left ✨
  • -t β€” return code 0 when the file is found, 1 otherwise. she behaves like the test utility here: 0 for true, 1 for 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 element
  • file=string [required] β€” the name of an existing map
  • mapset=string β€” the name of a mapset (default: search path). ’.’ for the current mapset
  • format=name [required] β€” output format
    • Options: shell, json
    • Default: shell
    • shell: shell script style output
    • json: JSON (JavaScript Object Notation)

πŸ’œ 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