最後にgrepを使って修正してください。

最後にgrepを使って修正してください。

過去2時間に変更されたファイルのリストをstdoutに追加したいと思います。ディレクトリにgrepを使用します。自動でなければなりません(ユーザーに時間などを尋ねることはできません)、条件文ではなくgrepを使用する必要があります。これが私が今やっていることです:

#!/bin/bash

#redirect output to a file otherwise grep will read all as one line not giving a readable   output
ls -lrt > ls_out
date > date_extr

# extract hour from date. E interpret what follows as an extended regex. o print only what is matched. m 1 stop after one match
#I'll go back 2 hours
time_=$(date | grep -Eo [0-9]+?: | grep -Eom 1 [0-9]+?)
time_1=$[$time_-1]
time_2=$[$time_-2]

#grep day and month from the previous file "" to include spaces in date_
date_=$(grep -oE [0-9]+\ [A-Za-z]+\  date_extr)
grep "$date_" ls_out > ls_date

#match time as it is if it has 2 digits for example 11, 19, 21. \ number avoid matches as 19: if time_ is 9:
grep \ $time_:      ls_date
grep \ $time_1:     ls_date
grep \ $time_2:     ls_date

#match 09: if time_ output was 9:
grep 0$time_:      ls_date
grep 0$time_1:     ls_date
grep 0$time_2:     ls_date

#cleaning up
rm ls_out ls_date date_extr

うまくいきます。唯一の問題は、スクリプトが午前00時または午前1時に実行されると、前日に変更されたファイルが一覧表示されないことです。

問題は、iiが日付とls -lrtの出力をgrepする必要があることです。 ifが必要なようです。

そのため、この質問をする場合、いくつかの修正を適用したリンクは次のとおりです。 http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_04_05.html。質問7.

ベストアンサー1

使用find . -maxdepth 1 -mmin -120。使用する必要がある場合は、空のgrep文字列を探してください。grep -l '' $(find . -maxdepth 1 -mmin -120)

おすすめ記事