Linux 기초 명령어 정리
Linux 기초 명령어 정리입니다. pwd, cd, ls, mkdir, rmdir, redirection, cat, cp, mv, rm, ln, grep, find, tar, date, stat, touch를 정리했습니다.
Linux 기초 명령어 정리
Linux 기초 명령어는 파일과 디렉터리를 이동하고, 내용을 확인하고, 검색하고, 묶고, 시간을 확인하는 데 집중해서 익히면 된다. 아래 예제는 실습 디렉터리 안에서 실행하도록 구성했다.
실습 준비
mkdir -p linux-basic-lab/docs linux-basic-lab/logs
cd linux-basic-lab
printf 'hello linux\n' > docs/readme.txt
printf 'error line\ninfo line\n' > logs/app.log위치와 목록
pwd
ls
ls -la
cd docs
cd ..
cd ~디렉터리 생성과 삭제
mkdir tmp
rmdir tmp
mkdir -p a/b/c
rm -r armdir은 비어 있는 디렉터리만 지운다. rm -r은 하위 내용까지 지우므로 대상 경로를 반드시 확인한다.
리다이렉션과 파일 보기
echo "first line" > output.txt
echo "second line" >> output.txt
cat output.txt
more output.txt
less output.txt복사, 이동, 삭제
cp docs/readme.txt docs/readme.bak
mv docs/readme.bak docs/readme.old
rm docs/readme.old링크
ln docs/readme.txt hardlink-readme
ln -s docs/readme.txt symlink-readme
ls -li docs/readme.txt hardlink-readme symlink-readme파이프와 grep
cat logs/app.log | grep error
grep -n "line" logs/app.log
grep -R "hello" .head, tail, find
head logs/app.log
tail logs/app.log
tail -f logs/app.log
find . -type f -name "*.txt"tar와 gzip
tar -cvf lab.tar docs logs
tar -tvf lab.tar
gzip lab.tar
ls -lh lab.tar.gz시간과 파일 메타데이터
date
stat docs/readme.txt
touch docs/readme.txt
stat docs/readme.txt기초 명령어는 옵션을 많이 외우기보다, 현재 위치 확인, 대상 확인, 실행, 결과 확인 순서로 익히는 것이 중요하다.