<p>I am connecting to pod via client-Go and I want to get the properties of the file directory</p>
<pre><code>func GetPodFiles(c *gin.Context)  {
    client, _ := Init.ClusterID(c)
    path := c.DefaultQuery(&quot;path&quot;, &quot;/&quot;)
    cmd := []string{
        &quot;sh&quot;,
        &quot;-c&quot;,
        fmt.Sprintf(&quot;ls -l %s&quot;, path),
    }
    config, _ := Init.ClusterCfg(c)
    req := client.CoreV1().RESTClient().Post().
        Resource(&quot;pods&quot;).
        Name(&quot;nacos-0&quot;).
        Namespace(&quot;default&quot;).SubResource(&quot;exec&quot;).Param(&quot;container&quot;, &quot;nacos&quot;)
    req.VersionedParams(
        &amp;v1.PodExecOptions{
            Command: cmd,
            Stdin:   false,
            Stdout:  true,
            Stderr:  true,
            TTY:     false,
        },
        scheme.ParameterCodec,
    )

    var stdout, stderr bytes.Buffer
    exec, err := remotecommand.NewSPDYExecutor(config, &quot;POST&quot;, req.URL())
    if err != nil {
        response.FailWithMessage(response.InternalServerError, err.Error(), c)
        return
    }
    err = exec.Stream(remotecommand.StreamOptions{
        Stdin:  nil,
        Stdout: &amp;stdout,
        Stderr: &amp;stderr,
    })
    if err != nil {
        response.FailWithMessage(response.InternalServerError, &quot;Error obtaining file&quot;, c)
        return
    }

    fmt.Println(stdout.String())
}
</code></pre>
<p>Execution Result Output</p>
<pre><code>total 0
lrwxrwxrwx   1 root root   7 Jun  1  2018 bin -&gt; usr/bin
drwxr-xr-x   5 root root 360 Feb 16 16:39 dev
lrwxrwxrwx   1 root root   8 Jun  1  2018 sbin -&gt; usr/sbin
drwxr-xr-x   2 root root   6 Apr 11  2018 srv
</code></pre>
<p>Expect the result</p>
<pre><code>&quot;data&quot;: [
        {
            &quot;perm&quot;: &quot;drwxr-xr-x&quot;,
            &quot;mod_time&quot;: &quot;2022-03-02 15:02:15&quot;,
            &quot;kind&quot;: &quot;d&quot;,
            &quot;name&quot;: &quot;temp&quot;,
            &quot;size&quot;: &quot;&quot;
        },
]
</code></pre>
<p>Is there a good way or a golang third-party library to handle it. Please let me know. Thank you</p>

gujiwork
<p>In a Kubernetes pod you can execute the <code>stat</code> linux command instead of <code>ls</code> command.</p>
<pre><code>$ stat yourFileOrDirName
</code></pre>
<p>The output of this command by default is like this:</p>
<pre class="lang-yaml prettyprint-override"><code>  File: yourFileOrDirName
  Size: 346             Blocks: 0          IO Block: 4096   directory
Device: 51h/82d Inode: 40431       Links: 1
Access: (0755/drwxr-xr-x)  Uid: ( 1000/ username)   Gid: ( 1000/ groupname)
Access: 2022-03-02 11:59:07.384821351 +0100
Modify: 2022-03-02 11:58:48.733821177 +0100
Change: 2022-03-02 11:58:48.733821177 +0100
 Birth: 2021-12-21 11:12:05.571841723 +0100
</code></pre>
<p>But you can tweak its output like this:</p>
<pre><code>$ stat --printf=&quot;%n,%A,%y,%s&quot; yourFileOrDirName
</code></pre>
<p>where  <code>%n</code> - file name, <code>%A</code> - permission bits and file type in human readable form, <code>%y</code> - time of last data modification human-readable, <code>%s</code> - total size, in bytes. You can also choose any character as a delimiter instead of comma.</p>
<p>the output will be:</p>
<pre class="lang-yaml prettyprint-override"><code>yourFileOrDirName,drwxr-xr-x,2022-03-02 11:58:48.733821177 +0100,346
</code></pre>
<p>See more info about the <code>stat</code> command <a href="https://man7.org/linux/man-pages/man1/stat.1.html" rel="nofollow noreferrer">here</a>.</p>
<p>After you get such output, I believe you can easily 'convert' it to json format if you really need it.</p>
<p><strong>Furthermore</strong>, you can run the <code>stat</code> command like this:</p>
<pre><code>$ stat --printf=&quot;{\&quot;data\&quot;:[{\&quot;name\&quot;:\&quot;%n\&quot;,\&quot;perm\&quot;:\&quot;%A\&quot;,\&quot;mod_time\&quot;:\&quot;%y\&quot;,\&quot;size\&quot;:\&quot;%s\&quot;}]}&quot; yourFileOrDirName
</code></pre>
<p>Or as @mdaniel suggested, since the command does not contain any shell variables, nor a <code>'</code>, the cleaner command is:</p>
<pre><code>stat --printf='{&quot;data&quot;:[{&quot;name&quot;:&quot;%n&quot;,&quot;perm&quot;:&quot;%A&quot;,&quot;mod_time&quot;:&quot;%y&quot;,&quot;size&quot;:&quot;%s&quot;}]}' yourFileOrDirName
</code></pre>
<p>and get the DIY json output:</p>
<pre class="lang-json prettyprint-override"><code>{&quot;data&quot;:[{&quot;name&quot;:&quot;yourFileOrDirName&quot;,&quot;perm&quot;:&quot;drwxrwxr-x&quot;,&quot;mod_time&quot;:&quot;2022-02-04 15:17:27.000000000 +0000&quot;,&quot;size&quot;:&quot;4096&quot;}]}
</code></pre>
