os
1 常量
const (
O_RDONLY int = syscall.O_RDONLY // 只读模式(必须三选一)
O_WRONLY int = syscall.O_WRONLY // 只写模式(必须三选一)
O_RDWR int = syscall.O_RDWR // 读写模式(必须三选一)
O_APPEND int = syscall.O_APPEND // 追加写入(不覆盖原有内容)
O_CREATE int = syscall.O_CREAT // 文件不存在时创建
O_EXCL int = syscall.O_EXCL // 与 O_CREATE 同用,要求文件必须不存在(原子性创建)
O_SYNC int = syscall.O_SYNC // 同步 I/O(写入直接刷盘)
O_TRUNC int = syscall.O_TRUNC // 打开时清空文件
)// 以读写模式打开文件,不存在则创建,追加写入
file, err := os.OpenFile("log.txt", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)2 变量
3 函数
3.1 func Mkdir(name string, perm FileMode) error
3.2 func MkdirAll(path string, perm FileMode) error
3.3 func MkdirTemp(dir, pattern string) (string, error)
3.4 func Remove(name string) error
3.5 func RemoveAll(path string) error
3.6 func Rename(oldpath, newpath string) error
3.7 func Link(oldname, newname string) error
3.8 func Symlink(oldname, newname string) error
3.9 func Readlink(name string) (string, error)
3.10 func Pipe() (r *File, w *File, err error)
3.11 func ReadFile(name string) ([]byte, error)
3.12 func WriteFile(name string, data []byte, perm FileMode) error
3.13 func Truncate(name string, size int64) error
3.14 func Chmod(name string, mode FileMode) error
3.15 func Chown(name string, uid, gid int) error
3.16 func Lchown(name string, uid, gid int) error
3.17 func Chtimes(name string, atime time.Time, mtime time.Time) error
3.18 func Environ() []string
3.19 func Clearenv()
3.20 func ExpandEnv(s string) string
3.21 func Getenv(key string) string
3.22 func Setenv(key, value string) error
3.23 func Unsetenv(key string) error
3.24 func LookupEnv(key string) (string, bool)
3.25 func Expand(s string, mapping func(string) string) string
3.26 func Chdir(dir string) error
3.27 func Getwd() (string, error)
3.28 func TempDir() string
3.29 func UserCacheDir() (string, error)
3.30 func UserCacheDir() (string, error)
3.31 func UserConfigDir() (string, error)
3.32 func UserHomeDir() (string, error)
3.33 func Getpid() int
3.34 func Getppid() int
3.35 func Getuid() int 和 func Geteuid() int
3.36 func Getgid() int 和 func Getegid() int
3.37 func Getgroups() ([]int, error)
3.38 func Exit(code int)
3.39 func IsExist(err error) bool
函数
功能说明
3.40 func SameFile(fi1, fi2 FileInfo) bool
4 类型
4.1 File类型
4.1.1 func Create(name string) (*File, error)
4.1.2 func CreateTemp(dir, pattern string) (*File, error)
4.1.3 func NewFile(fd uintptr, name string) *File
4.1.4 func Open(name string) (*File, error)
4.1.5 func OpenFile(name string, flag int, perm FileMode) (*File, error)
4.1.6 func (f *File) Read(b []byte) (n int, err error)
4.1.7 func (f *File) Write(b []byte) (n int, err error)
4.1.8 func (f *File) ReadAt(b []byte, off int64) (n int, err error)
4.1.9 func (f *File) WriteAt(b []byte, off int64) (n int, err error)
4.1.10 func (f *File) Seek(offset int64, whence int) (ret int64, err error)
4.1.11 func (f *File) Chmod(mode FileMode) error
4.1.12 func (f *File) Chown(uid, gid int) error
4.1.13 func (f *File) Stat() (FileInfo, error)
4.1.14 func (f *File) Truncate(size int64) error
4.1.15 func (f *File) Chdir() error
4.1.16 func (f *File) ReadDir(n int) ([]DirEntry, error)
4.1.17 func (f *File) Sync() error
4.1.18 func (f *File) Fd() uintptr
4.1.19 func (f *File) SyscallConn() (syscall.RawConn, error)
4.1.20 func (f *File) SetDeadline(t time.Time) error
4.1.21 func (f *File) Name() string
4.1.22 func (f *File) Close() error
4.2 FileInfo接口
4.2.1 func Stat(name string) (FileInfo, error)
4.2.2 func Lstat(name string) (FileInfo, error)
4.3 DirEntry接口
4.3.1 func ReadDir(name string) ([]DirEntry, error)
4.3.2 DirEntry与FileInfo对比
4.4 FileMode类型
4.4.1 核心特性
常量
值 (八进制)
描述
典型示例
4.5 ProAttr类型
4.6 Process类型
4.6.1 FindProcess(pid int) (*Process, error)
4.6.2 StartProcess(name string, argv []string, attr *ProcAttr) (*Process, error)
4.6.3 Kill() error
4.6.4 Release() error
4.6.5 Signal(sig Signal) error
4.6.6 Wait() (*ProcessState, error)
4.7 ProcessState
4.8 Signal接口
4.9 Root类型
最后更新于