Linux ''find'' command: File aging for special extention. Regex and mtime doesn't work together

StackOverflow https://stackoverflow.com/questions/23396926

Вопрос

My .sh file is like below:

#!/bin/sh

FOLDER = '/home/Desktop/myUserName/My_monitored_folder'

ASD= 'cd $FOLDER'
REGEX = '.*xxx.yyy*.*'
$ASD
CMD = 'find -regextype posix-extended -regex $REGEX -mtime +0h10m0s'
$CMD | xargs ls -Blatr** 

My find version is: 4.4.2

when I run this shell file: my purpose is to get some type of files(regex is just for that) that aged in that folder older than 10 minutes. Funny thing is that, -regex without -mtime give me back the files I need. When I use them together, it ends up in ls -Blatr

mtime doesn't function well. indeed mtime doesn't function at all. Could anyone take a look at it? I might be missing something thanks in advance for your time.

Это было полезно?

Решение 2

#!/bin/sh
OPENDIRECTORY='//My_Monitored_Folder'
REGEXTYPE='posix-extended'
REGEX='.*xxx.yyy*.*'
MINUTESAGED='+15'
CMD="find -regextype $REGEXTYPE -regex $REGEX -mmin $MINUTESAGED"
$OPENDIRECTORY
$CMD | xargs ls -lrt | tr -s " " | cut -d" " -f6-9

last pipes are to just get name and time from terminal log. I hope it helps everyone looking for this subject

Другие советы

Without some sample filenames, I cannot directly reproduce the issue but one possible workaround is to leave the regex business to grep.

find --mtime +0h10m0s | egrep $REGEX | xargs ...
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top