Using Epoch to Create a Unique Path File Name

Using the UNIX Epoch is a far more useful way to uniquely name a file whether it be new or a copy of an existing file. This epochify utility is an elegant way to do it in Go, but it can also be easily done with nothing but Bash as well.

💢 I have always hated (1) and (2) and (copy) when the designers of such things threw away an amazing opportunity to include the exact second the new file name was created.

package main

import (

func Epochify(path string) string {
    i := strings.LastIndex(path, ".")
    if i >= 0 {
        return fmt.Sprintf("%v-%v%v", path[0:i], time.Now().Unix(), path[i:])
    return fmt.Sprintf("%v-%v", path, time.Now().Unix())

func TextArgs() string { return strings.Join(os.Args[1:], " ") } 

func main() {

Here are some ways you could use it.

epochify some file
epochify ""
epochify "/a/path/to/"
cp $(epochify
ls some*
some file-1558288794