name "*json*" -exec stat -c "%-25n %y" \ ĭrwxrwxr-x. In case a user wants to look for a file that was modified in a given time range, for example, more than 30 days and less 90 days, use the following command: find / -mtime +30 -mtime -90. Let’s look at how we can use the exec option to execute the stat commands for each file found by the find command: $ find. But, using the exec option might be slower than xargs, and it’s more difficult to read. The exec option of the find command can be used similarly to the xargs command used above.
#Linux find files by date range full
The man page of the find command contains the full list of possible values for k. %Tk – file’s last modification time in a format specified by k.The full list of escapes and directives can be found in the man pages, but let’s take a look at some of them: The hyphen (-) between the % sign and the width specifies that the interpreted value should be left-padded. The following command will provide detailed information about a directory: ls -d -l. dot (.) will list all of them Type ls -l chap1.profile to display detailed information about that program. The field width of a directive is specified after the % sign of a directive. How Do I List Files In Linux Then you need type this: ls -a This list will list all files. If the width of the interpreted value for that directive is less than the specified width, then it is padded with whitespace.
The unit for the width of a directive is the number of characters. In the above example, we’re specifying something called a field width inside the filename printf directive. The application offers a wide range of parameters which you can apply in multiple ways to remove the files that were created on. It is a simple tool which enables user to delete files in bulk by specifying date and time stamps. json-folder Mon Aug 23 03:37:42.1869447530 2021 Delete Files By Date is another batch file deletion utility which brings comfort and a lot more options than Deletist. Once you’re happy that the command works as intended, it can be wrapped in a shell script and perhaps dropped into /etc/cron.daily so that it runs every night.Ĭould this Linux Tip be improved? Let us know in the comments below.$ find. The third argument, -delete, deletes all the files that match the selection criteria.
+40 specifies files last modified more than 40 days ago similarly, -3 would specify files last modified less than three days ago. The second argument, -mtime, is used to specify the “last modified” age in days of the files to search for. The first argument to the find command, /tmp/mytestdir, specifies the starting point: by default, only files in or below this directory will be acted upon. As you might expect, this deletes the files that match the selection criteria. This is the same find command as before, but with -delete appended. Once we’ve checked which files will be selected, we can delete them: find /tmp/mytestdir -mtime +40 -delete
#Linux find files by date range how to
The command above shows how to select files based on their last-modified date. Let’s start by listing all files over 40 days old: find /tmp/mytestdir -mtime +40 /tmp/mytestdir/50.txt We can use the find command to select files according to various criteria. They are what we will use to test the commands on this page. You should see that you have 50 files in that directory, dated one per day over the last fifty days.
Let’s start by creating 50 files dated yesterday, the day before, and so on for 50 days: mkdir /tmp/mytestdirįor a in $(seq 50) do touch $.txt -date="$a days ago" done When it comes to automatically deleting files, it makes sense to carry out the initial configuration in a test environment. For example, you may want to remove all mail files in a “Trash” folder older than 90 days, or all files in the Samba Recycle Bin that are older than 30 days. Sometimes it can be helpful to delete files over a certain age from a directory.