Print a file's last modified date in Bash

后端 未结 10 2152
难免孤独
难免孤独 2020-11-29 18:01

I can\'t seem to find how to print out the date of a file. I\'m so far able to print out all the files in a directory, but I need to print out the dates with it.

I

10条回答
  •  一个人的身影
    2020-11-29 18:37

    For the line breaks i edited your code to get something with no line breaks.

    #!/bin/bash
    for i in /Users/anthonykiggundu/Sites/rku-it/*; do
       t=$(stat -f "%Sm"  -t "%Y-%m-%d %H:%M" "$i")
       echo $t : "${i##*/}"  # t only contains date last modified, then only filename 'grokked'- else $i alone is abs. path           
    done
    

提交回复
热议问题