How do I delete files in UNIX older than x days?

How do I delete files in UNIX older than x days?

If you want to delete files older than 1 day, you can try using -mtime +0 or -mtime 1 or -mmin $((60*24)) .

How do I delete files and folders older than x days Linux?

You should use the command -exec rm -r {} \; and add the -depth option. The -r option to rm remove directories with all the content. The -depth option tell find to elaborate content of folders before the folder itself.

How do I delete files and folders older than 30 days 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.

How do I delete all files and folders older than x 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.

How can I delete more than 7 days in Unix?

3 Answers

  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 …

How do I delete old log files in UNIX?

Is there a proper way to clear log files on Unix? You can simply truncate a log file using > filename syntax. For example if log file name is /var/log/foo, try > /var/log/foo as root user.

How do I delete old dated files in Linux?

How to delete all files before a certain date in Linux

  1. find – the command that finds the files.
  2. . –
  3. -type f – this means only files.
  4. -mtime +XXX – replace XXX with the number of days you want to go back.
  5. -maxdepth 1 – this means it will not go into sub folders of the working directory.

How do I remove 10 days old 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 you clear the log file in Unix?

How do you delete files older than 7 days UNIX?

2 Answers

  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 …

How to delete files older than 5 days in Linux?

The second argument, -mtime, is used to specify the number of days old that the file is. If you enter +5, it will find files older than 5 days. The third argument, -exec, allows you to pass in a command such as rm. The {} ; at the end is required to end the command.

How to find and delete files in Linux?

Be careful with special file names (spaces, quotes) when piping to rm. That’s it, no separate rm call and you don’t need to worry about file names. Replace -delete with -depth -print to test this command before you run it ( -delete implies -depth ). Note that this command will not work when it finds too many files.

How to delete empty sub-directories in Linux?

To delete empty sub-directories, refer to @Costas comment above. Highly active question. Earn 10 reputation (not counting the association bonus) in order to answer this question.

How to delete shell scripts back to current date?

Closed 7 years ago. I’m new to shell scripts, can anyone help? I want to delete scripts in a folder from the current date back to 10 days. The scripts looks like: The script will run in every 10 day with Crontab, that’s why I need the current date. -delete no surprise. Remove it to test your find filter before executing the whole command