Developing find(1) in Go
This section will teach you the necessary things that you need to know in order to develop a simplified version of the find(1)
command-line utility in Go. The developed version will not support all the command-line options supported by find(1)
, but it will have enough options to be truly useful.
What you will see in the following subsections is the entire process in small steps. So, the first subsection will show you the Go way for visiting all files and directories in a given directory tree.
Traversing a directory tree
The most important task that find(1)
needs to support is being able to visit all files and sub directories starting from a given directory. So, this section will implement this task in Go. The Go code of traverse.go
will be presented in three parts. The first part is the expected preamble:
package main import ( "fmt" "os" "path/filepath" )
The second part is about implementing a function named walkFunction()
that will be used as an argument...