This is an education project that attempts to reimplement the GNU coreutils in Go. You can find the full manual here: https://www.gnu.org/software/coreutils/manual/coreutils.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
go-coreutils/stat/main.go

33 lines
496 B

package main
import (
"fmt"
"os"
"flag"
"log"
"io/fs"
)
func PrintStat(stat fs.FileInfo) {
fmt.Printf("File: %s\nSize: %d\nAccess: %v\nModify: %v",
stat.Name(),
stat.Size(),
stat.Mode(),
stat.ModTime())
}
func main() {
flag.Parse()
files := flag.Args()
for _, fname := range files {
f, err := os.Open(fname)
if err != nil { log.Fatal(err) }
defer f.Close()
stats, err := f.Stat()
if err != nil { log.Fatal(err) }
PrintStat(stats)
}
}