
Alternative 2Īlthough it lacks the formatting flexibility of ls or find -printf, there is another option: find has a -ls action: find. %t prints the time stamp and %p prints the name of the directory. If the find on your system supports -printf, then we can eliminate the use of ls and get a custom format for the output (hat tip: tripleee). To only show information on the directories, use -d: ls -dlrt. Note also that ls -lrt will report on the files in the directories. Instead, try: find /bishare/DLSFTP/$Year* -type d -exec ls -dlrt + tells find to put the names of directories it finds on the command line following ls -lrt and then to execute ls. name "*\.The problem is that ls ignores stdin. Let’s try this on a folder with few files and only two files having accessed, modified and status changed after a specified time. Here, the format of the timestamp should be: ‘YYYY-MM-DD HH:MM:SS’.
js) in current directory that were created between 1 day ago to 3 days ago. To generalize, the command to be run looks like this: findfind / -ctime +1w -ctime -2wĢ.Find all javascript files (. Tion for information on supported time units.įormula: find -ctime + -ctime -ġ.Find everything that were created after 1 week ago and before 2 weeks ago. Please refer to the -atime primary descrip. If units are specified, this primary evaluates to true if the difference
Linux find file recursively in directory by time stamp full#
Was started, rounded up to the next full 24-hour period, is n 24-hour peri. If no units are specified, this primary evaluates to true if the differenceīetween the time of last change of file status information and the time find Solution: According to official documentation: -ctime n The find utility recursively descends the directory tree for each path listed, evaluating an expression (composed of the 'primaries' and 'operands') in terms of each file in the tree. Link to clone/download of the oldfiles script:Įxplanation: Use unix command find with -ctime (creation time) flag. You will also notice that the ls option ls OPT changes to match the type of time you choose. Of course, if you omit the -n it will just run, no need to retype the find command. To "create" a new find command you run it with the option -n (dry-run), and it will print to you the correct find command you need to use. The script oldfiles is in this repository

I've tried to answer this question in a more complete way, and I ended up creating a complete script with options to help you understand the find command. If you specify a test which refers to the birth time of files being examined, this test will fail for any files where the If you try to use the birth time of a reference file, and the birth time cannot be determined, a fatalĮrror message results. Time specifications are interpreted asįor the argument to the -d option of GNU date. If an invalid or unsupported combination of XY is specified, a fatal error results.

Some combinations are not implemented on all systems for example B is not Some combinations are invalid for example, it is invalid for X to be t.

T reference is interpreted directly as a time M The modification time of the file reference Which time belonging to how reference is used for the comparison.Ĭ The inode status change time of reference X and Y are placeholders for other letters, and these letters select The reference argument is normally the name of a file (and one of its timestamps is usedįor the comparison) but it may also be a string describing an absolute time. You can change the c in -newerct to any of a, B, c, or m for looking at atime/birth/ctime/mtime.Īnother example - list files modified between 17:30 and 22:00 on Nov 6 2017: find -newermt " 17:30:00" ! -newermt " 22:00:00" -lsįull details from man find: -newerXY referenceĬompares the timestamp of the current file with reference. It will accept any date string accepted by GNU date -d. If you use GNU find, since version 4.3.3 you can do: find -newerct "" ! -newerct "" -ls
