​ Linux Beginner's Guide: From Zero to Mastery

dbx April 9, 2026 58 views

 Linux Beginner's Guide: From Zero to Mastery


### Introduction


Mastering Linux is an essential skill for any programmer, as it forms the backbone of countless development environments and production systems. This guide provides a structured, step-by-step approach to learning Linux, from fundamental concepts to advanced command-line techniques.


---


### 1. Linux Fundamentals


#### 1.1 What is an Operating System?


An Operating System (OS) is the foundational software layer on top of the hardware. It acts as a bridge between the hardware and other software, managing system resources, controlling program execution, and providing basic services such as memory management and task scheduling.


#### 1.2 Linux: Kernel vs. Distribution


It is important to distinguish between the Linux kernel and a Linux distribution:


- **Linux Kernel**: The core system program, maintained by Linus Torvalds, which provides hardware abstraction, file system control, and multitasking capabilities.

- **Linux Distribution**: What most people refer to as "Linux". It is a complete operating system that bundles the Linux kernel with a collection of common software and tools.


#### 1.3 Linux vs. Windows


Linux offers several distinct advantages over other operating systems:


- Stability and efficiency

- Free (or low-cost)

- Fewer vulnerabilities with rapid patching

- Multi-tasking and multi-user capabilities

- Robust user and file permission security

- Suitable for embedded systems with small kernels

- Low resource consumption


#### 1.4 Major Linux Distributions


- **Red Hat Enterprise Linux (RHEL)**: Widely used in production environments for its performance and stability (commercial).

- **Fedora**: A desktop-oriented distribution from Red Hat, serving as a testing ground for technologies later incorporated into RHEL.

- **CentOS**: A free, community-supported distribution compiled from RHEL source code.

- **Debian**: Known for its stability and security, with a large user base, especially outside the US.

- **Ubuntu**: A Debian derivative with excellent compatibility for new hardware, popular for both desktop and server use.

- **Deepin**: A Chinese distribution that integrates and configures excellent open-source software.


---


### 2. Getting Started with the Terminal


#### 2.1 Connecting to a Remote Server


You can connect to a remote server via SSH (Secure Shell) using the command: `ssh root@121.42.11.34`. After entering the password, you will be logged into the remote server.


#### 2.2 The Shell


The **Shell** is a program that provides a command-line interface (CLI) for users to interact with the kernel. It is a command interpreter that supports variables, conditionals, loops, and other programming constructs, allowing users to write small programs known as shell scripts.


Common types of shells include:

- Bourne Shell (sh)

- Bourne Again Shell (**bash**) – the most commonly used shell

- C Shell (csh), TENEX C Shell (tcsh)

- Korn shell (ksh), Z Shell (zsh), Friendly Interactive Shell (fish)


To see which shell you are currently using, run: `echo $SHELL`. To see all shells installed on your system, run: `cat /etc/shells`.


#### 2.3 The Command Prompt


After entering the command-line environment, you'll see the shell's prompt, typically ending with a dollar sign (`$`) for regular users or a hash (`#`) for the root user. The prompt often displays your username, hostname, and current directory.


For example: `[root@iZm5e8dsxce9ufaic7hi3uZ ~]# pwd /root`

- `root`: username

- `iZm5e8dsxce9ufaic7hi3uZ`: hostname

- `~`: current directory (home directory)

- `#`: indicates root privileges


Useful commands:

- `whoami`: displays the current username

- `hostname`: displays the current hostname


#### 2.4 Command Format


Linux commands generally follow the structure: `command parameters`


- **Short parameters**: Use a single dash, e.g., `ls -a` (a for "all")

- **Multiple parameters**: Can be combined, e.g., `ls -al`

- **Long parameters**: Use two dashes, e.g., `ls --all`

- **Parameter values**: Short form: `command -p 10`, e.g., `ssh root@121.42.11.34 -p 22`; Long form: `command --paramters=10`, e.g., `ssh root@121.42.11.34 --port=22`


#### 2.5 Essential Shortcuts


| Shortcut | Action |

