일단위로 검색

-mtime: 파일의 내용이 수정된 시간을 기준으로 검색.
-atime: 파일의 접근 시간을 기준으로 검색.
-ctime: 파일의 속성 변경 시간을 기준으로 검색.

 

1. N일 이상 지난 파일 찾기

find /path/to/directory -mtime +N

 

• /path/to/directory: 검색할 디렉토리 경로.
• +N: N일 초과된 파일을 찾음.
• 예: find /home/user -mtime +30 → 30일 이상 지난 파일.


2. N일 내의 파일 찾기

find /path/to/directory -mtime -N


• -N: N일 이내의 파일을 찾음.
• 예: find /home/user -mtime -7 → 7일 이내에 수정된 파일.


3. 정확히 N일 전의 파일 찾기

find /path/to/directory -mtime N


• N: 정확히 N일 전에 수정된 파일.
• 예: find /home/user -mtime 10 → 정확히 10일 전에 수정된 파일.

 

 

시간 단위로 검색 (-mmin, -amin, -cmin)

1. N분 이상 지난 파일 찾기

find /path/to/directory -mmin +N


• -mmin: 수정 기준.
• 예: find /var/log -mmin +60 → 수정된 지 60분 이상 지난 파일.

 

 

복합 조건으로 검색

1. 7일 이상 30일 미만 수정된 파일 찾기

find /path/to/directory -mtime +7 -mtime -30


2. 확장자와 함께 사용

find /path/to/directory -mtime +7 -name "*.log"


• 7일 이상 지난 .log 파일 찾기.


3. 파일만 찾기

find /path/to/directory -type f -mtime +7 -name "*.log"

 

작업과 결합 (-exec 옵션)

7일 이상 지난 파일을 찾고 삭제

find /path/to/directory -mtime +7 -exec rm -f {} \;

 

728x90
반응형

파일에서 한줄 읽기

BufferedReader br = new BufferedReader(new FileReader("/..../file"));
String tmp = br.readLine();
br.close();

파일에서 여러 줄 읽기

BufferedReader br = new BufferedReader(new FileReader("/..../file"));
String tmp;
while((tmp=br.readLine())!=null){
	
}
br.close();

파일에 쓰기

String tmp = "my file";
FileOutputStream out = new FileOutputStream("/..../path");
out.write(tmp.getBytes());
out.close();

파일 혹은 디렉토리가 있는지 확인하기

 File f = new File("/../path");
 if(f.exists()){
 	// 존재함
 }

파일 혹은 디렉토리인지 확인하기

File f = new File("/..../path");
if(f.isDirectory()){
	// 디렉토리
}
else if(f.isFile()){
	// 파일
}

파일 혹은 디렉토리 삭제하기

File f = new File("/...../path");
f.delete();

디렉토리 만들기

File f = new File("/...../path");
f.mkdir();
//f.mkdirs(); // 상위 디렉토리가 없을 경우 자동으로 생성해줌

 

728x90
반응형

* 분할

split -b 4096m BIGFILE BIGFILE_PREFIX

BIGFILE 을 4GB 단위로 자른다.

BIGFILE_PREFIXaa, BIGFILE_PREFIXab, BIGFILE_PREFIXac ... 와 같이 파일이 생성된다.


* 합치기

cat BIGFILE_PREFIX* > BIGFILE

728x90
반응형

+ Recent posts