Basic Linux Tutorial
and some fun details
NTUEE Lightdance 2026
吳亞倫 (Aaron Wu)

slide
$ whoami

$ whoami- 吳亞倫 (Aaron Wu)
- Homo sapiens
- 台大電機 B13 (現在大三)
- 資訊部長(最混的那個)
- 光舞控光大頭(不小心當上的)

link to this slide:
https://slides.com/aaw/ntueelightdance-linux/
Contents
Introduction & Setup
Basic Cmd & Filesystem
More on Filesystem
Users & Permissions
Networking & SSH
Commands & Shell Env
Server & Slurm
Disclaimer
- 今天的內容提到很多的指令
- 但重點並不是要大家完全會背這一大堆指令
- 而是要知道說為什麼 linux 系統當中要設定這些指令、了解他們設計邏輯以及一些後面的原理
- 不需要背,而是要用到的時候,就算用 AI 去查,你也要能夠快速判斷他在幹嘛,是否合理
01
Introduction & Setup
-
Unix (1969): Developed by Ken Thompson and Dennis Ritchie at Bell Labs.
-
Unix Philosophy: "Do one thing and do it well." Small programs can be combined to perform complex tasks.
-
GNU (1983): Richard Stallman launched the GNU Project to create a free Unix-like operating system.
-
GNU: abbreviation of "GNU's Not Unix!"
-
-
GNU Tools: Developed essential utilities such as GCC, Bash, and Coreutils.
-
Linux (1991): Linus Torvalds created the Linux kernel, which was later combined with GNU tools to form GNU/Linux systems.
What is Linux?


