How do I display a file's last modified date?


 
Thread Tools Search this Thread
Operating Systems AIX How do I display a file's last modified date?
# 1  
Old 10-26-2016
How do I display a file's last modified date?

I'm using a script that I need to get a file's "last modified date" in a format like 01:51:14 PM. We are running on AIX 6.1.0.0. I can't seem to find the right command parameters. Help!

# 2  
Old 10-26-2016
the trick to get the last modified time in epoch:
Code:
cpio -o 2>/dev/null <<EOF | od -d |  awk '
   NR == 2 {print $2 * 65536 - $3;exit}'
   myFile
EOF

Given epoch time, you can convert it to human-readable format.

Do you have truss on AiX?
If so, you may truss this:
Code:
truss -f -v 'lstat,lstat64' ls -d myFile 2>&1 | grep 't ='

I guess in perl you can do it in one swoop.

NOTE: use 'nawk' on Solaris

Last edited by vgersh99; 10-26-2016 at 05:30 PM.. Reason: modified the file name
# 3  
Old 10-26-2016
Quote:
Originally Posted by vgersh99
the trick to get the last modified time in epoch:
Code:
cpio -o 2>/dev/null <<EOF | od -d |  awk '
   NR == 2 {print $2 * 65536 - $3;exit}'
   dccfg_resmgr
EOF

Given epoch time, you can convert it to human-readable format.
I guess in perl you can do it in one swoop.

NOTE: use 'nawk' on Solaris
---------- Post updated at 03:29 PM ---------- Previous update was at 03:28 PM ----------

Thanks for the reply. WHERE do I reference the file I'm waring the date on? HOW can I assign the output of this code to a variable to be used in a script?
# 4  
Old 10-26-2016
Quote:
Originally Posted by mattadams1983
---------- Post updated at 03:29 PM ---------- Previous update was at 03:28 PM ----------

Thanks for the reply. WHERE do I reference the file I'm waring the date on? HOW can I assign the output of this code to a variable to be used in a script?
modified the original reply - now it should be obvious.
# 5  
Old 10-27-2016
What about
Code:
istat "filename"

?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need help with listing file name and modified date on a huge directory

hi, We have a huge directory that ha 5.1 Million files in it. We are trying to get the file name and modified timestamp of the most recent 3 years from this huge directory for a migration project. However, the ls command (background process) to list the file names and timestamp is running for... (2 Replies)
Discussion started by: subbu
2 Replies

2. OS X (Apple)

Arrange file by modified date

Hi, Am performing a find based on filename and result can contain multiple files being found Let's say my find command is find /Archive -f -name 12345.pdf and result of find command is /Archive/Folder A/12345.pdf /Archive/Folder B/12345.pdf please note white space in folder names I... (2 Replies)
Discussion started by: gigagigosu
2 Replies

3. Shell Programming and Scripting

Script to copy creation date over top of modified date?

Can someone draw up a script that for every file, folder and subfolder and files that will copy the creation date over top of the modified date?? I know how to touch every file recursively, but no idea how to read a files creation date then use that to touch the modification date of that file,... (3 Replies)
Discussion started by: toysareforboys
3 Replies

4. Shell Programming and Scripting

Find file by filename or with newest modified date

Hi, I have a directory that has numerous files in it, and there is two which are named "filerec_ddmmyyHH24MMSS" by the time they are created so "filerec_010615012250" was created at 01:22:50 on 1st June 2015. I need to find the most recently created of those 2 files and get the contents of... (4 Replies)
Discussion started by: finn
4 Replies

5. Shell Programming and Scripting

current date modified file

Hi , In my directory , i have many days file but i want to see all those which are of todays date. i tried this but it gives all the files mtime -0 |ls -ltr I tried the below option as well. 19635 find -iname "*.LOG" -mtime 19636 ls -ltr *.LOG -mtime -1 19637 ls -ltr *.LOG... (7 Replies)
Discussion started by: guddu_12
7 Replies

6. Shell Programming and Scripting

Test if a file has a last modified date of within the last 24 hours

Hi there Im trying to find a way to test whether the last modified time is older than 1 day or not so #!/bin/bash if ; then $TOUCHED = "recently" else $TOUCHED = "not so recently" fi ive seen loads of posts where people are using find and the -mtime property but i... (2 Replies)
Discussion started by: rethink
2 Replies

7. UNIX for Advanced & Expert Users

Finding the modified date time of a file

Hi, I am new bie to Unix. Might be a simple question I am asking. I want to find the last modified time of a file and find the difference between the currrent time and the last modified time. Appreciate, if someone can throw some light on what commands can be used. Cheers, James (2 Replies)
Discussion started by: JamesJoe
2 Replies

8. Shell Programming and Scripting

Finding modified File List after the chosen date in Korne Shell...

I am trying to write a Korne Shell asking the user for a date and a directory and then search recursively in this directory the list of files modified after the date chosen. But I am not getting good results when I Test it... #!/usr/bin/ksh echo "Enter a date (YYYYMMDD) " read date touch -t... (2 Replies)
Discussion started by: marconi
2 Replies

9. UNIX for Dummies Questions & Answers

how to retrieve original contents of a modified file (modified using vi)

Made changes to a file using vi editor and saved those changes now realised that the changes are not required How can I get the previous version of the file.i.e the one which was there on which I had made changes (3 Replies)
Discussion started by: novice100
3 Replies

10. UNIX for Dummies Questions & Answers

How do I get the last modified date of a file?

I am trying to load a group of files and their last dates modified into a text file that will in turn be used with SQL*Loader to load these files into Oracle. I am using a *.ksh script. I am getting the name of the file in by using the following: for file_ext in 'cat loaddir.ext'; do find... (2 Replies)
Discussion started by: akpopa
2 Replies
Login or Register to Ask a Question