The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to find a file named vijay in a directory using find command amirthraj_12 UNIX for Dummies Questions & Answers 6 10-25-2008 12:37 PM
how to find difference of 2 timestamps in secs? Alecs UNIX for Dummies Questions & Answers 0 03-24-2008 12:36 PM
mv command and file-timestamps gian1975 UNIX for Advanced & Expert Users 1 07-04-2006 10:01 AM
find command not giving file names accord. to timestamps thanuman UNIX for Dummies Questions & Answers 8 09-07-2004 09:04 AM
command find returned bash: /usr/bin/find: Argument list too long yacsil Shell Programming and Scripting 1 12-15-2003 06:38 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-24-2003
nguda nguda is offline
Registered User
  
 

Join Date: May 2002
Posts: 25
Find command to get the timestamps

I want to have the timestamps of the files containing a specific string in them.
I have tried using different combinations of find command and grep and ls but not giving the desired output.

find $HOME/bin/shells -name "*" -print -exec ls -Flt {} -exec grep -i "abc" '{}' \;

Please help.
  #2 (permalink)  
Old 03-24-2003
Perderabo's Avatar
Perderabo Perderabo is online now Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,114
When you do something like this, each time that ls runs, it will be with a single file name. So using -l to sort the output doesn't make sense.

And your -name "*" is going to match everything.

find $dir -type f -exec grep -q abc {} \; -exec ls -Fl {} \;

is the syntax that comes closest to what you're trying to do. Only if the first exec succeeds will the second exec be attempted. The order is important.
  #3 (permalink)  
Old 03-24-2003
nguda nguda is offline
Registered User
  
 

Join Date: May 2002
Posts: 25
Thanks for the reply.
I am using the same command and it is funny that even though I use ls -Fl, the list is not in that order. I am trying to get the list with latest file top in the list. ls -Fl should do that. But I don't understand why it is not doing. Below is my command.

find $dir -name "*" -exec grep -q "abc" {} \; -exec ls
-Flt {} \; | awk '{print $8}' | read timestamp.

I am expecting to have timestamp = Latest file time stamp.

Please suggest. Thank you.
  #4 (permalink)  
Old 03-24-2003
Perderabo's Avatar
Perderabo Perderabo is online now Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,114
It's like I said, each line is output by an individual execution of ls.
ls -lt a b c
can sort the lines that are output. But
ls -lt a ; ls -lt b ; ls -lt c
cannot.
  #5 (permalink)  
Old 03-24-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Since you're looking for every file, there's no need for the find command:

l -t `grep -lF 'abc' $HOME/bin/shells/*` | awk '{print $6,$7,$8}'

Last edited by oombera; 03-24-2003 at 12:27 PM..
  #6 (permalink)  
Old 03-24-2003
nguda nguda is offline
Registered User
  
 

Join Date: May 2002
Posts: 25
Sorry I do not understand.
Do you think I can get the latest file on the top of the list with the above command? (or if we modify it)?

Thanks for the help.
  #7 (permalink)  
Old 03-24-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
I included the -t option with the "l" command to sort by date, newest first. Give it a try and see if it does what you need. Are you only trying to print the date to the screen, or other information (such as filename) too?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0