[linux] Explaining the 'find -mtime' command

I'm trying to remove all the dateed logs except the most recent. Before I execute a script to remove the files, I want to of course test my commands to make sure I'm bringing up accurate results.

When executing these commands the date is:

Sep  1 00:53:44 AST 2014

Directory Listing:

Aug 27 23:59 testfile.2014-08-27.log
Aug 28 23:59 testfile.2014-08-28.log
Aug 29 23:59 testfile.2014-08-29.log
Aug 30 23:59 testfile.2014-08-30.log
Aug 31 23:59 testfile.2014-08-31.log
Sep  1 00:29 testfile.log

I thought -mtime +1 was supposed to list all files over a day old. Why isn't the 8-30.log one listed?

find . -type f -mtime +1 -name "testfile*log"
./testfile.2014-08-27.log
./testfile.2014-08-28.log
./testfile.2014-08-29.log

This is the desired effect, but it was just trial and error. What is this 0 saying?

find . -type f -mtime +0 -name "testfile*log"
./testfile.2014-08-30.log
./testfile.2014-08-27.log
./testfile.2014-08-28.log
./testfile.2014-08-29.log

This question is related to linux bash find

The answer is


+1 means 2 days ago. It's rounded.


To find all files modified in the last 24 hours use the one below. The -1 here means changed 1 day or less ago.

find . -mtime -1 -ls

Examples related to linux

grep's at sign caught as whitespace How to prevent Google Colab from disconnecting? "E: Unable to locate package python-pip" on Ubuntu 18.04 How to upgrade Python version to 3.7? Install Qt on Ubuntu Get first line of a shell command's output Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running? Run bash command on jenkins pipeline How to uninstall an older PHP version from centOS7 How to update-alternatives to Python 3 without breaking apt?

Examples related to bash

Comparing a variable with a string python not working when redirecting from bash script Zipping a file in bash fails How do I prevent Conda from activating the base environment by default? Get first line of a shell command's output Fixing a systemd service 203/EXEC failure (no such file or directory) /bin/sh: apt-get: not found VSCode Change Default Terminal Run bash command on jenkins pipeline How to check if the docker engine and a docker container are running? How to switch Python versions in Terminal?

Examples related to find

Find a file by name in Visual Studio Code Explaining the 'find -mtime' command find files by extension, *.html under a folder in nodejs MongoDB Show all contents from all collections How can I find a file/directory that could be anywhere on linux command line? Get all files modified in last 30 days in a directory FileNotFoundError: [Errno 2] No such file or directory Linux find and grep command together find . -type f -exec chmod 644 {} ; Find all stored procedures that reference a specific column in some table