年ごとにファイルを移動する方法

年ごとにファイルを移動する方法

年に基づいてファイルを移動する必要があります。私はfindコマンドを使用しました

find /media/WD/backup/osool/olddata/ -mtime +470 -exec ls -lrth {} \;|sort -k6

ただし、このコマンドを正常に実行するには、正確な数字を知る必要があります。mtime現在470は推測だけです。つまり、2012年を入力すると、2012年に関連するファイルのみが提供されます。

だからどうすればいいのかアドバイスが必要です。

年(2012年など)を基準にファイルを見つけ、別のディレクトリに移動します。

OS release 5.2

FIND version
GNU find version 4.2.27
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION SELINUX 

ベストアンサー1

-newermtこのオプションを使いたいですfind

find /media/WD/backup/osool/olddata/ -newermt 20120101 -not -newermt 20130101

2012年に修正されたすべてのファイルをインポートします。

検索でこれをサポートしていない場合は、-newermt次の手順を実行してオフセット計算を無効にすることもできます。

touch -d 20120101 /var/tmp/2012.ref
touch -d 20130101 /var/tmp/2013.ref
find /media/WD/backup/osool/olddata/ -newer /var/tmp/2012.ref -not -newer /var/tmp/2013.ref

マンページ

-newerXY reference
          Compares the timestamp of the current file with reference.   The
          reference  argument  is  normally the name of a file (and one of
          its timestamps is used for the comparison) but it may also be  a
          string  describing  an  absolute time.  X and Y are placeholders
          for other letters, and these letters select which time belonging
          to how reference is used for the comparison.

          ...

          m   The modification time of the file reference
          t   reference is interpreted directly as a time

おすすめ記事