Grep for modified time


 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Grep for modified time
# 1  
Old 11-11-2009
Grep for modified time

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

is it possible to come up with a list of files that are modified before a certain number of hours only using the grep command?

ex. list files that were modified less than 10 hours ago

i've only managed to list files that were created on the same day, i can't seem to figure out how to work the time.

2. Relevant commands, code, scripts, algorithms:

grep

3. The attempts at a solution (include all code and scripts):
Code:
ls -ul | grep `date +%Y-%m-%d`


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
p.61 Bash Guide for Beginners tld.org

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
# 2  
Old 11-11-2009
I'm not sure where you are going wrong (because you haven't shown what you actually did), but notice the difference between these on my machine:

Code:
bash-2.05a$ ls -ul | head -3
total 5377
-rw-r--r--  1 pcunix  pcunix           236367 Oct  6 14:37 h
-rw-r--r--  1 pcunix  pcunix              310 Aug 30 06:38 Girish
bash-2.05a$ ls -ul | head -4
total 5377
-rw-r--r--  1 pcunix  pcunix           236367 Oct  6 14:37 h
-rw-r--r--  1 pcunix  pcunix              310 Aug 30 06:38 Girish
-rw-r--r--  1 pcunix  pcunix             5471 Sep  5 13:59 Voila.html
bash-2.05a$ ls -ut | head -4
qa
tmp
world
wtoday
bash-2.05a$ ls -lut | head -4
total 5377
drwxr-xr-x  2 pcunix  pcunix              512 Nov 11 03:04 qa
drwxr-xr-x  2 pcunix  pcunix              512 Nov 11 03:04 tmp
drwxr-xr-x  4 pcunix  pcunix             9216 Nov 11 03:04 world
bash-2.05a$ ls -lt | head -4
total 5377
-rw-r--r--  1 pcunix  pcunix               13 Nov 10 20:42 dt
-rw-r--r--  1 pcunix  pcunix           360351 Nov 10 18:18 t
drwxr-xr-x  4 pcunix  pcunix             9216 Nov  8 21:24 world

# 3  
Old 11-11-2009
head command shows the top lines. i need a grep command that outputs files modified in the last 10 hours. so the output could be 20 files, or none, depending on modification time.

what i've come up with narrows the files down to whatever was modified during the current day, but i can't figure out how to screen for time

Code:
mo@mo-laptop:~$ ls -ul | grep `date +%Y-%m-%d`
-rw-r--r--  1 mo mo     4045 2009-11-12 09:09 Grated Parmesan.mm
-rw-r--r--  1 mo mo    14682 2009-11-12 09:09 statusrep.mm

# 4  
Old 11-12-2009
What TonyLawrence was getting at was that you should carefully look at the output of "ls -ul". He was using the "head"-command only to limit the output to the relevant lines.

Have a look at the various possibilities of displaying a directory entry of a file Unix uses. (Notice there are different forms of displaying the date information in older and younger files.)

"grep" filters out certain lines of some output text. Ask yourself if there is a common text pattern that sets apart all the files you are interested in and all the files you are not interested in. If there is such a thing you know you can use "grep" for the task on the premise you can construct a regular expression to cover that pattern. If there is no such thing then "grep" cannot (not even in theory) be supposed to be a suitable tool.

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

IF loop to check the time modified

Hi Frnds, i have a folder test in which files generated daily how to chek the files that are modified on that day as a condition for ex, if then echo "i have got something to do with the file" else echo" sorry" fi i will have more than 3 to 4 files that are modified today. and if... (5 Replies)
Discussion started by: mahesh300182
5 Replies

2. Shell Programming and Scripting

Reg file modified time

Hi, I have modified one file today. So if i give `ls -lrt filename` command it will show the current modified time. But i wanted to know what is the previous modified time for this file Is there any way to find this Thanks, Puni (3 Replies)
Discussion started by: puni
3 Replies

3. Shell Programming and Scripting

Grep for modified time

is it possible to come up with a list of files that are modified before a certain number of hours only using the grep command? ex. list files that were modified less than 10 hours ago i've only managed to list files that were created on the same day, i can't seem to figure out how to work... (3 Replies)
Discussion started by: momo.reina
3 Replies

4. Shell Programming and Scripting

Compare Last Modified Time across Time Zone

Hi, I'm new to shell script programming, I only have Java programming background. I'm writing a shell script to do file synchronization between 2 machines that located at different time zone area. Both machine were set its time zone according to its geographical location (Eg: server is at... (1 Reply)
Discussion started by: python
1 Replies

5. Shell Programming and Scripting

changing modified time

How to change the modified time of a file to any specified time. ls -ltr drwxr-xr-x 2 pipe pipe 4096 Jun 10 10:33 coredump_06062008 ---------------------------------------------------------------------- here file coredump_06062008 last modified time is Jun 10 10:33 and i... (1 Reply)
Discussion started by: ali560045
1 Replies

6. Shell Programming and Scripting

Getting modified time & filename only

Hi, When we use "ls -l" we are getting like below, -rw-r--r-- 1 mdskl mds 4161479 Apr 12 14:57 VTTF2008.20080412145748.cc But i need only modified time and filename only like below, Apr 12 14:57 VTTF3008.20080412145748.cc Thanks-:) Senthil (4 Replies)
Discussion started by: senthil_seera
4 Replies

7. HP-UX

Time Modified Issue Please Assist

I am trying to periodically check that the environment variables have not been changed on a HP-UX server. This was going to be easy except I ran into the odd circumstance of having two files that should be created equally be created differently when one is created by command line and the other is... (1 Reply)
Discussion started by: Emancipator
1 Replies

8. Shell Programming and Scripting

getting last accessed and modified time together

actually, i'm making an Intrusion Detection System for education purpose (for project) using Bourne shell. The problem I get in that is:- 1. My application should check if there's some modification or alteration in the directory. 2, For that thing, I need to have every attribute of file and... (1 Reply)
Discussion started by: raku05
1 Replies

9. UNIX for Dummies Questions & Answers

Checking modified time of files

My problem is with the find command. After looking through the forum I've got - find . -mtime 2 -name "*" which gives me a list of all the files modified in the last 2 days. How do I change this to list files modified in the last 2 hours? Sorry if this question is already on the forum... (4 Replies)
Discussion started by: am97395331
4 Replies

10. UNIX for Advanced & Expert Users

Modified time

How do you change the modified time of a file on UNIX?? (4 Replies)
Discussion started by: frank
4 Replies
Login or Register to Ask a Question