File basics
Because files are such an integral part of the computing ecosystem, it is crucial to understand the options available in Go for working with files. This section covers some basic operations, such as opening, closing, creating, and deleting files. Additionally, it covers renaming and moving, seeing if files exist, modifying permissions, ownership, timestamps, and working with symbolic links. Most of these examples use a hard-coded filename of test.txt
. Change this filename if you want to operate on a different file.
Creating an empty file
A common tool used in Linux is the touch program. It's frequently used when you need to quickly create an empty file with a specific name. The following example replicates one of the common touch use case of creating an empty file.
There are limited uses to creating an empty file, but let's consider one example. What if there was a service that wrote logs to a rotating set of files. Every day a new file is created with the current date, and the...