Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-13-2012
Registered User
 
Join Date: Jul 2008
Location: Richmond, Virginia
Posts: 46
Thanks: 14
Thanked 9 Times in 7 Posts
Behaviour of "find" command

Hi,

I'm trying to understand why the find command below is not listing a directory which was modified long back from the number of days specified in the mtime part.


Code:
user-aster :/mydir
$ ls -ld 1607570a-4fed44bb-4988
drwxr-xr-x  3 xyz abc 4096 Jun 29 01:02 1607570a-4fed44bb-4988
user-aster :/mydir
$ find . -type d -mtime +14
./1607570a-4fe95e03-14fb
./1607570a-4fe95e03-14fb/.mdir
user-aster :/mydir
$ uname -a
Linux aster 2.6.9-100.ELsmp #1 SMP Tue Feb 1 12:17:32 EST 2011 i686 i686 i386 GNU/Linux

If you see above, the directory "1607570a-4fed44bb-4988" doesn't show up in the find command. Can anyone point out why this is happening?

Thanks in advance.
Sponsored Links
    #2  
Old 07-13-2012
in2nix4life's Avatar
Registered User
 
Join Date: Oct 2007
Location: East Coast
Posts: 308
Thanks: 0
Thanked 69 Times in 67 Posts

Code:
ls -ld 1607570a-4fed44bb-4988
drwxr-xr-x 2 xxxx xxxx 40 Jun 29 01:02 1607570a-4fed44bb-4988

find . -mtime +13 -type d
./1607570a-4fed44bb-4988

The Following User Says Thank You to in2nix4life For This Useful Post:
aster007 (07-13-2012)
Sponsored Links
    #3  
Old 07-13-2012
Registered User
 
Join Date: Jul 2008
Location: Richmond, Virginia
Posts: 46
Thanks: 14
Thanked 9 Times in 7 Posts
Thanks in2nix4life!
But why does having 13 in mtime giving the correct output, when its 14 days past the file creation.
    #4  
Old 07-13-2012
in2nix4life's Avatar
Registered User
 
Join Date: Oct 2007
Location: East Coast
Posts: 308
Thanks: 0
Thanked 69 Times in 67 Posts
The find command is a funky animal and its functionality seems to vary from OS-to-OS. I've found that if I need it to list data that is X days old, it seems to work if you subtract 1 from the real amount.
Sponsored Links
    #5  
Old 07-13-2012
...@...
 
Join Date: Feb 2004
Location: NM
Posts: 9,646
Thanks: 164
Thanked 641 Times in 618 Posts
two points -

I disagree with in2nix.
find's behavior is largely very consistent, expecially on versions of UNIX that are POSIX-compliant.

find uses the stat() system call. This returns mtime as seconds since Jan 01 1970, called 'epoch seconds'. mtime +13 means the file's modification time is greater than the number of seconds in a day times 13 - at least (84600 * 13) seconds ago.
Not actual calendar days.

This result for find is from the CURRENT TIME. The time right now in epoch seconds. If you want find to behave the way you think about dates you have to give those it kinds of dates/times in the form of an mtime you set on a dummy file

So, -mtime +days ain't gonna cut it.
touch -t YYYYmmddhhmm [somefilename] sets an exact mtime on a file
example:

Code:
touch -t 20120628000  dummy  # midnight june 28
find /path/to/files -type d ! -newer dummy  -exec ls -ld {} \;

The Following User Says Thank You to jim mcnamara For This Useful Post:
aster007 (07-13-2012)
Sponsored Links
Closed Thread

Tags
find, linux, mtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Strange "cut" command's behaviour royalibrahim Shell Programming and Scripting 1 07-15-2011 02:19 AM
awk command to replace ";" with "|" and ""|" at diferent places in line of file shis100 Shell Programming and Scripting 7 03-16-2011 08:59 AM
find: "weird" regex behaviour courteous Shell Programming and Scripting 7 01-24-2011 01:50 PM
unix "trap" command behaviour aoussenko Shell Programming and Scripting 1 01-23-2009 08:01 AM
"find command" to find the files in the current directories but not in the "subdir" swamymns Shell Programming and Scripting 9 07-22-2008 11:23 AM



All times are GMT -4. The time now is 01:13 PM.