2017-12-18 8 views
1

그래서 특정 파일 확장자에 대해 수천 개의 폴더가있는 디렉토리를 반복적으로 검색하고 추가 된 날짜를 얻고 특정 연도로 필터링하려고합니다. 아래의 코드는 작동하지만 one-liner로 변환 할 수있는 방법이 있습니까?어떻게 이것을 하나의 라이너로 결합 할 수 있습니까? bash

  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은 년으로 날짜를 포함하므로 특정 연도보다 큰 모든 파일을 가져옵니다 ...

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

왜 당신이 한 줄 필요합니까? – Inian

+2

지적 호기심) – e9e9s

+2

이 배쉬인가? 루프는 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

파일의 출력 형식이 제 제어되지 않고 공백으로 구분됩니다 ... '11 월 11 일 2017 년 ' – 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}'