Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find directories created less than a week ago

Tags:

find

bash

unix

I know I can use this command to find directories created or modified less than a week ago:

find /home -type d -mtime -7

But how do I find directory that were created less than a week ago?

like image 785
Sergey Avatar asked Dec 11 '11 16:12

Sergey


People also ask

How do I search for files older than one day in Linux?

-mtime +0 matches any file whose mtime difference is at least 24 hours. Tf you want mtime to count calendar days, and not n-24 hour periods from now, use -daystart : -daystart -mtime 0 is means today and -daystart -mtime +0 means before today. Also you can find only files with adding -type f or only dirs -type d .

Where is Yesterday file in Unix?

You can use the find command to find all files that have been modified after a certain number of days. Note that to find files modified before 24 hours ago, you have to use -mtime +1 instead of -mtime -1 . Save this answer.


2 Answers

Creation time is not stored.

There is only 3 timestamps you can check

Last access time
Last modification time
Last change time

"Change" is one of: permission changes, rename etc. While the modification is contents only.

like image 200
SlavaNov Avatar answered Sep 24 '22 17:09

SlavaNov


Short answer: you can't.

There are three times stored in an inode

  • ctime: time of creation or change of the inode
  • mtime: time of last change of the file that the inode refers to
  • atime: time of last access to the file

The point is: ctime is altered not only by create, but also by chmod / chown, maybe even by ln (not sure). Man stat and man touch are your friends.

If you try to find fresh directories by means of find /home -type d -mtime -7 be prepared to also find older directories that had their mode or owner changed.

like image 44
wildplasser Avatar answered Sep 22 '22 17:09

wildplasser