behavior of find utility's -mtime -7 primary


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting behavior of find utility's -mtime -7 primary
# 1  
Old 02-24-2016
behavior of find utility's -mtime -7 primary

Can I ask a question not related to original question. I have this below command running on a directory which contains thousands of files. This command runs for 5 minutes. Any files received in folder1 during the execution of command is getting moved, even though that file is just received and it's not 7 days old as required in command.
Code:
find /folder1 -type f ! -mtime -7 -exec mv {} /folder2 \;


Last edited by Don Cragun; 02-24-2016 at 02:58 PM.. Reason: Get rid of FONT and SIZE tags; add CODE and ICODE tags.
# 2  
Old 02-24-2016
Moderator's Comments:
Mod Comment No. Please do not hijack a thread by posting a new topic in an existing thread. Create a new thread for a new topic.

I have moved this post into a new thread for you this time.

You haven't asked to move files that are exactly 7 days old; you have asked to move files that are less than 7 days old.
  • -mtime +7 more than 7 days old
  • -mtime 7 exactly 7 days old
  • -mtime -7 less than 7 days old
# 3  
Old 02-24-2016
Thanks. I am new user. I am learning. I couldn't find a way to create a new topic.
I know -mtime -7 means less than 7 days old, but there is a ! which actually inverts the sign. This is weird. But that's the way someone wrote that code in my organization few years back.
Thanks again.

Last edited by Don Cragun; 02-24-2016 at 03:48 PM.. Reason: Add ICODE tags.
# 4  
Old 02-24-2016
Quote:
Originally Posted by Super123
Thanks. I am new user. I am learning. I couldn't find a way to create a new topic.
I know -mtime -7 means less than 7 days old, but there is a ! which actually inverts the sign. This is weird. But that's the way someone wrote that code in my organization few years back.
Thanks again.
Moderator's Comments:
Mod Comment In the middle of the Home page for the UNIX & Linux Forums you'll see a list of the available sub-forums. Select the sub-forum in which you want to create your new thread. Then there will be a "New Thread" button under the bottom left corner of the box at the top of the page containing that sub-forum's name. Click on that button to create your new thread.


Sorry, I didn't notice the ! in ! -mtime -7. That would mean 7 or more days old (not just 7 days old) which could also be written as -mtime +6.

The standards state:
Quote:
If a file is removed from or added to the directory hierarchy being searched it is unspecified whether or not find includes that file in its search.
but that does not give an implementation the right to include a new file in the search and ignore the selection criteria. The behavior you're describing sounds like a bug in find on your system.
This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 02-24-2016
Thanks Don for your response..
I did a test. I started a program which writes lots of data in a file and it takes some time. While the file is still being written and not been committed, i did istat on that file, it shows modified time as -----. I guess that Find command is not able to calculate time on junk like --- and it faults.
# 6  
Old 02-24-2016
When a file is created, its last data access timestamp, last data modification timestamp, and last status change timestamp are all marked for update. Any timestamps marked for update are required by the standards to be updated before a successful completion of any of the following functions/system calls on that file: fstat(), fstatat(), fsync(), futimens(), lstat(), stat(), utime(), utimensat(), or utimes().

While it would theoretically be possible for the istat and find utilities to read the i-nodes for the files they are processing directly from the disks on which the filesystems are located, any sane utility writer would use fstat() after getting the file's name from reading the directory being processed. And, since the fstat() is required to update the timestamps before returning the status information to the caller, what you are seeing from istat should not happen on a system that conforms to the standards. (Note, however, that some filesystems have options that can be used when they are mounted that make the filesystems "more responsive" by ignoring standard requirements. If the filesystem you're working in was mounted with one of these options, you might want to ask your system administrator to change the mount options used so your code will work correctly instead of working incorrectly slightly faster.)
# 7  
Old 02-25-2016
Yes it looks like an exotic file system type or an exotic mount option.
To find out the fs type do
Code:
df /folder1

