Solved

Display file Modified date in other directory

Posted on 2006-06-28
4
4,412 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

695 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