Skip to content

This repository is a practical guide to essential Linux commands, covering topics like user and terminal management, file operations, text manipulation, and system navigation. It includes commands for working with files, directories, word counting, and advanced tasks like using Vim for editing and understanding the Linux file system hierarchy.

Notifications You must be signed in to change notification settings

panwar100/linux-command-cheat-sheet2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Linux-command-cheat-sheet2

Mastering Linux Commands with Examples

This repository provides a comprehensive guide to using Linux commands, with examples and screenshots for clarity.

Table of Contents

  1. User and Terminal Details
  2. File Operations
    • Creating, Viewing, and Appending
  3. Word Count and Line Count
  4. Head and Tail Commands
  5. Linux Command-Line Shortcuts
  6. Linux File System Hierarchy
  7. Move Command
  8. Copy Command
  9. TTY and Virtual Terminals
  10. Getting Command Information
  11. Editing with Vim

1. User and Terminal Details

To display the current user and terminal details:

Screenshot from 2024-11-28 17-11-45

2. File Operations

Create a file and append to it:

  • cat > f1
    • Purpose: Creates or overwrites the file f1.
    • Behavior: If f1 exists, its content will be erased, and new input will replace it. If f1 does not exist, it creates a new file.
    • Use Case: Start fresh with a new file or replace existing content.

image

  • cat >> f1
    • Purpose: Appends new content to the end of the file f1.
    • Behavior: If f1 exists, new input will be added to the end of the file without erasing the previous content. If f1 does not exist, it creates a new file.
    • Use Case: Add more content to an existing file without deleting its current data.

image

View file content:

  • cat f1
  • less f1
  • gedit f1 # like notepad
  • evince f1 # Open PDF file

3. Word Count (wc) Command

Display line, word, and character count of a file:

Screenshot from 2024-11-28 17-50-15

6: Number of lines

7: Number of words

33: Number of characters

Commands for specific counts:

  • Lines: wc -l f1
  • Words: wc -w f1
  • Characters: wc -c f1

Screenshot from 2024-11-28 17-52-47

4. Head and Tail Commands

Display first/last lines of a file:

  • head

Screenshot from 2024-11-28 17-55-46

  • tail

Screenshot from 2024-11-28 17-57-07

5. Linux Command-Line Shortcuts

Key shortcuts for efficient command-line use:

  • Ctrl + A: Move to the beginning of the line
  • Ctrl + E: Move to the end of the line
  • Ctrl + R: Search through command history
  • Ctrl + U: Clear the current line
  • Ctrl + L: Clear the screen

6. Linux File System Hierarchy

The Linux File System Hierarchy is an organized structure of directories and files that follows a standard layout, making it easy to navigate and manage. Here’s an overview of the main directories:

Screenshot from 2024-11-28 18-09-12

  • Root Directory: / The base of the Linux file system. All other directories and files stem from this root directory.

  • Key Directories in Linux

Screenshot from 2024-11-28 18-05-31

  • Paths: Absolute & Relative
    • Absolute path:Starts from the root (/) directory.

      cd /var

    • Relative path:Starts from the current working directory.

      cd /root/Desktop

7. Move Command

Move or rename files and directories:

  • Rename

Screenshot from 2024-11-28 18-27-49

  • Move

Screenshot from 2024-11-28 18-29-42

8. Copy Command

  • Copy a folder with its contents:

Screenshot from 2024-11-28 18-34-03

  • Copy file content to another file:

Screenshot from 2024-11-28 18-39-34

9. TTY and Virtual Terminals

  • Display terminal number:
    • tty
      • TTY stands for Teletypewriter, a term inherited from the early days of computing when physical terminals were used.
      • In modern Linux, a TTY represents a virtual terminal or text console that allows users to interact with the system.
      • Each TTY has a unique terminal number.

Screenshot from 2024-11-28 18-43-16

  • Switch to a virtual terminal:
    • Virtual terminals are text-based user interfaces that run independently of the graphical desktop environment.
    • By default, Linux provides 6 virtual terminals

Screenshot from 2024-11-28 18-54-41

Screenshot from 2024-11-28 18-47-29

10. Getting Command Information

  • date --help
  • man ls
  • pinfo mkdir
    • Navigation:
      • n: Next
      • p: Previous
      • d: Index

11. Editing with Vim

Basic Commands:

  • Insert mode: Press i
  • Save and exit: :wq!
  • Set line numbers: :se nu
  • Remove line numbers: :se nonu

Advanced Editing:

  • Copy three line: 3yy, Paste: p
  • Undo: u, Redo: Ctrl + r
  • Delete 10 lines: 10d
  • Copy 2 words: 2ya, Paste: p

Screenshot from 2024-11-28 19-00-10 Screenshot from 2024-11-28 19-00-24

About

This repository is a practical guide to essential Linux commands, covering topics like user and terminal management, file operations, text manipulation, and system navigation. It includes commands for working with files, directories, word counting, and advanced tasks like using Vim for editing and understanding the Linux file system hierarchy.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published