and its mount options are
Code:
mount -v | grep <fs type>

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find by name and mtime

Hi, I'm trying to find all files that have a .ksh and .p extension and that are 7 days old by using the below find command but it doesn't seem to as expected. It gives me random results.. Can someone point out what may be wrong? find . -name "*.ksh" -o -name "*.p" -mtime -7 (2 Replies)
Discussion started by: Jazmania
2 Replies

2. UNIX for Dummies Questions & Answers

Find using mtime

Hi, so I was using mtime and its not behaving the way I would think its supposed too. I have two pdf files. One modified today and another 6 months ago. I upload them to the solaris server. Then I run the below find statements. This finds my 2 files find *.pdf -type f -name '*.pdf' this finds... (2 Replies)
Discussion started by: vsekvsek
2 Replies

3. Shell Programming and Scripting

find -mtime +7

Dear all, find $ADMIN_DIR/$SID/arch/ -name '*.gz' -mtime +7 -exec rm {} \; is it retaining 7 days OR 8 days .gz files ? Thanks Prakash (10 Replies)
Discussion started by: prakashoracledb
10 Replies

4. Shell Programming and Scripting

Find + prune + mtime

Hi, i try to catch all files in a dir ,without going down in subdir , which don't have file extension and older than 10 days for example: my dir : drwxr-xr-x 7 notes01 notes 4096 Mar 8 14:11 . drwxr-xr-x 116 root system 4096 Mar 9 11:17 .. -rw-r----- 1 notes01... (4 Replies)
Discussion started by: Nicol
4 Replies

5. UNIX for Dummies Questions & Answers

find mtime syntax

Hi guys, I am looking for a way of moving all files out of a directory with a time stamp greater then the one I specify. Can anyone suggest a way of doing so? For example, move all files out of dir1 which were created after 17:00 into dir2. Thanks :) (1 Reply)
Discussion started by: JayC89
1 Replies

6. UNIX for Dummies Questions & Answers

(find) mtime vs. (unix) mtime

Hi I've made some test with perl script to learn more about mtime... So, my question is : Why the mtime from findfind /usr/local/sbin -ctime -1 -mtime -1 \( -name "*.log" -o -name "*.gz" \) -print are not the same as mtime from unix/linux in ls -ltr or in stat() function in perl : stat -... (2 Replies)
Discussion started by: hiddenshadow
2 Replies

7. UNIX for Dummies Questions & Answers

find -mtime query

Hello everyone, I have got two queries: 1) I want to do some work on files that were last modified yesterday. Will find ... -mtime -2 be correct or -mtime-1? 2)What about finding files that were modified today? Will it be -mtime -0 or -mtime -1? Thanks. (1 Reply)
Discussion started by: Rajat
1 Replies

8. UNIX for Dummies Questions & Answers

problem with find and mtime

I am using HP-UNIX , The below command doesnt display anything although i have changed a file in the directory by toutch -t 200010101800 nfile find /tmp/transfer/ -name "*.*" -mtime +1 Any problrm with the find command i written . .Please help ??.. Thanks, Arun (4 Replies)
Discussion started by: arunkumar_mca
4 Replies

9. UNIX for Dummies Questions & Answers

find . -mtime

...what am i doing wrong?? I need to find all files older than 30 days and delete but I can't get it to pull details for ANY + times. The file below has a time stamp which is older than 1 day, however if I try and select it using any of the -time flags it just doesn't see it. (the same thing... (1 Reply)
Discussion started by: topcat8
1 Replies

10. UNIX for Dummies Questions & Answers

find -mtime off by one day?

If I use the find command to find files older than n days I have to enter find . -mtime +(n-1). I tried this on a Solaris 9 system and also Linux. Is this something that all Unix veterans know about (I'm new to Unix)? If so, maybe my man pages need to be updated (how to do this?). :confused: (4 Replies)
Discussion started by: ceanntrean
4 Replies
Login or Register to Ask a Question