How do I delete 7 days old file in Linux?

How do I delete 7 days old file in Linux?

-mtime +7 : only consider the ones with modification time older than 7 days. -execdir \; : for each such result found, do the following command in . rm — ‘{}’ : remove the file; the {} part is where the find result gets substituted into from the previous part.

How do I delete 5 days old files in Linux?

4 Answers

  1. Also use -type f to delete files only (and keep sub directories)
  2. Alternatively, if you want to do the same for all files NEWER than five days: find /path/to/directory/ -mindepth 1 -mtime -5 -delete.
  3. @uom-pgregorio I would suggest putting the path in quotes.

How do I uninstall older than 30 days in Linux?

How to Delete Files Older than 30 days in Linux

  1. Delete Files older Than 30 Days. You can use the find command to search all files modified older than X days.
  2. Delete Files with Specific Extension. Instead of deleting all files, you can also add more filters to find command.
  3. Delete Old Directory Recursively.

Where are 2 days old files Linux?

4 Answers. 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 to create cron job to auto delete folder older than 7 days?

Can anyone help me create a cron job script on that deletes folder older than 7 days and runs one day before backup and delete old folders. Any help appreciated. For example, the description of crontab for deleting files older than 7 days under the /path/to/backup/ every day at 4:02 AM is as follows.

How to delete files older than 3 days?

I need to remove files older than 3 days with a cron job in 3 different directories. (these 3 directories are children of a parent directory /a/b/c/1 & /a/b/c/2 & /a/b/c/3) Can this be done with one line in the crontab?

How to delete backups older than 10 days in Cron?

If $USER is for the user’s userid, you have a problem: cron doesn’t define $USER in the runtime enviroinment. It does define $HOME, so you could use $HOME/DIRECTORY1/DIRECTORY2. I use one to delete backups older than 10 days and it looks something like this:

When to remove the # before the delete?

Remove the # before the -delete once you are sure that it is finding the files you want to remove.