特定のファイルをgrepし、その特定のファイルをコピーします。

特定のファイルをgrepし、その特定のファイルをコピーします。

これは私のファイルで、出力は次のようになります。ll | awk '{print $9}'

thread_dump_10-10-22_10:00:01*
thread_dump_10-10-22_10:05:01*
thread_dump_10-10-22_10:10:01*
thread_dump_10-10-22_10:15:01*
thread_dump_10-10-22_10:20:01*
thread_dump_10-10-22_10:25:01*
thread_dump_10-10-22_10:30:01*
thread_dump_10-10-22_10:35:01*
thread_dump_10-10-22_10:40:01*
thread_dump_10-10-22_10:45:01*
thread_dump_10-10-22_10:50:01*
thread_dump_10-10-22_10:55:01*
thread_dump_10-10-22_11:00:01*
thread_dump_10-10-22_11:05:01*
thread_dump_10-10-22_11:10:01*
thread_dump_10-10-22_11:15:01*
thread_dump_10-10-22_11:20:01*
thread_dump_10-10-22_11:25:01*
thread_dump_10-10-22_11:30:01*
thread_dump_10-10-22_11:35:01*
thread_dump_10-10-22_11:40:01*
thread_dump_10-10-22_11:45:01*
thread_dump_10-10-22_11:50:01*
thread_dump_10-10-22_11:55:01*
thread_dump_10-10-22_12:00:01*
thread_dump_10-10-22_12:05:01*
thread_dump_10-10-22_12:10:01*
thread_dump_10-10-22_12:15:01*
thread_dump_10-10-22_12:20:01*
thread_dump_10-10-22_12:25:01*
thread_dump_10-10-22_12:30:01*
thread_dump_10-10-22_12:35:01*
thread_dump_10-10-22_12:40:01*
thread_dump_10-10-22_12:45:01*
thread_dump_10-10-22_12:50:01*
thread_dump_10-10-22_12:55:01*

私の問題は、11時30分から12時30分の間にファイルを特定のフォルダにコピーすることです。ソース:/home/Downloads/thread_dumps宛先:/home/test

ベストアンサー1

コマンドを使用findし、すべてのファイルが同じパターン(時間で終わる)に従うとします。

find /home/Downloads/thread_dumps \( -name  '*11:[3-5][0-9]:*' -o -name '*12:[0-2][0-9]:*' -o -name '*12:30:[0-5][0-9]*' \) -exec cp --target-directory=/home/test {} +

上記のコマンドはファイルをコピーします。12:30:??(時間が12:31以上の場合、ファイルは考慮されません。)

ファイルが必要ない場合は、次の12:30コマンドfindを使用する必要があります。

find /home/Downloads/thread_dumps \( -name  '*11:[3-5][0-9]:*' -o -name '*12:[0-2][0-9]:*' \) -exec cp --target-directory=/home/test {} +

おすすめ記事