Display file Modified date in other directory

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

However ,I need to display file modified date of test.out in other directory

Please help.

Question by:srpendyala

Expert Comment

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

Expert Comment

ID: 17005227
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:


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 ;)
LVL 51

Expert Comment

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);}'

Accepted Solution

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!


Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
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…
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 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.:

821 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