Solved

Display file Modified date in other directory

Posted on 2006-06-28
4
4,408 Views
Last Modified: 2008-01-09
Hi Experts,
I have to get the file modified date of test.out .I am  using this command

echo `ls -l test.out | awk '{print $7}`-`ls -l test.out | awk '{print $6}`-`ls -l test.out | awk '{print $8}`

The file test.out is available in UNIX directory
stud50:/csim/data01/test.out

However ,I need to display file modified date of test.out in other directory
 stud50:/csim/stddata/

Please help.

Thanks
0
Comment
Question by:srpendyala
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 3

Expert Comment

by:yuseungkim
ID: 17004957
Why don't you put absolute path of test.out file instead of relative path. i.e. ls -l /csim/stddata/test.out

and you'd better change your command like as....

ls -l test.out | awk '{ printf ("%s-%s-%s\n", $7, $6, $8); }'

And one more thing is that if file is created other than this year, 8th column has year information instead of Time information

Andy K
0
 
LVL 4

Expert Comment

by:Phreonx
ID: 17005227
Hello,
first a clarification. Are you using:

echo `ls -l test.out | awk '{print $7}`-`ls -l test.out | awk '{print $6}`-`ls -l test.out | awk '{print $8}`

to just get the Modification date of test.out? Try:

ls -la test.out | awk '{print $6}'

instead. That should output something like this:

2006-06-29

Your question is not very clear. First assumption: You might be asking how you can set the modification date of /csim/stddata/ to that of test.out.
Second assumption: You are trying to output the Modification date of test.out to a separate file located in/csim/stddata/

First case: You want to set the modification date of /csim/stddata/ to that of test.out. Try this:

touch -d `ls -la test.out | awk '{print $6}'`/csim/stddata/

Second case: You are trying to output the Modification date of test.out to a separate file located in/csim/stddata/. Try this:

ls -la test.out | awk '{print $6}' >> /csim/stddata/ModificationDates.out

I don't know if this information is the answer to what you're asking. If not then, please be more precise.

Hope that helped ;)
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17026162
> echo `ls -l test.out | awk '{print $7}`-`ls -l test.out | awk '{print $6}`-`ls -l test.out | awk '{print $8}`
is wrong shell syntax (mixed and unmatched quotes and backticks)

I guess you mean something like  yuseungkim suggested:

ls -l `df|awk '/^stud50:\/csim\/stddata/{print $NF}'`/test.out|awk '{printf("%s-%s-%s\n",$7,$6,$8);}'
0
 
LVL 6

Accepted Solution

by:
JJSmith earned 500 total points
ID: 17047543


find / -name test.out -exec ls -l {} \; | awk 'NF==9{ printf ("%s-%s-%s-%s\n", $7, $6, $8, $9); }'

should list date-time and path-file for all test.out files on your system.

if you're not a super-user you may want to throw a " 2> /dev/null " on the end of the command - less the quotes of course!


Cheers
JJ
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question