bsh6226 2024. 1. 24. 13:52

리눅스

소스 비공개 문화에 반발하여 시작한 GNU 프로젝트의 차원에서 공개된 오픈소스(GPL) 운영체제. 누구나 GPL 소스에 접근하고 활용할 수 있으며, 많은 개발자가 참여하기때문에 수정이 빈번하고 호환성문제가 발생할 수 있음. (스스로 해결법 탐색할 수 있는 역량이 필요)

 

리눅스 기본패키지 구성

매번 ls와 pwd를 통해서 리눅스 파일 구조를 찾아내기보다는 기본적인 구조는 외워서 작업하는게 더 편리할 것으로 생각되어 기본 패키지는 외울 필요가 있다고 생각한다. 

 

Essential Directories to Remember

Path Purpose Common Usage
/ Root directory (everything starts here) cd / to go to the top level
/home/username/ User’s home directory User files, downloads, personal configs
/root/ Root user’s home directory Only accessible by root
/etc/ System configuration files Modify system settings (/etc/nginx/, /etc/hosts)
/var/log/ Log files Debugging server issues (/var/log/syslog, /var/log/nginx/)
/var/www/ Default web server files Hosting websites (/var/www/html/)
/usr/bin/ Executable programs System-wide commands like ls, vim, docker
/usr/local/bin/ Custom installed programs Manually installed tools/scripts
/tmp/ Temporary files (deleted on reboot) Store temporary files safely
/mnt/ or /media/ Mounted drives USBs, external storage (/mnt/mydrive/)
/dev/ Devices (disks, USBs) /dev/sda, /dev/tty
/proc/ Running system processes View system info (cat /proc/cpuinfo)

Common File Storage Locations for Jobs

Path Use Case Persistence cdDocker Considerations
/var/tmp/ Temporary files for long-running jobs ✅ Survives reboots Not automatically deleted in containers
/tmp/ Temporary job files (auto-cleaned on reboot) ❌ Deleted on reboot Lost when the container stops
/var/lib/<app>/ Application-related job files (e.g., databases, caches) ✅ Persistent Used for storing job results
/var/log/ Log files for jobs ✅ Persistent Use volumes for logs in Docker
/mnt/ Mounted external storage (large job files) ✅ Persistent Requires explicit mounting
/opt/<app>/ Third-party applications & job scripts ✅ Persistent Used for installed job-related tools
/home/<user>/jobs/ User-specific job files ✅ Persistent Not always available in containers
/data/ Custom data storage (user-defined) ✅ Persistent Must be manually created

 

 

우분투 패키지관리

우분투(Ubuntu)는 리눅스 배포판 중 하나로, 데비안(Debian) 계열에서 파생되었습니다. 패키지 관리에 apt(Advanced Package Tool)를 사용하며, 이 도구를 통해 소프트웨어 설치, 업데이트, 삭제, 그리고 유지관리를 효율적으로 수행할 수 있습니다.

 

리눅스 패키지 관리의 특징

  1. 오픈소스 특성:리눅스는 오픈소스 기반으로 각 개발자가 독립적으로 개발합니다. 업데이트 시 호환성 문제가 발생할 수 있으므로 검증된 업데이트만 적용해야 합니다.
  2. 공식 패키지 사용 권장: 우분투는 검증된 **공식 저장소(repository)**에서만 패키지를 배포합니다. 만약 문제 발생 시, 커뮤니티나 검색(구글링)을 통해 해결이 필요합니다.
  3. Deb 패키징 시스템: 데비안 계열의 리눅스 배포판은 .deb 형식의 패키지를 사용. 패키지 설치, 삭제, 업데이트 정보를 인덱스 정보로 관리.
  4. 인덱스 정보는 설치, 삭제, 업데이트 가능한 패키지의 메타데이터를 의미합니다. 즉, 패키지 관리자가 사용하는 **저장소(repository)**에 있는 패키지들의 목록과 관련 정보를 담고 있는 데이터입니다.

패키지관리 명령어

  • sudo apt-get update : 인덱스 정보를 최신으로 업데이트함. 만약 인덱스 정보가 오래되었다면, 패키지의 최신 버전이나 충돌관리가 원활하지 않습니다.
    • -y : 모든 대답에 yes를 하겠다는 옵션
  • apt upgrade : 보안 패치, 버그 수정, 성능 향상이 포함된 최신 상태를 유지합니다.서버에서는 호환성문제 우려로 실행하지 않음.
  • sudo apt-get install package명 : 패키지를 설치한다
    • sudo apt install mysql
    • sudo apt install openjdk-17-jdk -y
  • sudo apt-get remove package명 : 패키지를 삭제한다.  
  • sudo apt-get remove --purge package명 : 설정파일까지  같이 삭제한다.
