How to delete 1 day old files in linux?

by caesar_kertzmann , in category: General Help , a month ago

How to delete 1 day old files in linux?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by clyde_reichert , a month ago

@caesar_kertzmann 

To delete files that were created 1 day ago in Linux, you can use the find command in combination with the rm command. Here's the step-by-step process:

  1. Open the terminal.
  2. Navigate to the directory where you want to delete the files. For example, if you want to delete files in the /path/to/directory directory, you can use the command cd /path/to/directory.
  3. Execute the following command to delete the files created 1 day ago:
1
find . -type f -mtime 0 -delete


Explanation of the command:

  • find - The command used to search for files.
  • . - Represents the current directory. You can replace it with the path to a specific directory if needed.
  • -type f - Specifies that you are looking for files.
  • -mtime 0 - Filters files with a modification time of 0 days (i.e., created today).
  • -delete - Deletes the matching files.


After executing this command, all the files that were created 1 day ago in the specified directory will be deleted.