LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-13-2015, 09:12 AM   #1
andrew.comly
Member
 
Registered: Dec 2012
Distribution: Trisquel-Mini 7.0, Lubuntu 14.04, Debian lxde 8.0
Posts: 311
Blog Entries: 2

Rep: Reputation: 16
Question Can't use grep to find files modified within 10 hours ago.


I am currently reading the online book Bash Beginners' Guide (http://www.tldp.org/LDP/Bash-Beginne...ect_04_05.html), and am trying to complete Chapter 4.5. Exercises. Question 7 asks:
Make a list of files in your home directory that were changed less that 10 hours ago, using grep, but leave out directories.

I really think this question is strange, since no matter how many times I look at the manpages for grep, it simply never mentions modification time. However after doing some research on the web, I can now find all the files(not documents) changed less than 10 hours ago via "find":
Code:
find /media/a/LG/AC/ -maxdepth 1 -type f -mmin -600
The part of this questions that tells people to leave out directories isn't hard, since whenever you want to exclude something you can just find everything except for <yourString> via "grep -v", where "v" is short for inverse.

However, the part about "changed less that 10 hours ago" just doesn't seem plausible. Did the author mix up the word "grep" and "find"? Can "grep" be used to find a file modified within a certain amount of time?

Last edited by andrew.comly; 09-13-2015 at 09:16 AM.
 
Old 09-13-2015, 09:26 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,867
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Dunno, maybe the solution might include 'ls -l' and 'date'
 
1 members found this post helpful.
Old 09-13-2015, 10:30 AM   #3
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
Use find with the option that mimics ls -l

find -ls

Last edited by goumba; 09-13-2015 at 10:55 AM.
 
1 members found this post helpful.
Old 09-13-2015, 11:43 AM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,782

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
Originally Posted by andrew.comly View Post
However after doing some research on the web, I can now find all the files(not documents) changed less than 10 hours ago via "find":
I think "find" is the correct tool for this, the exercise writer made a mistake.

Quote:
The part of this questions that tells people to leave out directories isn't hard, since whenever you want to exclude something you can just find everything except for <yourString> via "grep -v", where "v" is short for inverse.
But see also grep's --directories option:
Quote:
-d action
--directories=action
If an input file is a directory, use action to process it. By default, action is ‘read’, which means that directories are read just as if they were ordinary files (some operating systems and file systems disallow this, and will cause grep to print error messages for every directory or silently skip them). If action is ‘skip’, directories are silently skipped. If action is ‘recurse’, grep reads all files under each directory, recursively, following command-line symbolic links and skipping other symlinks; this is equivalent to the -r option.
 
2 members found this post helpful.
Old 09-13-2015, 11:44 AM   #5
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
Originally Posted by andrew.comly View Post
However, the part about "changed less that 10 hours ago" just doesn't seem plausible. Did the author mix up the word "grep" and "find"?
I applaud you for not trying to use a screwdriver for hammering a nail. You are right of course, nobody would use grep for that, and I think it's a silly exercise. However, you are not alone. Read more at SO:
http://stackoverflow.com/questions/1...s-ago#17509507

Best regards,
HMW
 
3 members found this post helpful.
Old 09-26-2015, 10:43 PM   #6
andrew.comly
Member
 
Registered: Dec 2012
Distribution: Trisquel-Mini 7.0, Lubuntu 14.04, Debian lxde 8.0
Posts: 311

Original Poster
Blog Entries: 2

Rep: Reputation: 16
The exercise is truly defective.

Anyway, what's important is that I have learned how to make a list of files in a users home directory that were changed less that 10 hours ago, leaving out directories.

Last edited by andrew.comly; 09-26-2015 at 10:43 PM. Reason: spacing
 
  


Reply

Tags
bash, find, grep, modification



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to use cp find and grep together to copy a list of files using find with grep babhijit Linux - Newbie 10 07-03-2013 12:25 PM
[SOLVED] get disk usage of files modified in last 24 hours izzabdullah Linux - Server 1 04-19-2012 04:18 PM
Howto find out files that are changed less than 10 hours with grep command coolloo_djack Programming 1 03-20-2010 01:05 PM
Finding files modified n minutes ago tucs_123 AIX 5 10-09-2009 12:59 AM
bash scripting - how long ago file was modified brian0918 Programming 3 06-19-2003 04:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration