Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang os Package FileMode Constants with Examples

Golang | os Package FileMode Constants: Here, we are going to learn about the various FileMode constants of the os package with its usages, syntax, and examples.
Submitted by IncludeHelp, on November 06, 2021

List of os Package FileMode Constants

These single letters are the abbreviations used by the String method's formatting.

Constant Value Description
ModeDir d Directory
ModeAppend a Append-only
ModeExclusive l Exclusive use
ModeTemporary t Temporary file; Plan 9 only
ModeSymlink L Symbolic link
ModeDevice d Device file
ModeNamedPipe p Named pipe (FIFO)
ModeSocket s Unix socket domain
ModeSetuid u Setuid
ModeSetgid g Setgid
ModeCharDevice c Unix character device, when ModeDevice is set
ModeSticky t Sticky
ModeIrregular ? Non-regular file; nothing else is known about this file
ModeType Mask for the type bits. For regular files, none will be set.
ModePerm 0o777 Unix permission bits



Implementation in the package source code:

const (
	// The single letters are the abbreviations
	// used by the String method's formatting.
	ModeDir        = fs.ModeDir
	ModeAppend     = fs.ModeAppend
	ModeExclusive  = fs.ModeExclusive
	ModeTemporary  = fs.ModeTemporary
	ModeSymlink    = fs.ModeSymlink
	ModeDevice     = fs.ModeDevice
	ModeNamedPipe  = fs.ModeNamedPipe
	ModeSocket     = fs.ModeSocket
	ModeSetuid     = fs.ModeSetuid
	ModeSetgid     = fs.ModeSetgid
	ModeCharDevice = fs.ModeCharDevice
	ModeSticky     = fs.ModeSticky
	ModeIrregular  = fs.ModeIrregular

	ModeType = fs.ModeType

	ModePerm = fs.ModePerm


  • None

Return Value

The return type of these constants are fs.FileMode.


// Golang program to demonstrate the example of
// os Package FileMode Constants with Examples

package main

import (

func main() {
	// Printing the types & values
	fmt.Printf("%T, %v\n", os.ModeDir, os.ModeDir)
	fmt.Printf("%T, %v\n", os.ModeAppend, os.ModeAppend)
	fmt.Printf("%T, %v\n", os.ModeExclusive, os.ModeExclusive)
	fmt.Printf("%T, %v\n", os.ModeTemporary, os.ModeTemporary)
	fmt.Printf("%T, %v\n", os.ModeSymlink, os.ModeSymlink)
	fmt.Printf("%T, %v\n", os.ModeDevice, os.ModeDevice)
	fmt.Printf("%T, %v\n", os.ModeNamedPipe, os.ModeNamedPipe)
	fmt.Printf("%T, %v\n", os.ModeSocket, os.ModeSocket)
	fmt.Printf("%T, %v\n", os.ModeSetuid, os.ModeSetuid)
	fmt.Printf("%T, %v\n", os.ModeSetgid, os.ModeSetgid)
	fmt.Printf("%T, %v\n", os.ModeCharDevice, os.ModeCharDevice)
	fmt.Printf("%T, %v\n", os.ModeSticky, os.ModeSticky)
	fmt.Printf("%T, %v\n", os.ModeIrregular, os.ModeIrregular)
	fmt.Printf("%T, %v\n", os.ModeType, os.ModeType)
	fmt.Printf("%T, %v\n", os.ModePerm, os.ModePerm)


fs.FileMode, d---------
fs.FileMode, a---------
fs.FileMode, l---------
fs.FileMode, T---------
fs.FileMode, L---------
fs.FileMode, D---------
fs.FileMode, p---------
fs.FileMode, S---------
fs.FileMode, u---------
fs.FileMode, g---------
fs.FileMode, c---------
fs.FileMode, t---------
fs.FileMode, ?---------
fs.FileMode, dLDpSc?---------
fs.FileMode, -rwxrwxrwx

Golang os Package »

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.