?
Solved

Display file Modified date in other directory

Posted on 2006-06-28
4
Medium Priority
?
4,421 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…

650 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