Top 10 Essential Linux Commands: Must-Know Guide for Beginners
Welcome to the world of Linux command line! This article explains the 10 essential commands every Linux user should learn first with practical examples. Master these commands and you'll have solid foundations for Linux operations.
Table of Contents
1. pwd - Display Current Directory
pwd stands for "Print Working Directory" and displays the path of your current directory.
Basic Usage
$ pwd
/home/user
๐ก Tip: When you get lost, use pwd to check where you are!
โ ๏ธ Common Pitfalls
- Understand the difference between relative and absolute paths (
/home/uservsuser) - With symbolic links, the actual location may differ from the display
- Path separator is different from Windows (\\ vs /)
Practice Exercise
- Open your terminal
- Type
pwdand press Enter - The displayed path is your current directory
2. ls - List Files and Directories
ls stands for "List" and displays files and subdirectories in a directory.
Basic Usage
$ ls
Documents Downloads Pictures Videos
Useful Options
| Option | Description | Example |
|---|---|---|
-l |
Display detailed information (long format) | ls -l |
-a |
Show hidden files | ls -a |
-h |
Display file sizes in human-readable format | ls -lh |
-t |
Sort by modification time | ls -lt |
Combined Example
$ ls -la
total 32 drwxr-xr-x 5 user user 4096 Jan 11 10:00 . drwxr-xr-x 20 user user 4096 Jan 11 09:00 .. -rw-r--r-- 1 user user 220 Jan 11 08:00 .bashrc drwxr-xr-x 2 user user 4096 Jan 11 10:00 Documents
โ ๏ธ Common Pitfalls
- Hidden files (starting with .) are not shown without the
-aoption - Filenames with spaces require quotes or escaping
- Learn to read
ls -lpermission notation (rwxrwxrwx) - Directories start with "d" in the first character
3. cd - Change Directory
cd stands for "Change Directory" and changes your working directory.
Basic Usage
$ cd Documents
# Moves to Documents directory
Special Directory Specifications
cd ~
Move to home directory
cd ..
Move to parent directory (one level up)
cd -
Return to previous directory
cd /
Move to root directory
Practice Example: Directory Navigation
$ pwd /home/user $ cd Documents $ pwd /home/user/Documents $ cd .. $ pwd /home/user
โ ๏ธ Common Pitfalls
- Directory names with spaces require quotes (e.g.,
cd "My Documents") - Running
cdalone moves to home directory - Distinguish between relative paths (Documents) and absolute paths (/home/user/Documents)
- Specifying non-existent directory results in "No such file or directory" error
4. mkdir - Create Directory
mkdir stands for "Make Directory" and creates new directories.
Basic Usage
$ mkdir my_project
# my_project directory is created
Useful Options
Create parent directories too (-p)
$ mkdir -p projects/web/frontend
# Creates projects, web, frontend directories hierarchically
Create multiple directories at once
$ mkdir dir1 dir2 dir3
# Creates dir1, dir2, dir3 simultaneously
โ ๏ธ Common Pitfalls
- If a directory with same name already exists, you get "File exists" error
- If parent directory doesn't exist, you need the
-poption - In locations without permission, you get "Permission denied" error
- Names containing invalid characters (like /) cannot be used
5. touch - Create Empty File
The touch command creates new empty files or updates timestamps of existing files.
Basic Usage
$ touch newfile.txt
# newfile.txt is created
Create Multiple Files Simultaneously
$ touch file1.txt file2.txt file3.txt
# Creates 3 files simultaneously
๐ก Tip: touch doesn't modify existing file contents. Only the timestamp is updated.
โ ๏ธ Common Pitfalls
- When run on existing file, contents are preserved but modification time changes
- Cannot create files with same name as a directory
- Be aware of file extensions (.txt, .log, etc. based on purpose)
- In locations without permission, you get "Permission denied" error
6. echo - Output Text
The echo command outputs text to the screen or writes it to files.
Basic Usage
$ echo "Hello, Linux!"
Hello, Linux!
Output to File
Create new/Overwrite (>)
$ echo "First line" > file.txt
Append (>>)
$ echo "Second line" >> file.txt
Display Variables
$ echo $HOME
/home/user
โ ๏ธ Common Pitfalls
- Quote usage: Single (') and double (") quotes behave differently with variable expansion
- Be aware of redirection: (>) overwrites, (>>) appends
- Special characters ($, *, ?, etc.) may cause unintended behavior
- Text with newlines must be enclosed in quotes
7. cat - Display File Contents
cat stands for "Concatenate" and displays file contents or concatenates multiple files.
Basic Usage
$ cat file.txt
This is the content of file.txt Line 2 Line 3
Useful Features
Display with line numbers (-n)
$ cat -n file.txt
1 This is the content of file.txt
2 Line 2
3 Line 3
Concatenate Multiple Files
$ cat file1.txt file2.txt > combined.txt
โ ๏ธ Common Pitfalls
- Specifying non-existent file results in "No such file or directory" error
- Displaying huge files causes excessive scrolling (less command recommended)
- Displaying binary files may cause garbled text or terminal corruption
- When concatenating multiple files, pay attention to the order
8. cp - Copy Files or Directories
cp stands for "Copy" and copies files or directories.
Basic Usage
$ cp original.txt copy.txt # Copy file $ cp -r folder/ backup_folder/ # Copy directory
โ ๏ธ The cp command is crucial for professional work.
For safe usage and advanced techniques, see the detailed explanation in "File Operations Guide (Basics)".
9. mv - Move/Rename Files
mv stands for "Move" and moves files/directories or changes their names.
Basic Usage
$ mv oldname.txt newname.txt # Rename $ mv file.txt Documents/ # Move
โ ๏ธ The mv command is critical for file operations.
For safe usage and accident prevention techniques, see the detailed explanation in "File Operations Guide (Basics)".
10. rm - Delete Files or Directories
rm stands for "Remove" and deletes files or directories.
Basic Usage
$ rm unwanted.txt # Delete file $ rm -i important.txt # Delete with confirmation
๐จ Critical: rm command cannot be undone once executed!
โ ๏ธ The rm command is extremely dangerous.
For the dangers of rm -rf and safety measures, see the detailed explanation in "File Operations Guide (Basics)".
Please review before using in professional work.
Practice Exercises: Progressive Learning Challenges
๐ข Beginner Level: Get Familiar with Basic Operations
Exercise 1: Create Self-Introduction Folder
Goal: Create your own folder structure and a simple profile file
Steps
- Check your current directory
- Create a directory named "my_profile"
- Move to the created directory
- Create an empty file named "profile.txt"
- Write your name to the file
- View the file contents
View Solution
$ pwd /home/user $ mkdir my_profile $ cd my_profile $ touch profile.txt $ echo "Name: John Doe" > profile.txt $ cat profile.txt Name: John Doe
๐ก Intermediate Level: Practical Scenario
Exercise 2: Build Website Project
Goal: Create a typical directory structure used in real web development
Steps
- Create "website-project" directory and move into it
- Create src/css, src/js, src/images directories at once
- Create index.html and README.md in the root
- Write basic content to the HTML file
- Check the file structure
View Solution
$ mkdir website-project && cd website-project
$ mkdir -p src/{css,js,images}
$ touch index.html README.md
$ echo "<!DOCTYPE html><html><body><h1>Hello World</h1></body></html>" > index.html
$ ls -la
$ ls -la src/
๐ก Exercise Tips
- Don't fear mistakes: You can delete and retry with
rm -rfif you make errors - Use Tab completion: Press Tab key when entering filenames or directory names
- Use command history: Use โ key to recall past commands
- Make verification a habit: Check the situation with
lsorpwdafter operations
Common Issues and Solutions
๐จ "Permission denied" Error
Symptom
Cause and Solutions
- Cause: Attempting to create files/directories in a location without write permission
- Solution 1: Create in a location with permission (such as home directory)
- Solution 2: Use
sudocommand (use with caution) - Check method: Use
ls -lato check current permissions
๐จ "No such file or directory" Error
Symptom
Cause and Solutions
- Cause: The specified file or directory doesn't exist
- Solution 1: Use
lscommand to check contents of current location - Solution 2: Use
pwdto check current location and fix the path - Solution 3: Use Tab completion to enter the exact name
๐จ "File exists" Error
Symptom
Cause and Solutions
- Cause: A file or directory with the same name already exists
- Solution 1: Use a different name
- Solution 2: Delete the existing one before creating
- Check method: Use
ls -lato check existing files/directories
๐ก Handling Filenames with Spaces
Issue
Errors occur when operating on filenames with spaces like "My Document"
Solutions
# โ Wrong method $ cd My Document cd: My: No such file or directory # โ Correct method 1: Use quotes $ cd "My Document" # โ Correct method 2: Use escape $ cd My\ Document
๐ก Case Sensitivity
Important Note
Linux strictly distinguishes between uppercase and lowercase letters
# These are all treated as different files $ touch file.txt $ touch File.txt $ touch FILE.txt $ ls FILE.txt File.txt file.txt
Efficiency Techniques: Speed Up Command Line Work
โจ๏ธ Keyboard Shortcuts
Tab Completion
How to use: Type part of filename or directory name and press Tab key
$ cd Doc[Tab] $ cd Documents/
Command History
How to use: Use โโ keys to recall past commands
$ history # Display history list $ !! # Re-execute previous command $ !ls # Re-execute last "ls" command
Cursor Movement
How to use: Efficient movement in long command lines
Ctrl + A: Move to beginning of lineCtrl + E: Move to end of lineCtrl + U: Delete from cursor to beginning of lineCtrl + K: Delete from cursor to end of line
๐ Command Chaining Techniques
Command Chain (&&)
Execute next command only if previous one succeeds
$ mkdir project && cd project && touch README.md
Semicolon Chaining (;)
Execute sequentially regardless of success or failure
$ pwd; ls -la; date
Background Execution (&)
Run command in background
$ long-running-command &
โญ Wildcard Usage
Asterisk (*)
Matches any string
$ ls *.txt # Files ending with .txt $ cp project_* backup/ # Files starting with project_
Question Mark (?)
Matches any single character
$ ls file?.txt # file1.txt, fileA.txt, etc.
Brackets ([])
Matches any of the specified characters
$ ls file[123].txt # file1.txt, file2.txt, file3.txt $ ls file[a-z].txt # filea.txt through filez.txt
๐ฏ Practical Time-Saving Tricks
1. Batch Project Setup
$ mkdir -p myapp/{src,docs,tests} && cd myapp && touch README.md && echo "# My App" > README.md
2. Batch File Rename
$ for file in *.txt; do mv "$file" "${file%.txt}.bak"; done
3. Check Directory Size
$ du -sh * # Display size of each folder $ df -h # Check disk usage
๐ก Tips for Improvement
- Use daily: Touch the command line every day, even a little
- Create aliases: Register shortcuts for frequently used commands
- Read manuals: Check details with
man command_name - Learn by practice: Try using in actual projects
Summary
These 10 basic commands are the foundation of foundations for using Linux.
- Navigation:
pwd,ls,cd - Creation:
mkdir,touch,echo - Display:
cat - Operations:
cp,mv,rm
Master these and your learning of more advanced commands will progress smoothly!
This site is a participant in the Amazon Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.co.jp. Product prices are not affected.
๐ Recommended Books for Learning Basic Commands
We've carefully selected truly useful books to help you efficiently master basic commands. From comprehensive reference books to practical introductions, choose according to your level.
๐ The New Linux Textbook (ๆฐใใLinuxใฎๆ็งๆธ)
Target Level: Beginner to Intermediate
A standard textbook for systematically learning basic commands. Thoroughly explains from basic commands like pwd, ls, cd, mkdir, rm to pipes and redirection. Helps deepen not just "how to use" commands but essential understanding of "why these commands are needed."
๐ Linux Command Book Beginners 6th Edition (Linuxใณใใณใใใใฏ ใใฎใใผใบ ็ฌฌ6็)
Target Level: Beginner (Use as reference)
A practical book for looking up basic commands like a dictionary. Covers extensive commands including the 10 commands introduced in this article: pwd, ls, cd, mkdir, touch, echo, cat, cp, mv, rm. Perfect as a desk companion for quickly finding commands you want to use.
๐ Linux for Beginners - Learning While Resolving Simple Questions (ๅ ฅ้่ ใฎLinux - ็ด ๆดใช็ๅใ่งฃๆถใใชใใๅญฆใถ)
Target Level: Beginner (Practical introduction)
An introduction book for practically learning basic commands while addressing beginners' "simple questions." Like this article, starts with basic commands like pwd, ls, cd and gradually levels up. Learn while resolving questions like "why use this command?"
๐ Linux Server Construction and Operation Guide from Zero 2nd Edition (ใผใญใใใฏใใใLinuxใตใผใใผๆง็ฏใป้็จใฌใคใ ็ฌฌ2็)
Target Level: Intermediate to Advanced
A practical book for using basic commands in professional work. After mastering basic command usage, learn systematically how to use them in actual server construction and operation. Strongly recommended for those who want to know "how to use commands in professional work."
๐ Master Basic Commands Through Practice!
After acquiring knowledge from books, consolidate your learning by hands-on practice with Penguin Gym Linux exercises. You'll definitely improve your skills by actually using basic commands like pwd, ls, cd.