|----------|--------|

| ↑ / ↓ | Recall previously executed commands |

| Tab | Auto-complete commands or paths |

| Ctrl + R | Search through command history |

| Ctrl + L | Clear the screen |

| Ctrl + C | Abort the currently running command |

| Ctrl + U | Cut from cursor to beginning of line |

| Ctrl + K | Cut from cursor to end of line |

| Ctrl + W | Cut the word before the cursor |

| Ctrl + Y | Paste previously cut text |

| Ctrl + A | Jump to the beginning of the line |

| Ctrl + E | Jump to the end of the line |

| Ctrl + D | Close the shell session |


---


### 3. File and Directory Management


#### 3.1 Navigating Directories


- **`pwd`** (Print Working Directory): Displays the current directory path.

- **`which`**: Shows the path of the executable for a given command. Every command in Linux corresponds to an executable program.

- **`ls`** (List): Lists files and directories. Common options:

  - `-a`: Show all files, including hidden ones

  - `-l`: Display detailed list

  - `-h`: Human-readable sizes

  - `-t`: Sort by modification time

  - `-i`: Display inode numbers

- **`cd`** (Change Directory): Changes the current directory.

  - `cd /`: Go to the root directory

  - `cd ~`: Go to the home directory

  - `cd ..`: Go to the parent directory

  - `cd ./home`: Go to the "home" subdirectory of the current directory

  - `cd /home/lion`: Go to a specific absolute path

  - `cd` (no arguments): Return to the home directory


- **`du`** (Disk Usage): Estimates file and directory space usage.

  - `-h`: Human-readable

  - `-a`: Show sizes for files as well

  - `-s`: Display only the total size


#### 3.2 Viewing and Creating Files


- **`cat`** (Concatenate): Displays the entire content of a file (suitable for small files). Use `-n` to show line numbers.

- **`less`**: Displays file content page by page (suitable for large files). Navigation shortcuts:

  - `Space`: Forward one page

  - `b`: Backward one page

  - `Enter`: Forward one line

  - `y`: Backward one line

  - `d`: Forward half a page

  - `u`: Backward half a page

  - `q`: Quit

  - `/`: Search forward, `n` for next match, `N` for previous

- **`head`**: Shows the first few lines of a file (default: 10 lines). Use `-n` to specify the number.

- **`tail`**: Shows the last few lines of a file (default: 10 lines). Use `-n` to specify the number, and `-f` to follow the file as it grows.

- **`touch`**: Creates an empty file.

- **`mkdir`** (Make Directory): Creates a new directory. Use `-p` to create parent directories recursively, e.g., `mkdir -p one/two/three`.


#### 3.3 Copying and Moving Files


- **`cp`** (Copy): Copies files and directories.

  - `cp file file_copy`: Copy a file to a new name

  - `cp file one/`: Copy a file into a directory

  - `cp *.txt folder/`: Copy all `.txt` files to a folder

  - `-r`: Recursively copy directories

- **`mv`** (Move): Moves or renames files and directories.

  - `mv file one/`: Move a file to a directory

  - `mv file new_file`: Rename a file

  - `mv *.txt folder/`: Move all `.txt` files to a folder


#### 3.4 Deleting and Linking Files


- **`rm`** (Remove): Deletes files and directories. **Warning:** Linux does not have a recycle bin; deletion is permanent.

  - `-i`: Prompt for confirmation

  - `-f`: Force deletion

  - `-r`: Recursively delete directories (e.g., `rm -rf` for forceful recursive deletion)

- **`ln`** (Link): Creates links between files. Files in Linux are stored with three parts: filename, content, and permissions. Filenames are stored separately from content, linked via inodes.

  - **Hard links**: Two filenames share the same inode and content. Deleting one filename does not delete the content; the content is only removed when all hard links are deleted. Cannot link to directories.

  - **Soft links** (symbolic links): Similar to Windows shortcuts. Created with `ln -s file1 file2`. If the original file is deleted, the soft link becomes a dead link.


---


### 4. Users and Permissions


#### 4.1 User Management


