g.findfile(1)

πŸ’– g.findfile(1) β€” GRASS GIS User's Manual πŸ’–

okay bestie, welcome to g.findfile, a lil legend from the GRASS GIS manual πŸ’… it searches the GRASS data base for files and sets shell variables for you. no cap, it's giving "quietly doing the most important job in your script" energy πŸ‘‘


✨ NAME ✨

g.findfile β€” searches for GRASS data base files and sets variables for the shell 🐚


🌸 KEYWORDS 🌸

general, map management, scripts


πŸŽ€ SYNOPSIS πŸŽ€

g.findfile
g.findfile --help
g.findfile [-nl] element=string file=string  [mapset=string]   [--help]
[--verbose]  [--quiet]  [--ui]

πŸ¦‹ Flags:

  • -n β€” do not add quotes
  • -l β€” list available elements and dip out (exit), periodt
  • --help β€” print usage summary
  • --verbose β€” verbose module output (chatty mode πŸ—£οΈ)
  • --quiet β€” quiet module output (shy mode 🀫)
  • --ui β€” force launching GUI dialog

πŸ“ Parameters:

  • element=string [required] β€” name of an element
  • file=string [required] β€” name of an existing map
  • mapset=string β€” name of a mapset (default: search path). '.' for current mapset

🌈 DESCRIPTION 🌈

g.findfile is literally designed for Bourne shell or Python scripts that need to search for mapset elements, including: raster, vector maps, region definitions and imagery groups. it's the bestie your script calls when it needs to know where things live 🫢

the list of element names to search for is not fixed β€” any subdirectory of the mapset directory is a valid element name. so go off, name your subdirectories whatever, iykyk ✨

however!! the user can find the list of standard GRASS element names in the file $GISBASE/etc/element_list. this is the file which g.remove, g.rename and g.copy use to determine which files need to be deleted/renamed/copied for a given entity type. iconic behavior honestly πŸ‘‘


πŸ’œ 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 to 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`
🫢 lowkey the whole module is just "here's your variables, go be a main character"

🧚 EXAMPLES 🧚

SHELL

raster map example:

eval `g.findfile element=cell file=elevation`

if the specified file (here: raster map) does not exist, the variables will be set as follows:

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)

accessed: Saturday Jan 17 05:40:39 2026

Main index | General index | Topics index | Keywords index | Graphical index | Full index

Β© 2003-2025 GRASS Development Team, GRASS GIS 8.4.2 Reference Manual


and that's the whole page bestie!! πŸ’– this was GRASS 8.4.2, the g.findfile(1) manual, and yeah it's from the GRASS Development Team Β© 2003-2025, last touched Saturday Jan 17 05:40:39 2026 β€” slay, go set some variables βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from