g.filename(1)
g.filename(1) π β¨
okay bestie, this is the GRASS GIS User's Manual page for g.filename(1), and it's genuinely one of those quiet little icons that scripts are obsessed with. no cap.
β¨ NAME β¨
g.filename β prints GRASS data base file names ποΈπ
πΈ KEYWORDS πΈ
general, map management, scripts
π¦ SYNOPSIS π¦
g.filename
g.filename --help
g.filename [-c] element=string file=string [mapset=string] [--help]
[--verbose] [--quiet] [--ui]
π Flags:
-cβ Create element directory in the current mapset. Like, if the element directory for the database file doesn't exist yet, it goes ahead and makes it for you π--helpβ Print usage summary--verboseβ Verbose module output--quietβ Quiet module output--uiβ Force launching GUI dialog
π§ Parameters:
element=string[required] β Name of an elementfile=string[required] β Name of a database filemapset=stringβ Name of a mapset (default: current)
π DESCRIPTION π
g.filename is literally built for Bourne shell scripts that need to know the full file name β path included β for mapset elements. we're talking raster, vector and site maps, region definitions, imagery groups, all of it. πΊοΈβ¨
the list of element names you can search for is not fixed, bestie. any subdirectory of the mapset directory is a valid element name. slay, flexible queen.
that said, if you want the official roster of standard GRASS GIS element names, it's chilling in the file $GISBASE/etc/element_list. this is the exact file that g.remove/g.rename/g.copy consult to figure out which files need to be deleted/renamed/copied for a given entity type. iykyk π«Ά
π OUTPUT π
g.filename writes one line to standard output:
file=βfull_file_pathnameβ
the output is a /bin/sh command that sets the variable specified by the file name to the full UNIX path name for the data base file. you can set that variable in /bin/sh like this, queen:
eval `g.filename element=name mapset=name file=name`
π₯ NOTES π₯
this module generates the filename, but honestly it does not care if the file (or mapset or element) actually exists or not. and that's the point β it's a feature! it means shell scripts can create brand-new data base files, not just use existing ones. π
if the mapset is the current mapset, g.filename can automatically create the element you specified if it doesn't already exist, as long as you pass the -c flag. this makes it super easy to add new files to the data base without stressing about whether the required data base directories exist. (β οΈ heads up though: this program will not create a new mapset, even if the one you specified doesn't currently exist. so don't come for it about that.)
also, real talk β this module should not be used to create directories at the level of what this module refers to as files. like, a directory that carries a name specified by a user (think vector map directories) should not be created using this module. standard library functions that come with whatever language you're in are the more appropriate tool for that. periodt.
the program exits with a 0 if everything is ok; it exits with a non-zero value if there's an error, and in that case file=βfull_file_pathnameβ is not output. no partial results, no crumbs. π
π SEE ALSO π
g.findfileg.gisenv
π AUTHOR π
Michael Shapiro, U.S.Army Construction Engineering Research Laboratory
β SOURCE CODE β
Available at: g.filename source code (history)
Accessed: Saturday Jan 17 05:40:38 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
okay that's the whole page bestie, mwah π this was GRASS 8.4.2 g.filename(1) β go forth and let your shell scripts eat π«Άπβ¨
π¦ where this page comes from
- fedora 44: grass 8.4.2-4.fc44 Β· 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