This repository provides a comprehensive guide to using Linux commands, with examples and screenshots for clarity.
- User and Terminal Details
- File Operations
- Creating, Viewing, and Appending
- Word Count and Line Count
- Head and Tail Commands
- Linux Command-Line Shortcuts
- Linux File System Hierarchy
- Move Command
- Copy Command
- TTY and Virtual Terminals
- Getting Command Information
- Editing with Vim
To display the current user and terminal details:
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.
- 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.
View file content:
- cat f1
- less f1
- gedit f1 # like notepad
- evince f1 # Open PDF file
Display line, word, and character count of a file:
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
Display first/last lines of a file:
- head
- tail
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
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:
-
Root Directory: / The base of the Linux file system. All other directories and files stem from this root directory.
-
Key Directories in Linux
- Paths: Absolute & Relative
-
Absolute path:Starts from the root (/) directory.
cd /var
-
Relative path:Starts from the current working directory.
cd /root/Desktop
-
Move or rename files and directories:
- Rename
- Move
- Copy a folder with its contents:
- Copy file content to another file:
- 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.
- tty
- 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
- date --help
- man ls
- pinfo mkdir
- Navigation:
- n: Next
- p: Previous
- d: Index
- Navigation:
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