Find command to get the timestamps


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find command to get the timestamps
# 1  
Old 03-24-2003
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  
Old 03-24-2003
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  
Old 03-24-2003
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  
Old 03-24-2003
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  
Old 03-24-2003
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  
Old 03-24-2003
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  
Old 03-24-2003
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find file between timestamps Query

On my linux box, I have a file say dump.txt. I then need to move to another seperte folder and need to find only one file with extension *.tar that has the closest timestamp after / next to the timestamp of the dump.txt. (2 Replies)
Discussion started by: mohtashims
2 Replies

2. Shell Programming and Scripting

Find matching timestamps in two files.

OK. if the first file is : 3184 2014-07-28 04:15 global.Remote-Access 10.111.8.25 81.245.6.25 tcp 3268 3035 2014-07-28 04:16 global.Remote-Access 10.111.8.12 81.245.6.25 tcp 3268If the second file is: 1 Jul 28 04:12 2014-07-28 id967254(BGC-TLW-Cert) Tunneling: User with IP... (8 Replies)
Discussion started by: fxsme
8 Replies

3. Shell Programming and Scripting

How to use grep & find command to find references to a particular file

Hi all , I'm new to unix I have a checked project , there exists a file called xxx.config . now my task is to find all the files in the checked out project which references to this xxx.config file. how do i use grep or find command . (2 Replies)
Discussion started by: Gangam
2 Replies

4. Linux

Simplified find command to find multiple file types

Hi, I'm using the following command to find the multiple requierd file types and its working fine find . -name "*.pl" -o -name "*.pm" -o -name "*.sql" -o -name "*.so" -o -name "*.sh" -o -name "*.java" -o -name "*.class" -o -name "*.jar" -o -name "*.gz" -o -name "*.Z" -type f Though... (2 Replies)
Discussion started by: vickramshetty
2 Replies

5. AIX

How to find time difference between 2 timestamps?

HI All, can some one please help me how to fine the difference between two time stamps say a= Nov 10, 2009 9:21:25 AM b= Nov 10, 2009 10:21:25 AM I want to find difference between the a & b I googled and tried with some options but no luck. My OS is AIX (1 Reply)
Discussion started by: bandlan9
1 Replies

6. UNIX for Dummies Questions & Answers

how to find difference of 2 timestamps in secs?

I have a requirement to find the time difference in second between 2 given time stamps. An example scenario is shown below: 30 Oct 11:42:29:992 DEBUG org.apache.commons.digester.Digester - New match='form-validation/global/validator' (IID=, TID=) 30 Oct 11:42:29:993 DEBUG... (0 Replies)
Discussion started by: Alecs
0 Replies

7. Shell Programming and Scripting

Little bit weired : Find files in UNIX w/o using find or where command

Yes , I have to find a file in unix without using any find or where commands.Any pointers for the same would be very helpful as i am beginner in shell scritping and need a solution for the same. Thanks in advance. Regards Jatin Jain (10 Replies)
Discussion started by: jatin.jain
10 Replies

8. UNIX for Advanced & Expert Users

mv command and file-timestamps

Hi all, I need help to find out if it is possible (if so, how? :D ) to move a hard link to a given file without making the main file i-node modification time change. That is: I have a file myFile.txt , and I have a link myLink.dat to that file (obtained by: ln myFile.txt myLink.dat).... (1 Reply)
Discussion started by: gian1975
1 Replies

9. UNIX for Dummies Questions & Answers

find command not giving file names accord. to timestamps

Currently iam working on solaris environment, Iam using find command to get list of all files between any two given dates. But the find command is not listing files accord. to timestamp. I tried using -exec option as -exec ls -ltr {} \; Still the files are not listed according to timestamp..... (8 Replies)
Discussion started by: thanuman
8 Replies

10. Shell Programming and Scripting

command find returned bash: /usr/bin/find: Argument list too long

Hello, I create a file touch 1201093003 fichcomp and inside a repertory (which hava a lot of files) I want to list all files created before this file : find *.* \! -maxdepth 1 - newer fichcomp but this command returned bash: /usr/bin/find: Argument list too long but i make a filter all... (1 Reply)
Discussion started by: yacsil
1 Replies
Login or Register to Ask a Question