Linux is a multi-user operating system. The `root` user is the superuser with the highest privileges.


- **`sudo`**: Executes a command with root privileges. You will typically be prompted for your password.

- **`useradd` + `passwd`**: Add a new user (requires root). `useradd lion` creates a user named "lion". `passwd lion` sets the password.

- **`userdel`**: Deletes a user. `userdel lion` removes only the user; `userdel -r lion` also removes their home directory.

- **`su`** (Switch User): Switches the current user context. `su lion` switches to user "lion". `su -` switches to the root user.


#### 4.2 Group Management


Each user in Linux belongs to at least one group. If not specified, a group with the same name as the user is created.


- **`groupadd`**: Creates a new group.

- **`groupdel`**: Deletes an existing group.

- **`groups`**: Shows the groups a user belongs to.

- **`usermod`**: Modifies user account settings.

  - `-l`: Rename a user (note: home directory must be manually changed)

  - `-g`: Change the user's primary group

  - `-G`: Add the user to supplementary groups

  - `-aG`: Append the user to supplementary groups without leaving the original group

- **`chgrp`**: Changes the group ownership of a file.

- **`chown`**: Changes the user (and optionally group) ownership of a file. Requires root privileges.

  - `chown lion file.txt`: Transfer ownership of `file.txt` to user "lion"

  - `chown lion:bar file.txt`: Change both user and group

  - `-R`: Recursively change ownership for directories


#### 4.3 File Permissions


- **`chmod`** (Change Mode): Modifies file access permissions.

  - `-R`: Apply recursively to directories and their contents


Understanding the output of `ls -l` is crucial. For example: `drwxr-xr-x 5 root root 4096 Apr 13 2020 climb`


The permission string (e.g., `drwxr-xr-x`) is interpreted as follows:


| Position | Character | Meaning |

|----------|-----------|---------|

| 1st | `d` | Directory (`-` for regular file, `l` for link) |

| 2nd-4th | `rwx` | Owner permissions (read, write, execute) |

| 5th-7th | `r-x` | Group permissions (read, execute) |

| 8th-10th | `r-x` | Other users' permissions (read, execute) |


**Using numeric permissions:**

- `r` (read) = 4

- `w` (write) = 2

- `x` (execute) = 1


Example: `chmod 640 hello.c` results in `-rw-r-----`, meaning:

- Owner (6 = 4+2): read and write

- Group (4): read only

- Others (0): no permissions


**Using symbolic permissions:**

- `u`: user/owner

- `g`: group

- `o`: other

- `a`: all

- `+`: add permission

- `-`: remove permission

- `=`: set permission exactly


Examples:

- `chmod u+rx file`: Add read and execute for the owner

- `chmod g+r file`: Add read for the group

- `chmod o-r file`: Remove read for others

- `chmod a+x file`: Add execute for all users

- `chmod u=rwx,g=r,o=- file`: Owner has full permissions, group has read only, others have none


---


### 5. Finding Files


- **`locate`**: Searches for files and directories by name using a pre-built database. Newly created files may not be found until you run `updatedb` to refresh the database. Supports wildcards and regular expressions.

- **`find`**: Performs a real-time search of the actual hard drive. It is more powerful and allows you to perform actions on found files. Syntax: `find <where> <what> <action>`


**Examples:**

- `find . -name "file.txt"`: Find by name in current directory and subdirectories

- `find /var/log -name "syslog*"`: Find all files starting with "syslog" in `/var/log`

- `find /var -size +10M`: Find files larger than 10MB in `/var`

- `find -name "*.txt" -atime -7`: Find `.txt` files accessed within the last 7 days

- `find . -name "file" -type f`: Find only files (not directories)

- `find -name "*.c" -exec chmod 600 {} \;`: Execute a command on each found file (replace `{}` with the filename)


---


### 6. Software Management with YUM


In Red Hat family distributions (like CentOS), software is managed using the **YUM** package manager, which interacts with a software repository.


**Common YUM commands:**

- `yum update` or `yum upgrade`: Update all packages

- `yum search xxx`: Search for a package

