scalebion.blogg.se

I want to save some sort of file time
I want to save some sort of file time




i want to save some sort of file time
  1. #I WANT TO SAVE SOME SORT OF FILE TIME UPDATE#
  2. #I WANT TO SAVE SOME SORT OF FILE TIME WINDOWS#

  • %.16w: the birth time, in human-readable format, truncated to sixteen characters (enough to show the year, month, day, hour, minute and second).
  • %10s: the file size, aligned to ten characters.
  • %4h: the number of hard links to the file, aligned to four characters.
  • %A: the file type and permissions, in ls -l format.
  • %.10W: the birth time, in seconds since the Unix epoch (with a 10 digit fractional part).
  • The stat invocations above use these formatting options: With coreutils 8.32 or later, ls can display and sort using the birth time, using the -time=birth option: ls -l -time=birth Output similar to that of ls -l can be obtained with stat -c "%A %4h %U %G %10s %.16w %n" - *Īnd sorted output (assuming no filename with newline characters) with stat -c "%.10W %A %4h %U %G %10s %.16w %n" - * | On Linux systems running kernel 4.11 or later, with glibc 2.28 or later, and coreutils 8.31 or later, stat can show a file’s birth time on file systems which store it. Statx() was added to Linux in kernel 4.11 library support was added in glibc 2.28. This is not a standard POSIX interface though, but a Linux specific, says the man: To my knowledge, there is no standard/stable userspace utility allowing us to get this info yet, but it will probably appear in some time. Its API can give access to file creation time, if the info is available on the filesystem.

    #I WANT TO SAVE SOME SORT OF FILE TIME UPDATE#

    UPDATE 2020: since Linux kernel 4.11, a new statx(2) system call has been introduced. Use %W if you don't care about human readable date. That does not sort files by itself though you could try: stat -c '%w %n' * | sort -n UPDATE 2021: according to Thomas Nyman, the above command works on Linux if you have at least coreutils 8.31, glibc 2.28 & kernel 4.11. I tried the stat -c '%w' myfile command on a ext4 filesytem on a (recent enough) Ubuntu system without success (it just answers -). But you may try to have a look at the ext4 API. As Gilles says, it would probably be easier if you'd use a version control system. Now if you want to order files by creation date, I guess this is not easily (nor properly) possible. This command may take some time to return, probably because it also lists every extent related to the file. You would get something like that mentioning crtime ( not ctime!) if you use ext4. debugfs for extN filesystems debugfs -R 'stat partition/relative/path/to/file' /dev/sda1 The -t option will sort by the type of time indicated with the -time option (I suspect birth can be changed by creation if preferred).Īdd -r to reverse the sort order. So to list files sorted by creation/birth date/time, you can use: ls -lt -time=birth UPDATE 2021: the new ls command optionĪccording to Stéphane Chazelas, the ls version from coreutils 8.32 (and glibc 2.28, and kernel 4.11) is now capable of using the new statx(2) system call (see end of this answer) to extract the creation time metadata. Note: this answer mainly covers Linux systems. There is just no standard way to get it, but there is a way: However, some filesystems (as ext4 or XFS), do save this information within the file metadatas. Unfortunately, the stat(2) API does not provide a way to get the file creation time, as it is not required by the Unix standards. In particular, the ctime is always more recent than the mtime (file content modification time) unless the mtime has been explicitly set to a date in the future. The inode change time is updated whenever anything about the file changes (contents or metadata) except that the ctime isn't updated when the file is merely read (even if the atime is updated). Note that the ctime ( ls -lc) is not the file creation time, it's the inode change time.

    i want to save some sort of file time

    The stat utility can show the creation time, called “birth time” in GNU utilities, so under Cygwin you can show files sorted by birth time with stat -c '%W %n' * | sort -k1n.

    i want to save some sort of file time

    #I WANT TO SAVE SOME SORT OF FILE TIME WINDOWS#

    Windows also stores a creation time, but it's not always exposed to ports of unix utilities, for example Cygwin ls doesn't have an option to show it. For example, on Mac OS X (the only example I know of), use ls -tU. If your unix variant has a creation time, look at its documentation. If you need creation time, use a version control system: define creation time as the check-in time. You can't make ls print it because the information is not recorded. Most unices do not have a concept of file creation time.






    I want to save some sort of file time