98.Terminal, CLI - YukaKoshiba/MyknowledgeDocs GitHub Wiki

Hardware @English Version
Create Date:2025/07/10
Last Update Date:2025/07/10

Contents

Terminal  Terms

File OperationsCreate File  Delete File  Compile  Execute Program

Folder OperationsCreate Folder  Change Current Directory  Move File to Folder 

Other File OperationsUnzip File  Download File  List Files in Specified Directory 

DB OperationsConnect to DB ( SQLite )
Get Schema (DB Table Info) ( SQLite )
Measure Processing Time ( SQLite )
Disconnect from DB ( SQLite )

Web Server OperationsCheck HTTP Request/Status Code  Start HTTP Server


Terminal

Software (application) for using **CUI/CLI**.
= A program that provides a CUI environment to the user.

Reasons to Use the Terminal

Despite the existence of a **GUI** that allows easy mouse operations, the main reasons for specifically using the terminal are as follows:

1. **More advanced and detailed operations are possible**
It allows for deep OS configuration changes and complex system operations that are not available in a GUI.
For example, operations that are cumbersome in a GUI, such as renaming a large number of files at once or searching for and deleting files based on specific conditions, can be executed with a single command.

2. **Automation and efficiency of work**
By creating **scripts** (files describing a series of commands) that combine multiple commands, repetitive tasks can be automated.
This is a very powerful tool for developers and system administrators.
For example, tasks like backing up specific data at a fixed time every day can be automated.

3. **Remote operation**
Using protocols like **SSH (Secure Shell)**, you can connect to a server or another computer in a remote location and operate that computer directly.
→ This is an indispensable function when managing web servers or using cloud services.

4. **Less resource consumption**
While a GUI consumes a lot of system resources (memory and CPU) for graphical display,
the terminal is character-based, so it consumes very few resources,
which is particularly advantageous for less powerful computers or environments that require stable operation, such as servers.

5. **Essential tool for developers**
Many tasks in modern software development, such as programming language compilation, **version control** using **Git**, **package management** with **npm** or **pip**, and **debugging**, are performed on the terminal.

Professional environment
Specific tools (e.g., text editors like **vim** or **emacs**, multiplexers like **tmux**) are optimized for the terminal environment,
and with proficiency, work can be done faster and more efficiently than in a GUI environment.

Troubleshooting and diagnosis
If a system problem occurs and the GUI doesn't start, you can still check logs and diagnose the system status from the terminal.


Terms

  • **CUI/CLI**
    **CUI (Character User Interface)** or **CLI (Command Line Interface)**
    Types of computer operation methods.
    It is an interface where you input text to give instructions to the computer and receive results also in text.
    This is contrasted with **GUI (Graphical User Interface)**, where you operate icons and windows with a mouse.
  • **Source code**
    Code that is written and understandable by humans.
  • **Machine language** or **Binary code**
    Code expressed only in 0s and 1s that computers can understand (but humans cannot).
  •  
  • **Compile**
    The act of converting source code into machine language.

Available in Visual Studio Code (VS Code) **TERMINAL**, etc.


File Operations

File Creation

code fileName.extension"

File Deletion

rm fileName.extension

Compiling a File

make fileName

Executing a File

./fileName

The file name refers to the compiled (converted to machine language) file to be executed.

Folder Operations

Creating a New Folder

mkdir folderName

Changing the Current Folder

Change the current folder with "cd folderName".


// Desired folder name (absolute path or relative path)
cd folderName
// Move up one directory
cd ..
// Move up two directories
cd ../..
// Return to home directory
cd ~

Moving Files to a Folder

mv document.txt documents/

"mv targetFileName destinationFolderName"


Other

Extracting ZIP Files

unzip fileName.zip

Downloading Files

wget path_to_download_file

Listing Files in a Specified Directory

ls

DB Operations

By executing commands specific to each DB and connecting to the DB, you can write SQL directly in the terminal.

Connecting to a DB

SQLite

Execute the following command in the terminal or command prompt.
If the specified DB does not exist, a new database file will be created.

sqlite3 your_database_name.db

Once connected to the DB, the new command input line will become `sqlite`.

Importing CSV

SQLite

Set CSV mode.

.mode csv

Load the CSV file.

.import fileName.csv

Retrieving Schema

Retrieve what tables exist in the DB.

SQLite
.schema

Measuring Processing Time

SQLite
.timer on

Disconnecting from the DB

SQLite

The new command input line will revert from `sqlite` to `$`.

.quit

Web Server Operations

Checking HTTP Requests/Status Codes

Send an HTTP request to a specific URL and display only its response headers.

You can obtain the following information:
・**HTTP status code** (e.g., 200 OK, 404 Not Found)
・**Content type** (e.g., text/html, application/json)
・**Server information** (e.g., server type and version)
・Date and time, and other header information

curl -I https://www.~/

Starting an HTTP Server

Start a simple HTTP server created with Node.js.

http-server

This is mainly used to easily serve **static** web content locally.
When executing dynamic web content, use a different appropriate command.


// (Example: If you were using Flask with Python)
flask run
⚠️ **GitHub.com Fallback** ⚠️