Linux Commands
Let's study Commands.
When working in UNIX-like environments — whether Linux, macOS, or WSL — mastering basic shell commands is critical for efficient system navigation, debugging, and automation. In this post, I’ll walk you through some of the most useful and commonly used UNIX commands.
tree
The tree
command is a simple yet powerful tool to display directory hierarchies in a tree-like format.
Options:
-L N
: Limit the depth of directory traversal.-d
: Show only directories.-f
: Print full file paths.-a
: Include hidden files.-I PATTERN
: Ignore files/folders matching the pattern.
Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
(base) jaoneol@DESKTOP-B7GM3C5:/mnt/e/50.Utilities$ tree -L 2 -d -f -a
.
├── ./PC&OSInstall
│ ├── ./PC&OSInstall/0.HW목록
│ ├── ./PC&OSInstall/1.NDIVIA
│ └── ./PC&OSInstall/2.프린터드라이버
├── ./Developer
│ ├── ./Developer/01.Python
│ ├── ./Developer/02.CursorAI
│ ├── ./Developer/02.VSCode
│ ├── ./Developer/03.UML
│ ├── ./Developer/04.RegularExpression
│ ├── ./Developer/05.Virtual Machine
│ ├── ./Developer/06.원격접속
│ ├── ./Developer/07.Git
│ ├── ./Developer/08.MarkDown Editor
│ ├── ./Developer/09.LLMs
│ ├── ./Developer/10.DB
│ ├── ./Developer/11.OCR
│ └── ./Developer/12.Nodejs
└── ./기본설치
├── ./기본설치/Everything
├── ./기본설치/NotePad
├── ./기본설치/Q-Dir
└── ./기본설치/화면캡처
free
The free
command shows system memory usage, including RAM and swap.
Options:
-h
: Human-readable output (e.g., MB, GB).-t
: Show total memory line.-s N
: Continuously update every N seconds.
Example:
1
2
3
4
5
6
7
8
9
10
11
12
(base) jaoneol@DESKTOP-B7GM3C5:/mnt/e/50.Utilities$ free -h -s 2
total used free shared buff/cache available
Mem: 31Gi 2.3Gi 28Gi 67Mi 1.0Gi 29Gi
Swap: 8.0Gi 0B 8.0Gi
total used free shared buff/cache available
Mem: 31Gi 2.3Gi 28Gi 67Mi 1.0Gi 29Gi
Swap: 8.0Gi 0B 8.0Gi
....
Category | Description |
---|---|
Mem | Physical memory (RAM) usage. Reflects the actual usage of system memory. |
Swap | A portion of the disk used as virtual memory when RAM is insufficient. Swapping out data to disk and swapping it back in when needed can cause significant disk I/O, leading to performance degradation. Swap usage should be minimized. |
cat
cat
is short for “concatenate” and is typically used to view the contents of files.
Usage | Description | Example |
---|---|---|
cat filename.txt | Displays the content of filename.txt in the terminal. | cat notes.txt |
cat > filename.txt | Creates a new file or overwrites an existing file. After running this command, the terminal waits for input. Type the content and press Ctrl + D to save. | cat > newfile.txt (then type and press Ctrl+D ) |
cat file1.txt file2.txt > combined.txt | Concatenates file1.txt and file2.txt , and writes the result to combined.txt . This will overwrite combined.txt if it already exists. | cat intro.txt body.txt > article.txt |
cat >> filename.txt | Appends new content to the end of the file. Press Ctrl + D to finish. | cat >> notes.txt (then type and press Ctrl+D ) |
uname
Use uname
to get system information such as the kernel, architecture, and OS.
Output:
1
2
3
(base) jaoneol@DESKTOP-B7GM3C5:/mnt/e/50.Utilities$ uname -a
Linux DESKTOP-B7GM3C5 6.6.87.1-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Mon Apr 21 17:08:54 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
(base) jaoneol@DESKTOP-B7GM3C5:/mnt/e/50.Utilities$
For reference, the file /etc/os-release
contains information about the current OS distribution.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
(base) jaoneol@DESKTOP-B7GM3C5:/mnt/e/50.Utilities$ cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.1 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
(base) jaoneol@DESKTOP-B7GM3C5:/mnt/e/50.Utilities$