sudo apt install mysql

 

vi 에디터

- vi filename : 해당 파일을 객체로 에디터가 실행되며, 해당 파일이 존재하지 않으면 새로 생성하여 에디터 실행.( :wq는 파일을 저장후에 나옴, :q는 저장하지 않고 나옴)

- esc : to exit the mode

 

 

 

Window CLI

  • pip install package_name : the Python package installer, to install a Python package (library)
  • python my_script.py : runs a Python script (my_script.py in this case) using the Python interpreter.
  • python -m venv new_environment : run a python module called venv to run virtual environment called new_environment
  • dir - Lists the files and directories in the directory.
  • cd path/to/directory : This command changes the current directory to the specified path
  • md or mkdir - Creates a new directory.
  • del - Deletes one or more files.
  • copy - Copies files from one location to another.
  • move - Moves files from one location to another.
  • cls - Clears the command prompt screen.
  • type - Displays the contents of a text file.
  • exit - Closes the command prompt window.

 

Mac Environment

Window와의 차별점

  • 유닉스 기반 아키텍처: macOS는 유닉스(Unix) 기반 아키텍처로 만들어졌으며, 자연스럽게 명령줄(Command Line) 중심의 소프트웨어 관리 방식을 지원한다.
  • 홈브루(Homebrew):
    • 유닉스 계열 시스템에서 소프트웨어 설치 및 관리를 간편하게 해주는 패키지 관리 시스템이다.
    • Homebrew는 애플리케이션 및 도구의 설치를 자동화하며, 의존성(Dependencies) 관리, 업데이트, 구성(Configuration) 작업을 처리해 준다.
    • 사용자가 프로그램을 쉽게 설치하고 관리할 수 있도록 도와주는 역할을 하며, 명령줄 인터페이스(CLI) 기반의 앱스토어처럼 프로그램 다운로드를 중개해주는 프로그램이라고 할 수 있다.
 

homebrew cmd

  • brew search mariadb : mariadb로 시작하는 이름의 프로그램을 찾아준다. 만약 설치가 이미 되어있으면 체크표시가 뜸.
  • brew --help : brew의 명령어를 보여준다
  • brew install mariadb : mariadb를 인스톨한다.
  • brew services : brew를 통해서 서비스를 조작할 수 있다.
  • brew services info mariadb : mariadb의 상태를 확인한다.
  • brew services stop mariadb : mariadb를 중지시킨다.
  • brew services start mariadb : mariadb를 시작시킨다.
  • brew services restart mariadb : mariadb를 재시작시킨다.
  • brew --help : brew의 명령어를 보여준다
  • brew update : 설치목록 최신화
  • brew upgrade : 프로그램 최신화
  • brew search 'program' : 프로그램명 키워드로 다운로드 받을 수 있는 프로그램을 검색한다. 이미 다운로드 받은 프로그램은 볼드체로 표시되어있음
  • brew install 'program'
  • brew infro 'program' : program에 대한 설치위치 등의 정보를 공유해준다.
    • 설치파일 : /opt/homebrew/Cellar/mariadb/11.4.2
    • 설정 : "/etc/my.cnf"
    • 데이터베이스 위치 : /opt/homebrew/opt/mariadb/bin/mysqld_safe --datadir\=/opt/homebrew/var/mysql
    • bin : directory typically holds binary executables
    • brew services info 'program' : 이미 설치된 프로그램의 실행정보에 대해서 공유해준다.
    • brew services restart/stop 'program' : 시작/종료

