How do I delete 30 days old files in UNIX?

How do I delete 30 days old files in UNIX?

-mtime +30 : This refers to all the files which are older than 30 days. mtime stands for Modification time in Unix. You can change the number based on your requirement. -exec rm {} \ : This is actually the execution command which calls for deletion of all the files filtered by all the above criteria.

How do I delete 30 day old files 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.
  4. Conclusion.

How do you delete files older than date in Unix?

-type f -newermt “YYYY-MM-DD HH:MM:SS” -delete . It saves you from having to pipe everything through xargs, and having to handle filesnames with spaces or other disruptive characters.

How do I delete old files in UNIX?

3 Answers

  1. ./my_dir your directory (replace with your own)
  2. -mtime +10 older than 10 days.
  3. -type f only files.
  4. -delete no surprise. Remove it to test your find filter before executing the whole command.

How do I find files older than 30 days?

The above command will find and display the older files which are older than 30 day in the current working directorys….Find and delete files older than X days in Linux

  1. dot (.)
  2. -mtime – Represents the file modification time and is used to find files older than 30 days.
  3. -print – Displays the older files.

How do I delete a 6 month file in Unix?

As before, the -mtime parameter is used to find files older than X. In this case, it’s older than 180 days. You can either use the -delete parameter to immediately let find delete the files, or you can let any arbitrary command be executed ( -exec ) on the found files.

How do I delete files older than 7 days UNIX?

Explanation:

  1. find : the unix command for finding files/directories/links and etc.
  2. /path/to/ : the directory to start your search in.
  3. -type f : only find files.
  4. -name ‘*.
  5. -mtime +7 : only consider the ones with modification time older than 7 days.
  6. -execdir …

What is xargs command used for?

The xargs command is used in a UNIX shell to convert input from standard input into arguments to a command. In other words, through the use of xargs the output of a command is used as the input of another command.

How do I delete files in Windows older than 30 days?

To delete files older that X days, do the following.

  1. Open a new command prompt instance.
  2. Type the following command: ForFiles /p “C:\My Folder” /s /d -30 /c “cmd /c del @file” Substitute the folder path and the amount of days with desired values and you are done.

What is the difference between exec and xargs in Unix?

xargs reads from stdin (using blank as deliver for tokens) and executes commands; for each line read from the standard input, it executes a command using some initial argument(options) followed by the tokens read. exec will replace the shell with another process.