Print a file's last modified date in Bash

后端 未结 10 2146
难免孤独
难免孤独 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:21

    If file name has no spaces:

    ls -l  | awk '{print $6, " ", $7, " ", $8, " ", $9 }'
    

    This prints as the following format:

     Dec   21   20:03   a1.out
     Dec   21   20:04   a.cpp
    

    If file names have space (you can use the following command for file names with no spaces too, just it looks complicated/ugly than the former):

     ls -l  | awk '{printf ("%s %s %s ",  $6,  $7, $8); for (i=9;   i<=NF; i++){ printf ("%s ", $i)}; printf ("\n")}'
    

提交回复
热议问题