Mac CLI

  • clear : 터미널의 내용을 모두 삭제해서 정리한다
  • pwd : 현재 경로 확인
  • lsof : 열려있는 파일(프로세스) 확인
    • lsof -i portId : 네트워크 포트에서 실행중인 프로세스를 확인가능.portid에 열려있는 프로세스를 확인함
      • ESTABLISHED 상태의 항목 → 현재 네트워크 연결이 활성화된 상태
      • LISTEN 상태의 항목 → 서버(서비스) 역할을 하는 프로그램
      • CLOSED 상태 (연결이 종료됨)
      • SYN_SENT 상태 (연결 요청 중)
  • ls - Lists all files and directories in the current directory.
  • ls -al : 현재 디렉토리상 숨겨진 파일까지 포함하여 디테일하게 정보를 모두 보여줌
    • -a: This option stands for "all". It includes in the listings all files, including hidden files that start with a dot (.). 
    • -l: This stands for "long listing format". It displays detailed information about each file and directory. 
  • cd - Changes the current directory to another directory. Usage: cd /path/to/directory.
    • 주소관련 표기방법. 
    • ~: 홈 디렉토리
    • . : 현재디렉토리
    •  ./는 현재경로를 포함한 구분자
    • .. : 부모디렉토리
    • .filename : hidden파일
  • mkdir - Creates a new directory. Usage: mkdir newfolder.
  • rm - Removes files or directories. Usage: rm filename or rm -r directoryname to remove a directory and its contents. (Linux 옵션참조)
  • cp - Copies files or directories. Usage: cp source destination.
  • mv - Moves files or directories, or renames a file or directory. Usage: mv oldname newname.
  • grep - Searches for patterns within files. Usage: grep 'pattern' filename.
  • echo - Displays a line of text/string that is passed as an argument. Usage: echo "Hello World".
  • top - Displays active processes. It’s the Unix equivalent of Task Manager in Windows.
  • sudo - Executes a command with administrative privileges, necessary for commands that require administrative permissions.
  • netstat - displays information about network connections, routing tables, and network interface statistics.
    • -n: Displays numeric IP addresses and port numbers instead of hostnames.
    • -p: Shows the process associated with each connection.
    • -s: Displays statistics for network protocols (TCP, UDP, IP).
  • base64 : Base64 encoding takes three bytes (3*8 bits) of binary data and splits them into (4*6bits) groups. Each of these 6-bit groups is then represented by a single ASCII character. 
    • ex : base64 image.png > image.txt

 

Conceptual Framework: "User Interaction Stack"

Layer 1. Physical & Device Layer (Interfaces to the OS)

ConceptWhat it is 🔸 These are not processes, they’re interfaces managed by the kernel.

Keyboard / Mouse / Screen Hardware input/output
/dev/ttyN Physical text console (Ctrl+Alt+F1–F6)
/dev/pts/N Virtual terminal device (used by SSH, GUI terminals)
/dev/input/ Input devices (keyboard, mouse)

 

 

🧠 Layer 2. User Session Layer (Environment / Context)

 
ConceptWhat it is
Login Session Logical environment after login (local or SSH)
Seat Physical grouping of input/output (keyboard + monitor)
Environment Variables DISPLAY, XAUTHORITY, PATH, etc.

🔸 These are not processes, but the context in which processes run.
Use loginctl, who, or env to inspect them.

 

 

Layer 3. Program Execution Layer (Actual processes)

ConceptWhat it is
Shell (bash, zsh) A text-based command interpreter
Terminal Emulator (xterm, gnome-terminal) GUI window that wraps a terminal
X Server (Xorg, Xvnc) Program that manages GUI drawing
GUI Apps (gedit, firefox) X Clients — programs that request drawing
SSH Daemon / Client Process that builds remote sessions
 

🔸 These are all OS processes. They show up in ps, top, htop.

 

 

 

📡 Layer 4. Communication Protocol Layer (How things talk)

ConceptWhat it is
X11 / Wayland Protocol for GUI rendering
SSH Protocol Protocol for remote shell communication
PTY / TTY protocols Pseudo-terminal driver interfaces
 

🔸 These are not running programs, but rules or formats for communication.

 

LayerHelps answer...
Device Layer "What does the OS expose for interaction?"
Session Layer "Who is the user and what’s their environment?"
Process Layer "What’s actually running?"
Protocol Layer "How do those processes communicate?"

 

 

There are official terms related to some of these ideas:

Conceptual LayerRelated Real Concepts
Device Layer POSIX /dev, PTY/TTY subsystem in Linux kernel
Session Layer systemd-logind sessions, PAM sessions, XDG session management
Process Layer UNIX process model, ps, exec, fork
Protocol Layer X11 protocol spec, Wayland protocol, SSH RFCs

 

[User Input]
      ↓
      /dev/tty1     /dev/pts/0
      ↓               ↓
      [Shell] ← in Terminal (e.g. xterm)
   ↓
       [Login Session] ← session context/environment
   ↓
       [X Client (GUI App)] → [X Server (Xorg)]
      ↑
  speaks X11 protocol

 

A process is something the OS runs and tracks in memory.
A session or terminal device is something the OS uses to group or connect those processes.