[SOLVED] Can't use grep to find files modified within 10 hours ago.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.