Linux 명령어 완벽 정리: 파일 및 디렉토리 관리 핵심 9선
2025. 7. 25. 21:52ㆍ리눅스
728x90
🐧 리눅스 필수 파일/디렉토리 명령어 정리
: ls, cd, cp, mv, rm, find, grep, awk, sed
리눅스를 처음 배우는 분들을 위해 꼭 알아야 할 파일 및 디렉토리 관련 명령어를 설명과 예제 중심으로 정리했습니다.
📁 리눅스 파일/디렉토리 명령어 요약표
| 명령어 | 설명 | 예시 |
|---|---|---|
ls |
디렉토리 목록 조회 | ls -al |
cd |
디렉토리 이동 | cd /var/log |
cp |
파일/디렉토리 복사 | cp a.txt b.txt, cp -r dir1 dir2 |
mv |
파일/디렉토리 이동 또는 이름 변경 | mv a.txt b.txt |
rm |
삭제 | rm a.txt, rm -rf dir/ |
find |
파일 검색 | find / -name "*.log" |
grep |
텍스트 검색 | grep "error" syslog.log |
awk |
필드 기반 데이터 출력 | awk '{print $1}' file.txt |
sed |
문자열 치환 | sed 's/old/new/g' file.txt |
✅ 명령어별 실습 예제
1. ls, cd
mkdir test_dir
cd test_dir
touch a.txt b.txt .hidden.txt
ls
ls -al
결과:
ls → a.txt b.txt
ls -al → .hidden.txt 포함 전체 목록 출력
2. cp, mv
cp a.txt a_copy.txt
mv b.txt b_renamed.txt
ls
결과: a_copy.txt, b_renamed.txt 생성됨
3. rm
rm a_copy.txt
mkdir folder
touch folder/temp.txt
rm -rf folder
결과: a_copy.txt와 folder 모두 삭제됨
4. find
touch log1.log
touch log2.log
touch readme.md
find . -name "*.log"
결과:
./log1.log
./log2.log
5. grep
echo -e "error: file not found\ninfo: completed\nerror: disk full" > log.txt
grep "error" log.txt
결과:
error: file not found
error: disk full
6. awk
echo -e "user1 100\nuser2 200\nuser3 300" > data.txt
awk '{print $1}' data.txt
결과:
user1
user2
user3
7. sed
echo -e "apple\nbanana\napple" > fruits.txt
sed 's/apple/orange/g' fruits.txt
결과:
orange
banana
orange
▶️ 전체 실습 순서 요약
mkdir test_dir && cd test_dir
touch a.txt b.txt .hidden.txt
ls
ls -al
cp a.txt a_copy.txt
mv b.txt b_renamed.txt
rm a_copy.txt
mkdir folder && touch folder/temp.txt
rm -rf folder
touch log1.log log2.log readme.md
find . -name "*.log"
echo -e "error: file not found\ninfo: completed\nerror: disk full" > log.txt
grep "error" log.txt
echo -e "user1 100\nuser2 200\nuser3 300" > data.txt
awk '{print $1}' data.txt
echo -e "apple\nbanana\napple" > fruits.txt
sed 's/apple/orange/g' fruits.txt
👍 도움이 되셨다면 댓글이나 공감 부탁드립니다!
728x90
'리눅스' 카테고리의 다른 글
| Linux 명령어 완벽 정리: systemd 서비스 관리 관련 명령어 핵심 10선 (3) | 2025.07.28 |
|---|---|
| Linux 명령어 완벽 정리: 사용자 및 퍼미션 관리 관련 명령어 핵심 13선 (1) | 2025.07.28 |
| Linux 명령어 완벽 정리: 패키지 설치 관련 명령어 핵심 5선 (1) | 2025.07.28 |
| Linux 명령어 완벽 정리: 네트워크 관련 명령어 핵심 8선 (0) | 2025.07.27 |
| Linux 명령어 완벽 정리: 시스템 모니터링 핵심 6선 (2) | 2025.07.25 |