Search code examples
unixunix-timestampls

Date and time of a file in Unix in a desired format


Can anyone tell me what is the command to print out file creation TIME and DATE in UNIX? I have searched a lot on Google and got the solution for Linux. But those commands are not working on Sun OS.


Solution

  • Unix doesn't have a file creation time. It has these:

    • last modified time (content was modified)
    • last inode or files status change time (attributes like permissions, number of links etc., were changed)
    • last access time (content was read)

    ls is the best option if you are not feeding the output to a program. man ls is your friend.

    ls -lu => show last access time
    ls -lc => show last status change time
    ls -l  => show last modified time (default)
    

    In general, it is not recommended that we feed the output of ls into a program because of portability concerns. On macOS and Linux systems, we have a stat command to extract file status information.


    Related posts:

    Print a file's last modified date in Bash

    How to get the modified date and year of file in Unix?

    How to get file creation time in Unix with Perl