list of files modified 10 hours ago using grep

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:

Here is the question:

Make a list of files in your home directory that were changed less that 10 hours ago, using grep, but leave out directories.

I just started studying LINUX for about 2 weeks.

  1. Relevant commands, code, scripts, algorithms:

The code should have grep.

  1. The attempts at a solution (include all code and scripts):

ls -l /root | grep -v '^d'

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Linux Programming - CS 310 - Dr. James Hendrikson

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).

1) Make a list of files in your home directory

so, use /home/username

2) ls -l /home/username | grep -v "^d"

The above command will give only the files which is present under your home directory

3) If you want to use only grep command, then first you have to find out the current hour using

date +%H

4) Then read the lines one by one and extract the hour and do the comparsion. (But it is very tricky part), as you need to calculate and compare the date for some time (example : if the current time is 03:00, then you need to list the files which is having the time as 17:00 or less of last day )

5) Best approach is use find command instead of grep command.

[MAN="find"]
find
[/MAN]

thank you so much!

For your home directory, instead of using /home/username, you should use the $HOME environment variable, which is almost* guaranteed to be set. Some (but not all!) shells support tilde expansion as in ~/ expands to ${HOME}/.

  • There are some odd circumstances where this is not true, but you will likely not encounter them during your coursework.