Top 10 Essential Linux Commands: Must-Know Guide for Beginners

Basic Commands Introduction - Linux Command Fundamentals

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 - Check Current Location
  2. ls - List Files
  3. cd - Change Directory
  4. mkdir - Create Directory
  5. touch - Create File
  6. echo - Output Text
  7. cat - Display File Contents
  8. cp - Copy
  9. mv - Move/Rename
  10. rm - Delete
  11. Common Issues and Solutions
  12. Efficiency Techniques

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/user vs user)
  • With symbolic links, the actual location may differ from the display
  • Path separator is different from Windows (\\ vs /)

Practice Exercise

  1. Open your terminal
  2. Type pwd and press Enter
  3. 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 -a option
  • Filenames with spaces require quotes or escaping
  • Learn to read ls -l permission 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 cd alone 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 -p option
  • 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
  1. Check your current directory
  2. Create a directory named "my_profile"
  3. Move to the created directory
  4. Create an empty file named "profile.txt"
  5. Write your name to the file
  6. 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
  1. Create "website-project" directory and move into it
  2. Create src/css, src/js, src/images directories at once
  3. Create index.html and README.md in the root
  4. Write basic content to the HTML file
  5. 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 -rf if 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 ls or pwd after operations

Common Issues and Solutions

๐Ÿšจ "Permission denied" Error

Symptom

mkdir: cannot create directory 'test': Permission denied

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 sudo command (use with caution)
  • Check method: Use ls -la to check current permissions

๐Ÿšจ "No such file or directory" Error

Symptom

cd: Documents: No such file or directory

Cause and Solutions

  • Cause: The specified file or directory doesn't exist
  • Solution 1: Use ls command to check contents of current location
  • Solution 2: Use pwd to check current location and fix the path
  • Solution 3: Use Tab completion to enter the exact name

๐Ÿšจ "File exists" Error

Symptom

mkdir: cannot create directory 'project': File exists

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 -la to 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 line
  • Ctrl + E: Move to end of line
  • Ctrl + U: Delete from cursor to beginning of line
  • Ctrl + 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!

๐Ÿ“ข About Affiliate Links

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.

๐ŸŽ‰ 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.