Lets take an example, wherein we will find and delete file older than 7 days. We will be using the option “-mtime” of the find command for this. 1. Get a list of files using find command as follows: # find /path_to_directory -mtime +7 -type f -exec ls {}\; 2. If...
This is a very simple tutorial on how to find, move and delete files older than X days. I needed this for a project where I collected some images and needed to archive and delete them after a while. With this, you will be able with the Linux find command to find your JPG files old...
As you see in the above example, the directoryostechnixcontains 33 files. I don't want 33 files in this directory. I want to delete all oldest files and keep only 10 files. Now, let us find and delete oldest file(s) in this directory if it contains more than 10 files. To do so,...
Find files older than X days You can use themtimeparameter to find older files that have not been modified recently. Let's say you want to find files older than 30 days in the current directory. Use this command: find . -mtime +30 Find modified directories in the last n minutes or da...
change to a root user andtype the commandupdatedb, which would take a great amount of time according to the size of the system. Thus, it locates files much faster thanfind, but using an ‘older’ database may cause user failure to locate files which could be removed or not updated into...
find \$fpath -type f -mtime +15 -exec rm -rf {} \\; count=\$(cat /tmp/file.out | wc -l) if [ "\$prev_count" -lt "\$count" ] ; then MESSAGE="/tmp/file1.out" TO="[email protected]" echo "Apache Access log files are deleted older than 20 days" >> \$MESSAGE ...
Find Thefindutility offers much more advanced functionality. Below is an example from a script I've installed on a number of servers that I administer to ensure that a specific pattern of file (also known as a glob) exists for only five days and all files older than that are deleted. (...
# chmod +x /opt//delete-old-files.sh 最后添加一个 cronjob 自动化此任务。它于每天早上 7 点运行。 # crontab -e 0 7 * * * /bin/bash /opt//delete-old-folders.sh 你将看到类似下面的输出。 Apache Access log files are deleted older than 20 days +---+ Oct 11 /var/log/apache/2dayg...
find/home/user/<directory>-mtime+3-execrm{}\; Let’s break down the previous command to get the complete information about deleting the files older than a specific date. The /home/user/<directory> represents the targeted directory in which you want to delete the files. ...
That find expression (“-mtime +30”) menas “older than 30 days”. There is much more you can do with find – for example, printing is not the only action. There are also a galaxy of expressions you can use to seach by: owner, group owner, newer than or older than other files,...