How to Delete Files on a Particular Date with Unix

Can anybody please tell me how to delete all the files on a particular date in Unix? for example, I have a list of files: Nov 9 12:30 test, Nov 9 14:45 test 2, Nov 9 18:15 quick, Nov 10 07:20 quick 2...Now I would like to delete the file quick 2 created on Nov 10..... What would be the command?

Best Answered by

Dany· Answered on Feb 22, 2023

You can use two command lines to precisely find and delete files at a particular time. First, you can search for files whose last modification time is older than X minutes, days, months, or years using bash in Unix. Here is the Command Prompt for searching the specific file(s).

find / -name "your-directory" -mtime +XX -exec rm -f {}; Specify path, filename and time to delete the file.

The description of the Command line is as follows:

  • find - the command that finds the files.
  • ./your-directory - the absolute or relative path to the location of the search. I believe that using absolute routes will prevent future issues.
  • -mtime +XX - replace XX with the days you want to return. 
  • -exec rm -f {}; - this deletes files that match the particular settings.

It is safe to execute the preceding command since it will only produce a list of files that fit the search criteria; they will not be destroyed or modified; for example, a possible output might be: ./your-directory/file1.xd

As previously stated, my script's final phase was removing the files that matched the search more simpler. Fortunately, the most challenging step was completed. To erase the result of your search, add the -delete parameter to the search command:

find ./your-directory -daystart -maxdepth 1 -mmin +10 -type f -delete

When you delete a file or directory in Linux or Unix, it does not disappear forever. There are a few tiers of folders where deleted files can go before being completely removed from your system. So you can recover deleted files in Linux or Unix effortlessly. 

EaseUS Data Recovery Wizard can recover deleted files or folders on Linux. By downloading, you can access free recovery from various data loss situations and preview before recovery. Simply put, you can connect the Unix disk to a Windows PC and retrieve files. Download EaseUS to use its capabilities and recover your lost files for free.

Use EaseUS Data Recovery Wizard to recover deleted or lost files easily and quickly.

Tutorials on how to recover lost, deleted, or formatted data from HDD, SSD, USB, SD card, or other storage media on Windows and Mac.

People Also Ask

How to Delete a File/Folder at Logon [GPO Script Settings]

It is not a good thing that agents and supervisors can check some sensitive information. We will help you use the logon/logoff script to solve the issue in this passage.

Dany

Feb 22, 2023

What Is the Use of Shift Delete on Windows

We know many shortcuts can be used on Windows, and we are going to introduce the use of Shift + Delete on Windows. We will also let you know when and why you need to use this shortcut on Windows in this passage.

Dany

Mar 09, 2023

How to Delete Files from Archive by Text File

Renaming a file within a zip bundle is similar. Even in these circumstances, you can extract everything before zipping it back into a new file or overwriting the old one. So, keep reading this post to acquire the 2023 guide.

Dany

Feb 22, 2023

Can I Delete the Default Files on My External HDD Newly Bought

What should you do when you get a new external HDD? Is it necessary to delete the default files on your HDD? You will find the answer in this passage.

Dany

Mar 09, 2023

Why Deleted Files Can Be Recovered from Emptied Recycle Bin

This article will introduce why deleted files can be recovered from emptied Recycle Bin, whether it is time-related or not, whether the size of the file changes the chance of recovery, and whether restarting the PC makes it harder to recover the file.

Dany

Apr 19, 2023

Quickly Delete Massive File Structure on Windows Server 2012

Normally, the deletion of large files takes a long time. Your computer needs to confirm and analyze the data, which will take time. The methods below may help you quickly delete massive files structure on Windows Server 2012.

Dany

Feb 22, 2023