- `yum install xxx`: Install a package

- `yum remove xxx`: Remove a package


**Changing the YUM repository to a domestic mirror** (to improve speed):

1. Back up the original repository configuration:

   `mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup`

2. Download the Alibaba Cloud repository configuration:

   `wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo`

3. Generate a cache:

   `yum makecache`


---


### 7. Using the Manual Pages (man)


- **`man`**: Displays the manual for a command or function. Manuals are organized into sections:

  1. Executable programs or shell commands

  2. System calls (functions provided by the kernel)

  3. Library calls (functions within program libraries)

  4. Special files (usually in `/dev`)

  5. File formats and conventions

  6. Games

  7. Miscellaneous

  8. System administration commands

  9. Kernel routines


Usage: `man <section> <command>`. For example, `man 3 rand` looks up the `rand` function in section 3, and `man ls` looks up the `ls` command.


A typical manual entry includes:

- `NAME`: Command name and brief description

- `SYNOPSIS`: Usage syntax

- `DESCRIPTION`: Detailed explanation of options and behavior

- `SEE ALSO`: Related commands and references


For a quicker reference, many commands also support `--help` or `-h`.


---


### 8. Text Processing


#### 8.1 grep (Global Regular Expression Print)


Searches for text patterns in files and prints matching lines.

- `-i`: Ignore case

- `-n`: Show line numbers

- `-v`: Show lines that do **not** match

- `-r`: Recursively search directories

- `-E`: Use extended regular expressions


Examples:

- `grep path /etc/profile`: Find lines containing "path"

- `grep -E ^path /etc/profile`: Find lines starting with "path"

- `grep -E [Pp]ath /etc/profile`: Find "path" or "Path"


#### 8.2 sort


Sorts lines of a text file.

- `-o`: Write sorted output to a file

- `-r`: Reverse order

- `-R`: Random order

- `-n`: Numeric sort (default treats numbers as strings)


#### 8.3 wc (Word Count)


Counts lines, words, and characters.

- `-l`: Count lines

- `-w`: Count words

- `-c`: Count bytes

- `-m`: Count characters


#### 8.4 uniq


Removes or reports duplicate lines. **Note:** Only removes consecutive duplicates.

- `-c`: Count occurrences

- `-d`: Only show duplicate lines


#### 8.5 cut


Cuts out selected portions of each line.

- `-d`: Specify delimiter

- `-f`: Select fields (e.g., `cut -d , -f 1 file.txt`)


---


### 9. Redirection, Pipes, and Streams


In Linux, command output can go to three places: the terminal, a file, or as input to another command. The standard terminology uses:

- `stdin`: Standard input (keyboard)

- `stdout`: Standard output (terminal, non-error)

- `stderr`: Standard error (terminal, error messages)


#### 9.1 Redirection


- **`>`** : Redirects stdout to a new file (overwrites if the file exists)

  `cut -d , -f 1 notes.csv > name.csv`

