2017-12-18 6 views
1

私は特定のファイル拡張子のために何千ものフォルダを持つディレクトリを再帰的に検索し、追加された日付を取得して特定の年をフィルタリングします。以下のコードは動作しますが、1ライナーに変換できる方法はありますか?これをワンライナーに組み合わせるにはどうすればいいですか?

  1. はtmp.txt

    foreach i (` cat tmp.txt `) 
    ls -ltrh $i >> tmp2.txt 
    end 
    
  2. 欄にすべてのそれらのファイルの

    find . -name "*xml" >> tmp.txt 
    
  3. GET許可情報&タイムスタンプ情報をtmp.txtするために、XMLと&書き込みを終了するすべてのファイルを取得します8には年として日付が含まれているため、特定の2014年よりも長い年のすべてのファイルを取得します。

    awk '$8 >=2014' tmp2.txt >> tmp3.txt 
    
+1

??:彼は一例であり、あなたのニーズに数学を合わせる...

別の解決策 – Inian

+2

知的好奇心;) – e9e9s

+2

これはBashですか?ループはcshのように見えますか? –

答えて

5

この方法を試してください。

find . -type f -name '*xml' -newermt "2014-01-01" -ls 

man findから:

私は シェルでどうなるのか
-newerXY reference 
      Succeeds if timestamp X of the file being considered is newer 
      than timestamp Y of the file reference. The letters X and Y 
      can be any of the following letters: 

      a The access time of the file reference 
      B The birth time of the file reference 
      c The inode status change time of reference 
      m The modification time of the file reference 
      t reference is interpreted directly as a time 
+0

ファイルの出力形式は私の制御ではなく、スペースで区切られています... '1111 11207' – e9e9s

+0

' -ls'を '-exec ls -lh { } + 'または' -printf'ここで、フォーマットパラメータを 'ls'に渡すことができます。 – Pavel

+0

ああ、そうです。私は今働いている。ありがとう! – e9e9s

1

find . -mtime -$((365*4)) -name "*xml" >> tmp.txt 

Tあなたが働くものを持っている場合は、ワンライナーを必要としないのはなぜ

find . -name '*xml' -printf '%TY %p\n' | awk '$1 >= 2014 {$1=""; print}'