Solved

Display file Modified date in other directory

Posted on 2006-06-28
4
4,399 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
4 Comments
 
LVL 3

Expert Comment

by:yuseungkim
Comment Utility
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
Comment Utility
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
Comment Utility
> 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
Comment Utility


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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now