2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
# Basic Linux Commands
|
|
|
|
|
|
|
|
|
|
## 1. Navigation and File Management:
|
|
|
|
|
|
|
|
|
|
### a) pwd (Print Working Directory)
|
|
|
|
|
- Shows the current directory path
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `pwd`
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
### b) ls (List)
|
|
|
|
|
- Lists files and directories in the current directory
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `ls` [options] [directory]
|
|
|
|
|
#### Common options:
|
|
|
|
|
- l: Long format with details
|
|
|
|
|
- a: Show hidden files
|
|
|
|
|
- h: Human-readable file sizes
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
### c) cd (Change Directory)
|
|
|
|
|
- Changes the current directory
|
|
|
|
|
- Usage:
|
2024-09-03 19:13:24 -06:00
|
|
|
- `cd [directory]`
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
### d) mkdir (Make Directory)
|
|
|
|
|
- Creates a new directory
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `mkdir [directory_name]`
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
### e) rmdir (Remove Directory)
|
|
|
|
|
- Removes an empty directory
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `rmdir [directory_name]`
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
### f) touch
|
|
|
|
|
- Creates an empty file or updates timestamps
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `touch [filename]`
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
### g) cp (Copy)
|
|
|
|
|
- Copies files or directories
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `cp [source] [destination]`
|
|
|
|
|
#### Common Options:
|
2024-09-02 16:42:08 -06:00
|
|
|
-r: Recursive (for directories)
|
|
|
|
|
|
|
|
|
|
### h) mv (Move)
|
|
|
|
|
- Moves or renames files and directories
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `mv [source] [destination]`
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
### i) rm (Remove)
|
|
|
|
|
- Deletes files or directories
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `rm [options] [file/directory]`
|
|
|
|
|
#### Options:
|
2024-09-02 16:42:08 -06:00
|
|
|
-r: Recursive (for directories)
|
|
|
|
|
-f: Force deletion without prompting
|
|
|
|
|
|
|
|
|
|
## 2. File Viewing and Editing:
|
|
|
|
|
|
|
|
|
|
### a) cat (Concatenate)
|
|
|
|
|
- Displays file contents
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `cat [filename]`
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
### b) less
|
|
|
|
|
- Views file contents page by page
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `less [filename]`
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
### c) head
|
|
|
|
|
- Displays the first few lines of a file
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `head [options] [filename]`
|
|
|
|
|
#### Common Options:
|
2024-09-02 16:42:08 -06:00
|
|
|
-n [number]: Specify number of lines
|
|
|
|
|
|
|
|
|
|
### d) tail
|
|
|
|
|
- Displays the last few lines of a file
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `tail [options] [filename]`
|
|
|
|
|
#### Common Options:
|
2024-09-02 16:42:08 -06:00
|
|
|
-n [number]: Specify number of lines
|
|
|
|
|
-f: Follow file updates in real-time
|
|
|
|
|
|
|
|
|
|
### e) nano
|
|
|
|
|
- Simple text editor
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `nano [filename]`
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
## 3. File Permissions and Ownership:
|
|
|
|
|
|
|
|
|
|
### a) chmod (Change Mode)
|
|
|
|
|
- Modifies file permissions
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `chmod [options] [mode] [file/directory]`
|
|
|
|
|
|
2024-09-02 16:42:08 -06:00
|
|
|
### b) chown (Change Owner)
|
|
|
|
|
- Changes file ownership
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `chown [user]:[group] [file/directory]`
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
## 4. System Information:
|
|
|
|
|
|
|
|
|
|
### a) uname
|
|
|
|
|
- Displays system information
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `uname [options]`
|
|
|
|
|
#### Common Options:
|
2024-09-02 16:42:08 -06:00
|
|
|
-a: All information
|
|
|
|
|
|
|
|
|
|
### b) df (Disk Free)
|
|
|
|
|
- Shows disk space usage
|
|
|
|
|
- Usage: df [options]
|
2024-09-03 19:13:24 -06:00
|
|
|
#### Common Options:
|
2024-09-02 16:42:08 -06:00
|
|
|
-h: Human-readable sizes
|
|
|
|
|
|
|
|
|
|
### c) du (Disk Usage)
|
|
|
|
|
- Estimates file and directory space usage
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `du [options] [directory]`
|
|
|
|
|
#### Common Options:
|
2024-09-02 16:42:08 -06:00
|
|
|
-h: Human-readable sizes
|
|
|
|
|
-s: Summary for directory
|
|
|
|
|
|
|
|
|
|
## 5. Process Management:
|
|
|
|
|
|
|
|
|
|
### a) ps (Process Status)
|
|
|
|
|
- Lists running processes
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `ps [options]`
|
|
|
|
|
#### Common options:
|
|
|
|
|
-aux: Detailed information for all processes
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
### b) top
|
|
|
|
|
- Displays real-time system process information
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `top -u [user]`
|
|
|
|
|
#### Common Options:
|
|
|
|
|
-u: active apps for specified user
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
### c) kill
|
|
|
|
|
- Terminates processes
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `kill [options] [PID]`
|
|
|
|
|
#### Common Options:
|
2024-09-02 16:42:08 -06:00
|
|
|
-9: Force kill
|
|
|
|
|
|
|
|
|
|
## 6. Network Commands:
|
|
|
|
|
|
|
|
|
|
### a) ping
|
|
|
|
|
- Tests network connectivity
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `ping [options] [destination]`
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
### b) ifconfig
|
|
|
|
|
- Displays network interface information
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `ifconfig`
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
### c) ssh (Secure Shell)
|
|
|
|
|
- Connects to remote systems securely
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `ssh [user]@[host]`
|
|
|
|
|
#### Common Options:
|
|
|
|
|
-p: Specify a port
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
## 7. Package Management (for Debian-based systems):
|
|
|
|
|
|
|
|
|
|
### a) apt-get update
|
|
|
|
|
- Updates package lists
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `sudo apt-get update`
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
### b) apt-get upgrade
|
|
|
|
|
- Upgrades installed packages
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `sudo apt-get upgrade`
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
### c) apt-get install
|
|
|
|
|
- Installs new packages
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `sudo apt-get install [package_name]`
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
## 8. File Compression:
|
|
|
|
|
|
|
|
|
|
### a) tar
|
|
|
|
|
- Archives files
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `tar [options] [archive_name] [files/directories]`
|
|
|
|
|
- Usage: `tar -cvf archive.tar files/` "compress files from 'files' directory into archive.tar"
|
|
|
|
|
#### Common options:
|
2024-09-02 16:42:08 -06:00
|
|
|
-c: Create archive
|
|
|
|
|
-x: Extract archive
|
|
|
|
|
-v: Verbose
|
|
|
|
|
-f: Specify archive file
|
2024-09-03 19:13:24 -06:00
|
|
|
-t: List the contents inside the tar file
|
|
|
|
|
-z: Gzip the file after tar'ing it. "Double compressed"
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
### b) gzip
|
|
|
|
|
- Compresses files
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `gzip [filename]`
|
2024-09-02 16:42:08 -06:00
|
|
|
|
|
|
|
|
### c) gunzip
|
|
|
|
|
- Decompresses gzip files
|
2024-09-03 19:13:24 -06:00
|
|
|
- Usage: `gunzip [filename.gz]`
|