-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLS.go
More file actions
105 lines (66 loc) · 1.67 KB
/
Copy pathLS.go
File metadata and controls
105 lines (66 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"fmt"
"io/ioutil"
"os"
"os/user"
"strconv"
"syscall"
)
func ls(command []string) {
if len(command) <= 3 {
if len(command) == 1 {
getDirectoryContents()
} else {
if command[1] == "-l" {
displayFileInfo(command[2])
} else if command[1] == "-al" {
displayFileInfo(command[2])
}
}
} else {
for i := 1; i < len(command); i++ {
displayFileInfo(command[i])
}
}
}
func getDirectoryContents() {
currentDir, _ := os.Getwd()
directoryFiles, _ := ioutil.ReadDir(currentDir)
for _, fileName := range directoryFiles {
fmt.Println(fileName.Name())
}
}
func displayFileInfo(fileName string) {
//layoutISO := "2019-04-15"
//layoutUS := "January 2, 2006"
info, _ := os.Stat(fileName)
fmt.Print(info.Mode(), " ")
nlink := uint64(0)
if sys := info.Sys(); sys != nil {
if stat, ok := sys.(*syscall.Stat_t); ok {
nlink = uint64(stat.Nlink)
}
}
fmt.Print(nlink, " ")
getGroupandUserNames()
//getFileSize(info)
fmt.Print(info.Size(), " ")
// fmt.Print(info.ModTime(), " ")
t := info.ModTime()
//parseTime, _ := time.Parse(layoutUS, t)
fmt.Print(t.Format("Apr 15 21:01:05"), " ")
fmt.Println(info.Name())
//fmt.Println();
}
func getGroupandUserNames() {
groupCharactheristics, err := user.LookupGroupId(strconv.Itoa(os.Getegid()))
userCharacteristics, err := user.LookupId(strconv.Itoa(os.Geteuid()))
if err != nil {
fmt.Println(err)
}
fmt.Print(groupCharactheristics.Name + " " + userCharacteristics.Username + " ")
}
// func getFileSize(info FileInfo ){
// fmt.Println(info.Size());
// }