Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find command find directories that were created after a certain date under Linux/Cygwin

I want to use the find command to find these directories:

Access: 2013-12-13 10:59:46.190886900 -0500
Modify: 2013-12-03 07:04:02.995890600 -0500
Change: 2013-12-03 07:04:02.995890600 -0500
 Birth: 2013-12-02 07:04:02.000000000 -0500  (I want a time after '12-03')

This is the command I ran but it still lists older directories:

find . -type d -newerBt '2013-12-03 00:00:00' -exec du -h {} \;

How can I modify this line to find the directories created after that date? What is the difference between -newerct and -newerBt. I think I want the birth date.

Note: I am running this with the latest cygwin.

like image 963
Berlin Brown Avatar asked Dec 13 '13 16:12

Berlin Brown


People also ask

How do I search for files older than a date in Linux?

You could start by saying find /var/dtpdev/tmp/ -type f -mtime +15 . This will find all files older than 15 days and print their names. Optionally, you can specify -print at the end of the command, but that is the default action.

How do I find the oldest directory in Linux?

To search for a directory, use -type d. -printf '%T+ %p\n' prints the last modification date & time of file (defined by %T) and file path (defined by %p). The \n adds a new line. Sort | head -n 1 it sorts the files numerically and passes its output to the head command which displays the 1 oldest file.

How do I search all directories in Linux?

Using the Find Command The “find” command allows you to search for files for which you know the approximate filenames. The simplest form of the command searches for files in the current directory and recursively through its subdirectories that match the supplied search criteria.


2 Answers

You could use stat instead:

 find . -type d -exec bash -c '(( $(stat -c %W "{}") > $(date +%s -d '2013-12-03') )) && du -h "{}"' \;
like image 177
devnull Avatar answered Oct 01 '22 20:10

devnull


You are finding directories, but showing files contained therein.

Those files may have birth dates that lie before that of the containing directory. For example, create a file, then a directory, and move the file into that directory.

This is the difference between birth date and change date. If a file is moved into the dir, the dir is changed, so I think -newerct is what you want.

like image 34
Rody Oldenhuis Avatar answered Oct 01 '22 21:10

Rody Oldenhuis