Skip to Content
문서시작하기시작하기명령줄 기본 사항

명령줄 기본 사항

Linux를 처음 접하는 사용자에게는 명령줄이 낯설거나 심지어 겁이 날 수도 있습니다. 그러나 실제로 명령줄은 Linux 시스템에서 가장 강력하고 유연한 도구입니다. 기본 명령줄 작업을 익히면 시스템 관리가 더욱 효율적일 뿐만 아니라 Linux가 내부적으로 작동하는 방식을 이해하는 데도 도움이 됩니다.

이 기사에서는 터미널과 셸의 개념을 이해하고, 가장 일반적으로 사용되는 명령을 익히고, 파일 경로, 파이프, 권한과 같은 핵심 지식을 학습하는 데까지 여러분을 안내합니다.

터미널과 셸이란?

터미널

터미널은 텍스트 명령을 입력하여 컴퓨터와 상호 작용할 수 있는 창을 제공하는 애플리케이션입니다. Ubuntu 데스크탑 환경에서 터미널은 검은색(또는 어두운) 배경의 창으로 표시됩니다.

Ubuntu 26.04의 기본 터미널 애플리케이션은 Ptyxis입니다. 기존 GNOME 터미널을 대체하고 더 나은 컨테이너 통합을 제공합니다. 필요한 경우 기존 GNOME 터미널을 설치할 수 있습니다.

보다 현대적인 GPU 가속 터미널을 사용해보고 싶다면 Ghostty를 26.04 유니버스 저장소에서 미리 보기 패키지로 사용할 수 있습니다.

sudo apt install ghostty

Ghostty는 기본 터미널이 아닙니다. OpenGL 4.3을 지원하지 않는 장치에서는 소프트웨어 렌더링 대체가 필요할 수 있습니다.

쉘

쉘은 실제로 명령을 처리하는 터미널 뒤에 있는 프로그램입니다. 터미널에 명령을 입력하면 쉘이 명령을 구문 분석하고 실행합니다. 우분투의 기본 쉘은 Bash(Bourne Again Shell)입니다.

일반적인 쉘에는 다음이 포함됩니다.

쉘설명
배쉬우분투의 기본 셸, 풍부한 기능과 우수한 호환성
Zsh더 나은 자동 완성 및 테마를 갖춘 보다 현대적인 셸
물고기즉시 사용 가능한 구문 강조 기능을 갖춘 사용자 친화적인 셸
대시Ubuntu에서 시스템 스크립트용으로 사용하는 경량 셸

다음 명령을 사용하여 현재 쉘을 확인할 수 있습니다.

echo $SHELL

터미널을 여는 방법

Ubuntu 26.04에는 터미널을 여는 방법이 여러 가지 있습니다.

방법 1: 키보드 단축키

가장 빠른 방법은 Ctrl + Alt + T를 눌러 터미널 창을 직접 여는 것입니다.

방법 2: 애플리케이션 메뉴에서

  1. 왼쪽 상단에 있는 활동 버튼을 클릭합니다(또는 Super 키를 누릅니다).
  2. 검색창에 “터미널”을 입력하세요
  3. 터미널 아이콘을 클릭하여 엽니다.

방법 3: 파일 관리자에서

GNOME 파일 관리자(Nautilus)에서 빈 공간을 마우스 오른쪽 버튼으로 클릭하고 **“터미널에서 열기”**를 선택할 수 있습니다. 터미널은 자동으로 현재 디렉터리로 이동합니다.

방법 4: TTY 가상 터미널

Ctrl + Alt + F3(F3~F6)을 눌러 텍스트 전용 가상 터미널로 전환하세요. 그래픽 인터페이스로 다시 전환하려면 Ctrl + Alt + F2를 누르세요. 이는 그래픽 인터페이스에 문제가 있을 때 특히 유용합니다.

기본 명령

pwd - 작업 디렉토리 인쇄

pwd(작업 디렉터리 인쇄)은 현재 디렉터리의 경로를 표시합니다.

pwd # Example output: /home/username

ls - 디렉토리 내용 나열

