update lpic: head,tail,wc doc
This commit is contained in:
@@ -0,0 +1,77 @@
|
|||||||
|
# 📘 **Using `head` and `tail` Commands in Linux/Unix**
|
||||||
|
|
||||||
|
Both `head` and `tail` are essential commands for viewing specific portions of a file quickly, without opening the entire file.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔝 `head` — Show the Top of a File
|
||||||
|
|
||||||
|
The `head` command displays the beginning part of a file.
|
||||||
|
|
||||||
|
### Syntax
|
||||||
|
|
||||||
|
```bash
|
||||||
|
head [options] file
|
||||||
|
```
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```bash
|
||||||
|
head file1
|
||||||
|
```
|
||||||
|
|
||||||
|
**Description**:
|
||||||
|
Displays the first 10 lines of `file1` (default behavior).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
head -n 5 file1
|
||||||
|
```
|
||||||
|
|
||||||
|
**Description**:
|
||||||
|
Shows the first 5 lines of `file1`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔚 `tail` — Show the Bottom of a File
|
||||||
|
|
||||||
|
The `tail` command displays the end part of a file.
|
||||||
|
|
||||||
|
### Syntax
|
||||||
|
|
||||||
|
```bash
|
||||||
|
tail [options] file
|
||||||
|
```
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```bash
|
||||||
|
tail file1
|
||||||
|
```
|
||||||
|
|
||||||
|
**Description**:
|
||||||
|
Displays the last 10 lines of `file1` (default behavior).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
tail -n 20 file1
|
||||||
|
```
|
||||||
|
|
||||||
|
**Description**:
|
||||||
|
Shows the last 20 lines of `file1`.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
tail -f file1
|
||||||
|
```
|
||||||
|
|
||||||
|
**Description**:
|
||||||
|
Follows the file as it grows — useful for watching logs in real-time.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✅ Summary of Options
|
||||||
|
|
||||||
|
| Command | Option | Description |
|
||||||
|
| ------- | ------------- | ------------------------------------------- |
|
||||||
|
| `head` | `-n <number>` | Show the first `<number>` lines |
|
||||||
|
| `tail` | `-n <number>` | Show the last `<number>` lines |
|
||||||
|
| `tail` | `-f` | Follow the file in real-time (live updates) |
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
# 📘 **Using the `wc` Command in Linux/Unix**
|
||||||
|
|
||||||
|
`wc` (word count) is a utility that counts lines, words, and bytes or characters in files. It’s useful for quickly getting file size details in text terms.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚙️ Syntax
|
||||||
|
|
||||||
|
```bash
|
||||||
|
wc [option] file
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔎 Basic Usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
wc file
|
||||||
|
```
|
||||||
|
|
||||||
|
**Example output:**
|
||||||
|
|
||||||
|
```
|
||||||
|
5 6 43 file1
|
||||||
|
```
|
||||||
|
|
||||||
|
This output means:
|
||||||
|
|
||||||
|
| Number | Meaning |
|
||||||
|
| ------ | ------------------- |
|
||||||
|
| `5` | Number of **lines** |
|
||||||
|
| `6` | Number of **words** |
|
||||||
|
| `43` | Number of **bytes** |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📋 Common Options
|
||||||
|
|
||||||
|
| Option | Description | Example |
|
||||||
|
| ------ | ------------------------- | ------------ |
|
||||||
|
| `-l` | Count **lines** only | `wc -l file` |
|
||||||
|
| `-w` | Count **words** only | `wc -w file` |
|
||||||
|
| `-c` | Count **bytes** only | `wc -c file` |
|
||||||
|
| `-m` | Count **characters** only | `wc -m file` |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📌 Notes
|
||||||
|
|
||||||
|
* `bytes (-c)` counts raw bytes, which might differ from characters (`-m`) in multibyte encodings like UTF-8.
|
||||||
|
* Without options, `wc` outputs lines, words, and bytes by default.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user