Linux `find` 명령어 활용
Linux `find`로 파일/디렉토리 찾고 삭제하기
리눅스에서 파일이나 디렉토리를 찾을 때 find 명령어가 아주 유용해. 특정 이름 패턴이나 파일 타입으로 검색할 수 있지.
- 파일 찾기: 현재 디렉토리에서
._*패턴의 파일을 찾으려면:bash find . -name "._*" -type f - 찾은 파일 바로 삭제: 위에서 찾은 파일을 바로 삭제하려면
-delete옵션을 써봐.bash find . -name "._*" -type f -delete - 후처리 (
-exec): 찾은 결과에 대해 다른 명령을 실행하고 싶다면-exec를 사용하면 돼.{}는find결과가 들어갈 자리이고,\;로 명령 끝을 알려줘.bash find /경로/ -type d -name "20240630" -exec rm -rf {} \;이건/경로/에서20240630이름의 디렉토리를 찾아 강제로 삭제하는 예시야.
여기서 배울 것
- `find` 명령어로 파일/디렉토리 검색하는 법
- `-delete` 옵션으로 바로 검색 결과 삭제하기
- `-exec` 옵션으로 검색 결과에 후처리 적용하기
- `{}`와 `\;`의 의미 이해하기
원본 파일 보기 (.claude/skills/tn-linux-find-files/SKILL.md)
---
name: Linux `find` 명령어 활용
description: Use when the user needs to locate or delete files and directories on a Linux system based on specific criteria such as name patterns, file types, or modification times, using the `find` command.
version: 1.0.0
source: /home/son/prj/resume/backup_notes_260317/notion/Tech Note/linux find files 304d7efd824b80fabf01d45498792692.md
---
# linux find files
find . -name "._*" -type f
find . -name "._*" -type f -delete
-exec 붙이면 후처리 가능
{} = 나온 결과
```
find /경로/ -type d -name "20240630" -exec rm -rf {} \;
```
출처:
[https://betwe.tistory.com/entry/간단-명령어-find-명령어로-특정-패턴-폴더-또는-파일-삭제](https://betwe.tistory.com/entry/%EA%B0%84%EB%8B%A8-%EB%AA%85%EB%A0%B9%EC%96%B4-find-%EB%AA%85%EB%A0%B9%EC%96%B4%EB%A1%9C-%ED%8A%B9%EC%A0%95-%ED%8C%A8%ED%84%B4-%ED%8F%B4%EB%8D%94-%EB%98%90%EB%8A%94-%ED%8C%8C%EC%9D%BC-%EC%82%AD%EC%A0%9C)
[개발과 육아사이:티스토리]