ls(목록)은 디렉터리의 파일과 폴더를 보는 데 가장 일반적으로 사용되는 명령 중 하나입니다.

# List current directory contents ls # Show detailed information (permissions, size, modification time, etc.) ls -l # Show hidden files (files starting with .) ls -a # Combined usage: detailed info + hidden files + human-readable file sizes ls -lah # List contents of a specific directory ls /etc # Sort by modification time (newest first) ls -lt

cd - 디렉토리 변경

cd(디렉터리 변경)은 디렉터리 간을 전환하는 데 사용됩니다.

# Enter a specific directory cd /var/log # Go up one level cd .. # Return to the home directory cd ~ # Or simply type cd # Return to the previous directory cd - # Enter a multi-level directory cd /usr/share/doc

mkdir - 디렉토리 생성

# Create a single directory mkdir myproject # Create nested directories (-p auto-creates parent directories) mkdir -p projects/web/frontend # Create multiple directories at once mkdir dir1 dir2 dir3

cp - 파일 및 디렉터리 복사

# Copy a file cp file.txt backup.txt # Copy a file to a specific directory cp file.txt /home/username/Documents/ # Copy an entire directory (requires -r for recursive copy) cp -r myproject myproject-backup # Copy while preserving file attributes (permissions, timestamps, etc.) cp -a source/ destination/

mv - 이동 또는 이름 바꾸기

# Rename a file mv oldname.txt newname.txt # Move a file to another directory mv file.txt /home/username/Documents/ # Move and rename mv file.txt /home/username/Documents/newname.txt # Move an entire directory mv myproject /opt/

rm - 파일 및 디렉터리 제거

# Remove a file rm file.txt # Remove a directory and its contents (recursive deletion) rm -r myproject # Force removal (no confirmation prompt) rm -f file.txt # Confirm before each deletion rm -i *.txt
Warning

rm으로 삭제된 파일은 휴지통으로 이동하지 않고 즉시 영구적으로 삭제됩니다! 특히 rm -rf /과 같은 명령은 전체 시스템을 파괴합니다. rm를 사용하기 전에 항상 올바른 파일을 삭제하고 있는지 확인하십시오. 초보자는 먼저 ls을 사용하여 어떤 파일이 일치하는지 확인한 다음 확인한 후에 삭제해야 합니다.

고양이 - 파일 내용 보기

# View the complete contents of a file cat file.txt # Display line numbers cat -n file.txt # Concatenate multiple files cat file1.txt file2.txt # Create a new file (Ctrl+D to finish input) cat > newfile.txt

less - 페이지 단위 보기

파일 내용이 매우 긴 경우 less보다 cat이 더 적합합니다.

less /var/log/syslog

less의 일반적인 작업:

  • 스페이스: 다음 페이지
  • b: 이전 페이지
  • g: 파일의 시작 부분으로 이동
  • G: 파일 끝으로 이동
  • /키워드: 검색
  • n: 다음 검색결과
  • q: 종료

머리와 꼬리 - 파일의 시작과 끝 보기

# View the first 10 lines (default) head file.txt # View the first 20 lines head -n 20 file.txt # View the last 10 lines tail file.txt # View the last 50 lines tail -n 50 file.txt # Follow file changes in real time (commonly used for viewing logs) tail -f /var/log/syslog

파일 경로

파일 경로를 이해하는 것은 명령줄 사용의 기본입니다. Linux 파일 시스템은 /(루트 디렉터리)부터 시작되며 모든 파일과 디렉터리가 이 트리 구조로 구성됩니다.

절대 경로와 상대 경로

절대 경로는 루트 디렉터리 /에서 시작하고 파일의 전체 위치를 제공합니다.

# Absolute path examples /home/username/Documents/file.txt /etc/nginx/nginx.conf /var/log/syslog

상대 경로는 현재 디렉터리에서 계산됩니다.

# Assuming you are in /home/username # The following two are equivalent: cat /home/username/Documents/file.txt # Absolute path cat Documents/file.txt # Relative path

특수 경로 기호

