Move files that are 30 minutes old
You can use find
along with -exec
for this:-
Replace /sourcedirectory
and /destination/directory/
with the source and target paths as you need.
find /sourcedirectory -maxdepth 1 -mmin -30 -type f -exec mv "{}" /destination/directory/ \;
What basically the command does is, it tries to find files in the current folder -maxdepth 1
that were last modified 30 mins ago -mmin -30
and move them to the target directory specified. If you want to use the time the file was last accessed use -amin -30
.
Or if you want to find files modified within a range you can use something like -mmin 30 -mmin -35
which will get you the files modified more than 30 but less than 35 minutes ago.
References from the man
page:-
-amin n
File was last accessed n minutes ago.
-atime n
File was last accessed n*24 hours ago. When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored, so to match -atime
+1, a file has to have been accessed at least two days ago.
-mmin n
File's data was last modified n minutes ago.
-mtime n
File's data was last modified n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file modification times.
Move file that has aged x minutes
Checking relative age of files can be done by Bash's built-in file date comparison operator -ot
.
See help test
:
FILE1 -nt FILE2 True if file1 is newer than file2 (according to modification date).
FILE1 -ot FILE2 True if file1 is older than file2.
#!/usr/bin/env bash
declare -- TIME_FILE
TIME_FILE="$(mktemp)" || exit 1 # Failed to create temp-file
trap 'rm -- "$TIME_FILE"' EXIT # Purge the temp-file on exit
declare -i EXPECTED_AGE_TIME=10
# Set the time of the referrence $TIME_FILE to $EXPECTED_AGE_TIME minutes
touch --date "$((EXPECTED_AGE_TIME)) min ago" "$TIME_FILE"
# If $FILE is older than $TIME_FILE, then move it
[[ "$FILE" -ot "$TIME_FILE" ]] && mv -- "$FILE" "./loaded/$FILE"
Move files older than x minutes
You can't call methods without an object providing the method, so .MoveFile
should be fso.MoveFile
. However, in its current form the script would move all files from C:\CopyFlow\Directory test\Inn
if any of the files in the folder passed as argument to the script is older than 5 minutes.
What you need to do is pass C:\test\inn
as the argument to the script, and move only those files that actually are older:
If age > age_threshold Then
file.Move "C:\test\inn\error\"
End If
Related Topics
Debugging Shared Libraries with Gdbserver
Can Ptrace Tell If an X86 System Call Used the 64-Bit or 32-Bit Abi
Linux: How to Detect That Ftp File Upload Is Finished
How to Download the Torvalds Linux Kernel Master, (Re)Compile It, and Boot It with Qemu
Why Is Crond Failing to Run a Non-Root Crontab on Alpine Linux
How to Make a Bash Shell Script Interact with Another Command Line Program
Sed Help: Matching and Replacing a Literal "\N" (Not the Newline)
Check If a Program in a Specific Path Is Running
Prohibit Unaligned Memory Accesses on X86/X86_64
Use a C Library in Swift on Linux
Getting "I Won't Open a Connection To" When Connecting to Ftp Server from Google Compute Engine
Find All Files Matching 'Name' on Linux System, and Search with Them for 'Text'
Set Environment Variable with Space in Linux
Service Doesn't Support Chkconfig
What Is the Most Efficient and Elegant Way Develop/Debug Linux Kernel