- **`>>`** : Redirects stdout to a file, appending to the end (creates the file if it doesn't exist)

  `cut -d , -f 1 notes.csv >> name.csv`

- **`2>`** : Redirects stderr to a file

  `cat not_exist_file.csv > res.txt 2> errors.log`

- **`2>>`** : Redirects stderr, appending to a file

- **`2>&1`** : Redirects both stdout and stderr to the same location

  `cat not_exist_file.csv > res.txt 2>&1`

- **`<`** : Uses a file as stdin for a command

  `cat < name.csv`

- **`<<`** : Uses keyboard input (until a specified delimiter) as stdin

  `sort -n << END`


#### 9.2 Pipes (`|`)


Pipes connect commands, using the output of one command as the input of another. This is a powerful concept in the Unix philosophy.


Examples:

- `cut -d , -f 1 name.csv | sort > sorted_name.txt`

- `du | sort -nr | head`

- `grep log -Ir /var/log | cut -d : -f 1 | sort | uniq`


#### 9.3 Streams


A **stream** is a sequence of data (typically binary) processed incrementally. Pipes and redirection operate by processing data as streams, reading and handling data piece by piece rather than loading entire files into memory.


---


### 10. Process Management


#### 10.1 Viewing Processes


- **`w`** : Shows who is logged in and what they are doing. Displays system uptime, load averages, user information, and current commands.

- **`ps`** (Process Status): Takes a snapshot of current processes (static). Common options:

  - `-ef`: List all processes

  - `-efH`: List all processes in a tree format

  - `-u`: List processes for a specific user

  - `-aux`: Filter by CPU and memory usage

  - `-aux --sort -pcpu`: Sort by CPU usage descending

  - `-axjf`: Display as a tree (similar to `pstree`)

- **`top`** : Provides a dynamic, real-time view of running processes. Shows system summary (uptime, load average, tasks, CPU usage, memory) and updates continuously.

- **`kill`** : Terminates a process by its PID. Use `-9` to force termination.

  `kill 956` or `kill -9 7291`


#### 10.2 Process States


Linux processes can be in one of five states:

- **`R`** (Running): Currently executing

- **`S`** (Sleeping): Interruptible sleep (waiting for an event)

- **`D`** (Uninterruptible): Waiting for I/O, cannot be interrupted even with `kill`

- **`Z`** (Zombie): Terminated but process descriptor still exists

- **`T`** (Stopped): Suspended by a signal


#### 10.3 Foreground vs. Background Processes


By default, processes run in the **foreground**, reading from the keyboard and writing to the display. To run a process in the **background**, append an `&` symbol. Background processes allow you to continue using the terminal, but they are tied to the terminal session and will terminate if the session ends.


- **`nohup`** : Runs a process immune to hangup signals (e.g., terminal closure). Often used with `&`: `nohup cp name.csv name-copy.csv &`

- **`bg`** : Resumes a suspended background job, changing its state from "stopped" to "running"

- **`jobs`** : Lists background jobs for the current terminal session

- **`fg`** : Brings a background job to the foreground


#### 10.4 Daemons and systemd


A **daemon** is a special type of background process that runs independently of any user session. Daemons typically have names ending with 'd' (e.g., `systemd`, `httpd`) and are often started at system boot.


**systemd** is a collection of system management components, running as PID 1, responsible for starting and managing other services.


Common `systemctl` commands:

- `systemctl start nginx`: Start a service

- `systemctl stop nginx`: Stop a service

- `systemctl restart nginx`: Restart a service

- `systemctl status nginx`: Check service status

- `systemctl reload nginx`: Reload configuration without stopping

- `systemctl enable nginx`: Enable service to start at boot

- `systemctl disable nginx`: Disable automatic startup

- `systemctl is-enabled nginx`: Check if enabled

- `systemctl list-unit-files --type=service`: List all services and their startup status


---


### 11. File Compression and Archiving


**Archiving** (or "tarring") combines multiple files into a single archive file. **Compression** reduces the size of a file (often an archive). The `tar` command is commonly used for archiving, often combined with `gzip` or `bzip2` for compression.


#### 11.1 tar (Tape Archive)


- `tar -cvf sort.tar sort/`: Create an archive of the "sort" directory (`c`=create, `v`=verbose, `f`=file)

- `tar -cvf archive.tar file1 file2 file3`: Archive multiple files

- `tar -tf archive.tar`: List contents without extracting (`t`=list)

- `tar -rvf archive.tar file.txt`: Append a file to an existing archive (`r`=append)

- `tar -xvf archive.tar`: Extract an archive (`x`=extract)


#### 11.2 Compressed Archives


Use the `z` option for gzip compression or `j` for bzip2:

- `tar -czvf archive.tar.gz directory/`: Create a gzipped archive

- `tar -xzvf archive.tar.gz`: Extract a gzipped archive


#### 11.3 Viewing Compressed Files


Use `zcat`, `zless`, or `zmore` to view the contents of compressed files without decompressing them.


#### 11.4 zip/unzip


For compatibility with Windows zip files:

- `unzip archive.zip`: Extract

- `unzip -l archive.zip`: List contents without extracting

- `zip -r sort.zip sort/`: Recursively compress a directory


---


### 12. Compiling and Installing from Source


When a package is not available in the YUM repository, you can compile and install it from source code. Most Linux programs are open source and can be compiled to match your specific system.


**Basic steps:**

1. Download the source code

2. Extract the archive

3. Configure (`./configure`)

4. Compile (`make`)

5. Install (`make install`)


**Example: Compiling htop**

1. Download: `wget https://example.com/htop-3.0.0.tar.gz` (or use `scp` to transfer from local)

2. Extract: `tar -zxvf htop-3.0.0.tar.gz` then `cd htop-3.0.0`

3. Configure: `./configure` (checks for required build tools)

4. Compile: `make`

5. Install: `make install`


---


### 13. Networking


#### 13.1 ifconfig


Displays network interface configuration. If not found, install with `yum install net-tools`.

- `eth0`, `eth1`, etc.: Ethernet interfaces (wired connections)

- `lo`: Loopback interface (127.0.0.1), used for local communication and testing

- `wlan0`: Wireless LAN interface


#### 13.2 host


Converts between IP addresses and hostnames.

- `host github.com`: Look up the IP address of a domain

- `host 13.229.188.59`: Look up the hostname for an IP address


#### 13.3 ssh (Secure Shell)


Connects to a remote server using a secure, encrypted channel. `ssh user@ip:port` (default port is 22)


#### 13.4 SSH Configuration


- Server configuration: `/etc/ssh/sshd_config`

- Client configuration: `/etc/ssh/ssh_config` (global), `~/.ssh/config` (user-specific)


Common server configuration parameters:

- `Port`: SSH daemon port (default 22)

- `PermitRootLogin`: Allow root login

- `PasswordAuthentication`: Allow password authentication

- `PubkeyAuthentication`: Allow public key authentication


Client configuration example (`~/.ssh/config`):

```

Host lion

    HostName 172.x.x.x

    Port 22

    User root

```

After configuration, you can simply type `ssh lion` to connect


#### 13.5 Passwordless SSH Login


1. Generate a key pair on the client: `ssh-keygen` (defaults to RSA encryption)

   - Creates `~/.ssh/id_rsa` (private key) and `~/.ssh/id_rsa.pub` (public key)

2. Copy the public key to the server: `ssh-copy-id root@172.x.x.x`

   - This appends the public key to `~/.ssh/authorized_keys` on the server

3. Now you can log in without a password: `ssh root@172.x.x.x` or `ssh lion` (if configured)


#### 13.6 wget


Downloads files from HTTP or FTP servers directly from the terminal. It is robust, retrying failed downloads until completion. Use `-c` to continue an interrupted download.


#### 13.7 scp (Secure Copy)


Copies files between computers over a network using SSH encryption.

- Syntax: `scp user@ip:source_file user@ip:destination_file`

- Example: `scp ~/Desktop/htop-3.0.0.tar.gz root@121.42.11.34:.`


#### 13.8 rsync


Synchronizes files and directories locally or remotely. It is an intelligent version of `scp` often used for incremental backups.


Basic usage:

- `rsync -arv Images/ backups/`: Synchronize local directories

- `rsync -arv Images/ root@192.x.x.x:backups/`: Synchronize to a remote server


Options:

- `-a`: Archive mode (preserves permissions, timestamps, etc.)

- `-r`: Recursive (include subdirectories)

- `-v`: Verbose (detailed output)

- `--delete`: Delete files in the destination that are not in the source


#### 13.9 System Shutdown and Reboot


- `halt`: Shuts down the system (requires root)

- `reboot`: Restarts the system (requires root)

- `poweroff`: Powers off the system (does not require root)


---


### 14. Vim Editor


Vim (Vi Improved) is a powerful text editor widely used by programmers. It is a favorite among Unix-like system users alongside Emacs.


#### 14.1 Modes


Vim has four main modes:


1. **Normal Mode** (Interactive): Default mode when Vim starts. In this mode, you cannot type text directly. Instead, keys are used for navigation, deletion, copying, and other editing commands.

2. **Insert Mode**: The familiar text-editing mode. Enter by pressing `i`, `I`, `a`, `A`, `o`, or `O`. Exit by pressing `Esc`.

   - `i`: Insert before the cursor

   - `I`: Insert at the beginning of the line

   - `a`: Insert after the cursor

   - `A`: Insert at the end of the line

   - `o`: Insert a new line below the current line

   - `O`: Insert a new line above the current line

3. **Command Mode** (Last Line Mode): Enter by pressing `:` from Normal mode. Used for saving, quitting, searching, and configuration commands.

4. **Visual Mode**: Enter by pressing `v` (character), `V` (line), or `Ctrl+v` (block). Used for selecting and manipulating blocks of text.


#### 14.2 Basic Operations


**Opening a file:** `vim filename` (creates the file if it doesn't exist)


**Navigation in Normal Mode:**

- `h`, `j`, `k`, `l`: Left, down, up, right (arrow keys also work)

- `0`: Jump to the beginning of the line

- `$`: Jump to the end of the line

- `w`: Jump forward by word

- `gg`: Jump to the first line of the file

- `G`: Jump to the last line


**Exiting:**

- `:q`: Quit (will complain if changes are unsaved)

- `:q!`: Quit without saving

- `:wq` or `:x`: Save and quit


**Deleting (Cutting):**

- `x`: Delete the character under the cursor

- `dd`: Delete (cut) the current line

- `2dd`: Delete two lines starting from the current line

- `dw`: Delete from the cursor to the end of the word

- `d0`: Delete from the cursor to the beginning of the line

- `d$`: Delete from the cursor to the end of the line


**Copying (Yanking) and Pasting:**

- `yy`: Yank (copy) the current line

- `yw`: Yank a word

- `y$`: Yank from the cursor to the end of the line

- `y0`: Yank from the cursor to the beginning of the line

- `p`: Paste after the cursor or on the next line


**Other Useful Commands:**

- `u`: Undo

- `Ctrl + r`: Redo

- `r`: Replace a single character

- `/pattern`: Search forward for "pattern" (`n` for next, `N` for previous)

- `:set nu`: Show line numbers

- `:set nonu`: Hide line numbers


#### 14.3 Advanced Operations


**Find and Replace:**

- `:s/old/new`: Replace the first occurrence on the current line

- `:s/old/new/g`: Replace all occurrences on the current line

- `:2,4 s/old/new/g`: Replace on lines 2 through 4

- `:%s/old/new/g`: Replace globally in the entire file


**Inserting a File:** `:r filename` inserts the contents of another file at the cursor position


**Splitting the Screen:**

- `:sp filename`: Split horizontally

- `:vsp filename`: Split vertically

- `Ctrl + w` then `w`: Move between viewports

- `Ctrl + w` then `+`/`-`: Resize viewport

- `Ctrl + w` then `q`: Close the current viewport


**Running External Commands:** `:! command` executes a terminal command from within Vim, e.g., `:! ls`


#### 14.4 Visual Mode Operations


- `v`: Character-wise visual mode (select characters)

- `V`: Line-wise visual mode (select entire lines)

- `Ctrl + v`: Block-wise visual mode (select rectangular blocks)


In block visual mode, you can select multiple lines and use `I` to insert the same text at the beginning of each selected line (press `Esc` twice to apply)


#### 14.5 Vim Configuration


To make settings permanent, create a `.vimrc` file in your home directory (`cd ~`). You can add any Vim configuration commands to this file, allowing you to customize Vim into a powerful IDE-like environment.


---


### 15. Conclusion


This guide has covered the fundamental concepts and practical commands needed to start working effectively with Linux. From understanding the operating system and the shell, to managing files, processes, users, and permissions, and finally to advanced text processing and editing with Vim – these skills form the foundation of Linux proficiency. Regular practice and exploration will turn these commands into second nature, empowering you to harness the full power of the Linux command line.


Advertisement

Tags:

dbx

Written by dbx

Author at ITProgram