기호의미예
/루트 디렉터리cd /
~현재 사용자의 홈 디렉토리cd ~은 cd /home/username과 동일합니다.
.현재 디렉토리./script.sh은 현재 디렉터리에서 스크립트를 실행합니다.
..상위 디렉터리cd ../..이 두 단계 올라갑니다.
-이전 디렉터리(CD에만 해당)cd -
# Practical examples # Return to the home directory from anywhere cd ~ # View the contents of the parent directory ls .. # Run a script in the current directory ./my-script.sh # Copy a file from two levels up to the current directory cp ../../config.txt .

파이프와 리디렉션

파이프와 리디렉션은 명령줄의 매우 강력한 기능입니다. 여러 개의 간단한 명령을 결합하여 복잡한 작업을 수행할 수 있습니다.

파이프(|)

파이프는 한 명령의 출력을 다른 명령의 입력으로 전달합니다.

# View all processes and search for lines containing "nginx" ps aux | grep nginx # List directory contents and display them page by page ls -la /etc | less # Count the number of files in the current directory ls | wc -l # View disk usage, sorted by size du -sh * | sort -h # Multi-level pipe: find errors in logs, deduplicate, and sort cat /var/log/syslog | grep "error" | sort | uniq -c | sort -rn

출력 리디렉션(> 및 >>)

# Write command output to a file (overwrites existing content) echo "Hello, Ubuntu!" > hello.txt # Append command output to the end of a file echo "Another line" >> hello.txt # Save a command listing to a file ls -la > filelist.txt # Redirect error output to a file command 2> errors.log # Redirect both standard output and error output command > output.log 2>&1 # Or the shorter version command &> output.log

입력 리디렉션 <

# Read input from a file wc -l < file.txt # Common usage: import an SQL file into a database mysql -u root -p database_name < backup.sql

권한 기본 사항

Linux는 다중 사용자 시스템이므로 권한 관리가 시스템 보안을 보장합니다.

sudo - 관리자로 실행

sudo(수퍼유저 Do)을 사용하면 일반 사용자가 관리자(루트) 권한으로 명령을 실행할 수 있습니다.

# Install software sudo apt install vim # Edit a system configuration file sudo nano /etc/hosts # Open a shell as root (use with caution) sudo -i # Check sudo privileges sudo -l

sudo을 처음 사용하면 루트 비밀번호가 아닌 사용자 비밀번호를 묻습니다. 비밀번호는 일정 기간 동안 기억됩니다.

chmod - 파일 권한 수정

Linux 파일 권한은 소유자(u), 그룹(g) 및 **기타(o)**의 세 그룹으로 나뉩니다. 각 그룹에는 읽기(r=4), 쓰기(w=2) 및 실행(x=1) 권한이 있습니다.

# View file permissions ls -l file.txt # Example output: -rw-r--r-- 1 user group 1024 Jan 1 12:00 file.txt # Add execute permission to a file chmod +x script.sh # Set exact permissions (owner: rwx, group: rx, others: rx) chmod 755 script.sh # Common permission combinations chmod 644 file.txt # Owner read/write, others read-only chmod 600 secret.key # Owner read/write only chmod 777 shared.txt # Full permissions for everyone (not recommended) # Recursively modify directory permissions chmod -R 755 /var/www/html

일반적인 키보드 단축키

키보드 단축키를 익히면 명령줄 효율성이 크게 향상될 수 있습니다.

바로가기기능
탭자동 완성 명령, 파일 이름, 디렉터리 이름
탭 탭가능한 모든 완성 옵션 표시
Ctrl + C현재 실행 중인 명령을 중단합니다.
Ctrl + D현재 쉘을 종료합니다(exit을 입력하는 것과 동일).
Ctrl + R명령 기록을 통한 역검색
Ctrl + L화면 지우기(clear 명령과 동일)
Ctrl + A커서를 줄의 시작 부분으로 이동
Ctrl + E커서를 줄 끝으로 이동
Ctrl + W커서 앞의 단어 삭제
Ctrl + U커서부터 줄의 시작 부분까지 삭제
Ctrl + K커서 위치부터 줄 끝까지 삭제
위쪽/아래쪽 화살표명령 기록 찾아보기
!!마지막 명령을 다시 실행
!$이전 명령의 마지막 인수 참조
# Tab completion example cd /etc/ng[Tab] # Auto-completes to cd /etc/nginx/ # Typical usage of !!: forgot to add sudo apt install vim # Permission error, then: sudo !! # Equivalent to sudo apt install vim # Ctrl+R search history # Press Ctrl+R, type "docker", and the most recent command containing "docker" will appear

