Or the ones modified more than one day, five hours ago: $ find foo -name database-agent* -mtime -1d5h -ls
to find the files last modified in the last one day, five hours): $ find foo -name database-agent* -not -newermt "14:00" -newermt "12:00" -ls Or we could even find the ones last modified between noon and 2 p.m.: In Unix-like and some other operating systems, find is a command-line utility that locates files based on some user -specified criteria and either prints the pathname of each matched object or, if another action is requested, performs that action on each matched object. So, if I want to get the files after noon, I could write the following: Use the output of one command as the command-line argument(s) to another command. I discovered that this type of filtering is actually quite easy to do with the "find" command. Use find to find files and directories whose names match simple patterns. rw-r-r- 1 markneedham wheel 3.1K 23 Jun 11:49 foo/īut I wanted to split the files in half so that I could have the ones created before and after noon on June 23. rw-r-r- 1 markneedham wheel 3.1K 23 Jun 11:49 foo/
rw-r-r- 1 markneedham wheel 3.9K 23 Jun 13:44 foo/
sort on last digit of month) -k 2 : Select 2nd field and sort it out. k 2.9 : Select 2nd filed and 9th character for sorting (i.e sort on last digit of year) -k 2.5 : Select 2nd field and 5th character for sorting (i.e. rw-r-r- 1 markneedham wheel 3.8K 23 Jun 13:44 foo/ How do I sort by date in Unix Multilevel sort -n : sort numeric data. rw-r-r- 1 markneedham wheel 13K 23 Jun 13:44 foo/ rw-r-r- 1 markneedham wheel 2.8K 23 Jun 13:44 foo/ rw-r-r- 1 markneedham wheel 2.7K 23 Jun 11:49 foo/ rw-r-r- 1 markneedham wheel 9.5K 23 Jun 11:49 foo/ rw-r-r- 1 markneedham wheel 5.8K 23 Jun 14:00 foo/ rw-r-r- 1 markneedham wheel 2.5K 23 Jun 14:00 foo/ And I want the time varies from 09:00-09:05. I want the 'Jan 18 09:00' not hard coded, I want it coming from the system date and time. I know this command: ls -ltr /system1/.505 grep 'Jan 18 09:00'. rw-r-r- 1 markneedham wheel 12K 23 Jun 13:44 foo/ Hi, I wanna to find files with specific date and time. rw-r-r- 1 markneedham wheel 4.8K 23 Jun 14:00 foo/ rw-r-r- 1 markneedham wheel 3.8K 23 Jun 13:44 foo/ rw-r-r- 1 markneedham wheel 11K 23 Jun 13:44 foo/ rw-r-r- 1 markneedham wheel 8.6K 23 Jun 11:49 foo/ rw- 1 greys greys 7335 Oct 20 17:22 /home/greys/.bash_history You can use the exec option of the find command to invoke ls command and show timestamps for each file: :~ $ sudo find /var/log -mtime 0 -exec ls -ld \ ĭrwx- 4 greys greys 4096 Sep 21 21:30 /home/greys Thi can be useful for identifying current log files, like this: :~ $ sudo find /var/log -mtime 0Įach of the files from this list has been updated today. Typical ways of using find mtime are shown below. Find command has a great operator for narrowing down the list of results: mtime.Īs you probably know from the atime, ctime and mtime post, the mtime is a file property confirming the last time the file was modified.įind uses mtime option to identify files based on when they were modified.