LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-19-2010, 03:51 AM   #1
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 234

Rep: Reputation: 18
finding files exactly 7 days old


hi
i am a newbie in linux ,i am writing a bash script to identify the files which are exactly 7 days ( a week old)
i tried this command
find /var/backup -mtime +7 -exec ls -d {} \;
but this gives me even the files which are older than 7 days

[root@proxy access]# find . -mtime +7 -exec ls -d {} \;
./access.log.1.gz
./access.log.2.gz
./access.log.2.gz19Apr10
./access.log.3.gz
./access.log.3.gz19Apr10
./access.log.4.gz

[root@proxy access]# ll
-rwxrwxrwx 1 root root 48869073 Mar 7 04:02 access.log.4.gz
-rwxrwxrwx 1 root root 53259282 Mar 14 04:03 access.log.3.gz
-rwxrwxrwx 1 root root 58549296 Mar 21 04:03 access.log.2.gz
-rwxrwxrwx 1 root root 72788051 Mar 28 04:03 access.log.1.gz
-rwxrwxrwx 1 root root 68077106 Apr 4 04:03 access.log.3.gz19Apr10
-rwxrwxrwx 1 root root 70632288 Apr 11 04:03 access.log.2.gz19Apr10
-rwxrwxrwx 1 root root 68914245 Apr 18 04:03 access.log.1.gz19Apr10

i want only the file which is 7 days old
 
Old 04-19-2010, 04:26 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You can try something like:
Code:
find . -daystart -mtime 7
where -daystart measures time from today at 00:00. You can find more details on the GNU findutils manual, here.
 
Old 04-19-2010, 04:30 AM   #3
bakdong
Member
 
Registered: Apr 2009
Posts: 214

Rep: Reputation: 44
info find shows this:

-- Option: -daystart
Measure times from the beginning of today rather than from 24 hours
ago. So, to list the regular files in your home directory that
were modified yesterday, do

find ~ -daystart -type f -mtime 1

Bear in mind that mtime is the modification time, there are also tests for the atime and ctime which you might like to examine.

+ and - before the time gives you a range, so +1 giver everything 1 day and older.

If you actually want files that are exactly 7 days old from the current time, don't use daystart.
 
Old 04-19-2010, 04:59 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by bakdong View Post
If you actually want files that are exactly 7 days old from the current time, don't use daystart.
True. To clarify, using -daystart and -mtime 7 from today (2009-04-19) you will find files last modified between 2009-04-12 00:01 and 2009-04-13 00:00.

Without -daystart you have to consider files modified 7*24 hours ago from the current time, always in the range of 24 hours. Suppose now is 11:55, using only -mtime 7 you will find files modified between 2009-04-11 11:56 and 2009-04-12 11:55.
 
  


Reply



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] Delete old files older than 7 days anon091 Linux - Newbie 3 09-18-2009 01:15 PM
Script help - delete files older than 45 days but exclude the system files jojothedogboy Linux - Software 3 06-13-2008 03:43 PM
Finding files and then finding content within those files... Maeltor Linux - Software 5 03-13-2007 12:06 PM
which files have modified in the last few days ? varun_saa Mandriva 6 03-10-2007 10:34 AM
help with a script that deletes files more than X days old BrianK Linux - General 5 06-14-2004 09:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:33 AM.

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