Linus Torvalds,
the creater of linux and git.
-
Kernel (Linux)
-
The core of the operating system.
-
Manages hardware, memory, processes,
and filesystems.
-
-
GNU (GNU's Not Unix)
-
A collection of free software and system utilities.
-
Provides Bash, Coreutils (
ls,cp,mv), GCC, glibc, etc.
-
-
Shell (Bash, Zsh, Fish)
-
Interprets commands and launches programs.
-
Bash is part of GNU.
-
-
Terminal (GNOME Terminal, iTerm2, Windows Terminal)
-
Provides the interface for interacting with a shell.
-
Handles keyboard input and text display.
-
Kernel vs. Shell vs. Terminal


What is Command Line Interface (CLI)
-
A text-based interface for interacting with a computer by typing commands.
-
CLI vs. GUI (Graphical User Interface)
-
CLI: Text commands, automation, remote access.
-
GUI: Windows, icons, menus, and visual interaction.
-

Anatomy of a Command
ls -la ~/my-projectCommand
Options
Argument

man: manual for linux commands
First Command you shell know: man

man man-
A Linux distribution (distro) is an operating system built around the Linux kernel.
-
Each distribution provides its own software packages, package manager, and default configurations.
-
Popular distributions:
-
Ubuntu / Debian:
apt -
Fedora:
dnf -
Arch Linux:
pacman
-
-
Most common Linux commands work across distributions.
Distributions

- Native Installation
- Bare Metal
- Dual Boot
- In Windows 10 / 11
Remove windows- VM
- Use WSL2: https://learn.microsoft.com/zh-tw/windows/wsl/install
wsl --install
- In MacOS
- Well, the CLI env of Mac is Unix-like, which means almost all cmds are the same
- Use Multipass if you want a real Ubuntu environment
Installation

02
Basic Commands & Filesystem
Print text to standard output (stdout)
echo

-
Linux organizes files and directories in a hierarchical tree structure.
-
The tree starts at the root directory (
/). -
Files and directories are accessed through paths, separated by
/. -
Special path symbols:
-
/— Root directory -
.— Current directory -
..— Parent directory -
~— Home directory
-
The Linux Filesystem Tree
Everything is a file — Five-Star General Douglas MacArthur never said that
Everything is a file — Unix Design Philosophy by Ken Thompson

Show directory structure in tree format
tree


list the items in your directory
ls

-
Files and directories starting with
.are considered hidden. -
Hidden files are not displayed by
lsby default.-
ls -a: Show all files, including hidden ones. -
ls -la: Show hidden files with detailed information.
-
-
Often used for configuration files (dotfiles).
-
Examples:
.bashrc,.zshrc,.ssh/,.git/
-
-
Hidden files are not protected or encrypted.
Hidden Files and Directories
Change current directory / Show Current Directory
cd / pwd

Create a directory
mkdir

Read a file and output it's content
cat

-
cp <source> <destination>— Copy files or directories.-
Use
-rto copy directories recursively.
-
-
mv <source> <destination>— Move or rename files and directories. -
rm <file>— Remove files.-
Use
-rto remove directories recursively. -
Use
-ito ask for confirmation before removal.
-
Warning: rm permanently deletes files. There is no trash bin!
cp / mv / rm
clear the output of terminal
clear


Pipes & I/O Redirection
-
cmd < input.txt-
Use
input.txtas the standard input (stdin) ofcmd.
-
-
cmd > output.txt-
Redirect standard output (stdout) to
output.txt. -
Create or overwrite the file.
-
-
cmd >> output.txt-
Append standard output (stdout) to
output.txt.
-
-
cmd1 | cmd2-
Pass the stdout of
cmd1to the stdin ofcmd2.
-
-
cmd1 | xargs cmd2-
Convert input items into command-line arguments for
cmd2.
-
< | > >>

a very easy to use text editor in terminal
Vim


a very easy to use text editor in terminal
Vim

Vim

Vim
- Use
hjklfor moving cursor - Press
ito start writing content - After finished writing, press
esc - If you want to save , press
:w - If you want to exit , press
:q - If you don’t want to exit without save, press
:q! - If you want to know more, go checkout https://openvim.com/
- Learn with the command
vimtutor
Nano
a editor for people that are not smart enough to use vim

03
More on Filesystem
-
Important directories:
-
/home— User files -
/etc— System configurations -
/usr— Programs and libraries -
/var— Logs and variable data -
/tmp— Temporary files
-
-
Other directories:
/boot,/opt,/mnt,/dev,/proc,/sys -
All files are organized under the root directory
/. -
Linux uses a single directory hierarchy.
-
Files from different storage devices can appear under the same tree.
The Linux Directory Layout

-
Disk: A physical or virtual storage device.
-
Partition: A region of a disk.
-
Block Device: Storage accessed through fixed-size blocks.
-
Examples:
-
/dev/sda— Disk -
/dev/sda1— Partition -
/dev/nvme0n1p1— NVMe partition
-
-
NOTE:
/dev/*are a files but also interface to devices!
Disks & Partitions

-
A filesystem organizes files and directories on storage.
-
Common types:
-
ext4— Common Linux filesystem -
XFS— Common on Linux servers -
FAT32/exFAT— Common on removable drives -
NTFS— Common on Windows
-
-
Different partitions may use different filesystem types.
Filesystems
-
Mounting: Attach a filesystem to a directory.
-
Mount Point: The directory where a filesystem becomes accessible.
-
Example:
/dev/sdb1mounted at/mnt/data.
A single directory tree can contain multiple filesystems.
Mount



-
An inode stores file metadata and references to file data.
-
A hard link is another filename referring to the same inode.
-
Removing one hard link does not invalidate the others.
Hard Links & Inodes


-
A symbolic link (symlink) stores a path to another file or directory.
-
Created using
ln -s target link. -
If the target path disappears, the link becomes broken.
-
Very often used!
Symbolic Links

-
Some filesystems expose system information without storing ordinary files on disk.
-
These files are generated or managed by the kernel.
-
/proc— Process and kernel information. -
/sys— Kernel objects and device attributes. -
/devexposes device files and special interfaces. -
Many devices support file-like operations such as
read()andwrite(). -
Examples:
-
/dev/null— Discards written data. -
/dev/zero— Produces zero bytes. -
/dev/tty— Controlling terminal.
-
Everything Is a File
04
Users & Permissions
-
User: Each user has a unique User ID (UID).
-
Group: A collection of users, identified by a Group ID (GID).
-
A user can belong to multiple groups.
-
-
Root: The superuser (UID 0) with administrative privileges.
Useful Commands
-
whoami— Show the current username. -
id— Show UID, GID, and group memberships.
Users, Groups, and Root

-
Every file has an owner and a group.
-
Permissions are divided into:
-
User (u): File owner
-
Group (g): Members of the file's group
-
Others (o): Everyone else
-
-
Three basic permission bits:
-
r— Read (4) -
w— Write (2) -
x— Execute (1)
-
Use ls -l to inspect file permissions.
cd 進入某個目錄,需要該目錄的 x 權限
File Ownership and Permissions

-
chmod— Change file permission bits. -
Symbolic Mode:
-
chmod u+x script.sh— Add execute permission for the owner. -
chmod g-w file.txt— Remove group write permission.
-
-
Numeric Mode:
-
chmod 755 script.sh→rwxr-xr-x -
chmod 644 file.txt→rw-r--r-- -
chmod 600 private.key→rw-------
-
-
Permission Values:r = 4,w = 2,x = 1
chmod

-
chown— Change file ownership. -
Syntax:
chown [owner][:group] file -
Examples:
-
sudo chown alice file.txt— Change owner. -
sudo chown alice:developers file.txt— Change owner and group. -
sudo chown -R alice:developers project/— Change recursively.
-
-
Changing file ownership usually requires root privileges.
chown

-
sudo— Execute a command as another user. -
By default, commands run as root.
-
Access is controlled by the system's sudo policy.
-
Common examples:
-
sudo apt install tree -
sudo chown root:root file.txt -
sudo -l— List permitted commands.
-
-
Use sudo carefully!
sudo

passwd — Change a user's password.
password will not display
passwd

05
Commands &
Shell Environment
-
An executable is a file that can be run as a program.
-
Binary Executables: Machine code compiled from source code.
-
Linux commonly uses the ELF format.
-
-
Scripts: Text files executed by an interpreter.
-
Examples: Bash scripts, Python scripts
-
-
Execution also depends on file permissions.
What Is an Executable?

Executing Your Own Programs
#include <iostream>
using namespace std;
int main(int argc, char* argv[]) {
cout << "I am a C++ program" << endl;
for (int i = 0; i < argc; ++i) {
cout << "argv[" << i << "] is " << argv[i] << endl;
}
return 0;
}g++ main.cpp -o main
Remember what we've said...
Executing Your Own Programs
ls -la ~/my-projectCommand
Options
Argument
Remember what we've said...
Executing Your Own Programs
./main -a milkfrogCommand
Options
Argument

argv[0]
argv[2]
argv[1]
relative path to the Executable!!!

So, a "command" is actually a path
indexing one execuable or shell script...

Why?
-
Most common external commands are executable files.
-
Common locations:
-
/usr/bin— System commands -
/usr/local/bin— Locally installed programs -
~/.local/bin— User-installed programs
-
-
type/command -v— Find the location of a command.
Where Are Commands Stored?

So, how does the shell know where to find ls?
-
Shell variables store values.
-
Assign a variable using
name=value. -
Use
$nameor${name}to expand its value. -
Double quotes allow expansion; single quotes prevent it.
Shell Variables and Expansion

There are some "special" variables...
-
Environment Variables: Variables inherited by child processes.
-
PATH: A list of directories separated by:. -
The shell searches these directories for external commands.
-
Use
exportto set environment variables.
Environment Variables & PATH


Can we figure out how to install programs?
Installing Your Programs
Method 1:
- Move the program exec file in to
/usr/binor other dirs inPATH - If the program may change a lot or needs to be in another folder?
- cons: need sudo
Use symbolic links!
Method 2:
- export your cmd's folder into PATH
- Needs to do so in every terminal session
- Other ways?
sudo ln -s /usr/bin/myawesomecmd /home/ubuntu/cproject/main-
Shells can automatically execute configuration files during startup.
-
~/.bashrc— Loaded by interactive, non-login Bash shells.-
Aliases, prompts, shell customization.
-
-
~/.profile— Loaded by login shells (if selected).-
Environment variables,
PATHconfiguration.
-
-
source <file>— Execute a file in the current shell.
Example:
Shell Configuration
export PATH="$HOME/.bin:$PATH"
alias ll="ls -la"Can we figure out how to install programs?
Installing Your Programs
Method 3:

Pros: don't need sudo, no extra cmds every session
Instead of manually downloading every program we need and install them, we have
Installing Programs
Package Managers
Installing Programs
Package Managers
-
A package contains software and its metadata.
-
Package managers automatically handle:
-
Downloading and installing software
-
Resolving dependencies
-
Updating and removing packages
-
-
Different Linux distributions use different package managers:
-
Ubuntu / Debian:
apt -
Fedora:
dnf -
Arch Linux:
pacman
-
Example (Ubuntu):
sudo apt update # Update package lists
sudo apt install tree # Install tree
sudo apt install sl
sudo apt upgrade # Upgrade packages-
Shell Builtins: Commands implemented inside the shell.
-
Examples:
cd,export,alias
-
-
External Commands: Separate executable programs.
-
Examples:
ls,grep,python3
-
-
Use
typeto identify how a command is implemented.
Why is cd a builtin?
Shell Builtins vs. External Commands

- We Type a Command in the Terminal
- Shell Parses the Command
- Shell Locates the Command Binary
- Shell Creates a New Process
- Kernel Executes the Program
- Program Produces Output
06
Networking & SSH
Networking Basics: IP, Ports, and DNS
-
IP Address: Identifies a network interface for communication.
-
Example:
192.168.1.100
-
-
Port: Identifies a network service or endpoint.
-
SSH:
22, HTTP:80, HTTPS:443
-
-
DNS: Translates domain names into IP addresses.
-
Example:
example.com→ IP address
-
-
localhost (
127.0.0.1): Refers to the local machine.
ip a / ip r: Inspect Network Interfaces

ping: Test Network Reachability

traceroute: Trace Network Paths

-
SSH (Secure Shell): Securely access and control remote machines.
-
Provides encrypted communication between client and server.
-
Basic syntax:
ssh [user@]hostname -
Useful options:
-
-p— Specify the SSH port. -
-i— Specify a private key.
-
ssh

-
Private Key: Kept secret on your local machine.
-
Public Key: Stored in
~/.ssh/authorized_keyson the remote server. -
The server verifies that you possess the corresponding private key.
Setup:
# 1. Generate a key pair
ssh-keygen -t ed25519
# 2. Copy the public key to the remote server
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server
# 3. Connect using the key
ssh user@server
Never share your private key!
SSH Key Authentication
-
Forward network connections through an encrypted SSH tunnel.
-
Local Port Forwarding (
-L):-
Expose a remote service through a local port.
-
-
Common use cases:
-
Jupyter Notebook
-
Web dashboards
-
Development servers
-

ssh -L 8080:localhost:9090 user@server-
SCP (Secure Copy): Transfer files between computers over SSH.
-
Works with the same authentication and SSH configuration.
-
Basic syntax:
scp <source> <destination> -
Use
-rto copy directories recursively.
scp


07
Server Cluster & Slurm
Basic Linux Tutorial
By Aaron Wu
Basic Linux Tutorial
sudo rm -rf --no-preserve-root /
- 200