도움 받기

Linux에서는 도움을 받을 수 있는 여러 가지 방법이 있습니다.

man - 매뉴얼 페이지

man(수동)은 가장 권위 있는 명령 문서입니다.

# View the manual for the ls command man ls # Search manuals (by keyword) man -k "copy file" # View a specific section of the manual man 5 crontab # View the crontab file format (section 5)

—help 플래그

대부분의 명령은 간결한 사용법 요약을 표시하는 --help 플래그를 지원합니다.

ls --help cp --help systemctl --help

tldr - 단순화된 매뉴얼

tldr(너무 깁니다. 읽지 않음)은 초보자에게 적합한 간결하고 실용적인 명령 예를 제공합니다.

# Install tldr sudo apt install tldr # Update the database tldr --update # View command usage tldr tar tldr rsync tldr systemctl

기타 도움말 리소스

# View a brief description of a command whatis ls # Find the path of a command which python3 whereis nginx # Check the command type (built-in, external, alias, etc.) type cd type ls

초보자를 위한 필수 명령 치트 시트

Tip

초보자가 가장 일반적으로 사용하는 20가지 명령은 다음과 같습니다. 참고용으로 북마크하세요! 한 번에 모두 외울 필요는 없습니다. 필요할 때 찾아보기만 하면 시간이 지남에 따라 제2의 천성이 될 것입니다.

명령목적일반적인 예
pwd현재 디렉토리 표시pwd
ls디렉토리 내용 나열ls -lah
cd디렉토리 변경cd /var/log
mkdir디렉토리 생성mkdir -p a/b/c
cp파일/디렉토리 복사cp -r src/ dst/
mv이동/이름 바꾸기mv old.txt new.txt
rm파일/디렉토리 제거rm -r dirname
cat파일 내용 보기cat file.txt
less파일을 페이지별로 보기less /var/log/syslog
head/tail파일의 시작/끝 보기tail -f log.txt
grep텍스트 검색grep "error" log.txt
find파일 찾기find / -name "*.conf"
sudo관리자 권한으로 실행sudo apt update
apt패키지 관리자sudo apt install vim
chmod권한 수정chmod +x script.sh
nano/vim텍스트 편집기nano file.txt
df디스크 사용량 확인df -h
top/htop프로세스 보기htop
systemctl시스템 서비스 관리systemctl status nginx
history명령 기록 보기history | grep ssh

고급 팁

명령 별칭

자주 사용하는 명령에 대한 짧은 별칭을 만들 수 있습니다.

# Temporary alias (only valid for the current session) alias ll='ls -lah' alias gs='git status' # Permanent alias (written to ~/.bashrc) echo "alias ll='ls -lah'" >> ~/.bashrc echo "alias update='sudo apt update && sudo apt upgrade -y'" >> ~/.bashrc # Apply aliases immediately source ~/.bashrc

명령 기록

# View command history history # Search command history history | grep "apt install" # Execute command #42 from history !42 # Clear history history -c

와일드카드

# * matches any characters ls *.txt # All .txt files cp *.jpg photos/ # Copy all .jpg files # ? matches a single character ls file?.txt # Matches file1.txt, fileA.txt, etc. # [] matches a specified range ls file[1-3].txt # Matches file1.txt, file2.txt, file3.txt

이러한 기본 사항을 학습한 후에는 이미 Ubuntu 명령줄에서 대부분의 일상 작업을 처리할 수 있습니다. 쉘 스크립팅, 시스템 관리, 네트워크 구성 등과 같은 고급 주제를 계속 학습할 수 있습니다. 연습이 완벽함을 만든다는 것을 기억하세요. 실습 경험이 명령줄을 마스터하는 가장 좋은 방법입니다.