0% found this document useful (0 votes)
31 views1 page

Working With Text Files in Bash

The document introduces essential Bash commands for viewing and manipulating text files, including 'cat', 'less', 'head', and 'tail'. Each command is explained with its usage, options, and examples. These commands are crucial for inspecting and understanding text file contents.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views1 page

Working With Text Files in Bash

The document introduces essential Bash commands for viewing and manipulating text files, including 'cat', 'less', 'head', and 'tail'. Each command is explained with its usage, options, and examples. These commands are crucial for inspecting and understanding text file contents.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

# Working with Text Files in Bash

This file introduces commands for viewing and manipulating the content of text files.

1. cat: Concatenate and Display Files


- Displays the content of one or more files.
- `cat <filename>`: Shows the content of the specified file.
- `cat file1.txt file2.txt`: Shows the content of both files concatenated.
- Example: `cat README.md`

2. less: View File Content Page by Page


- Allows you to view large files without loading the entire content into memory.
- Use spacebar to go to the next page, 'b' for the previous page, and 'q' to quit.
- `less <filename>`: Opens the file in the less viewer.
- Example: `less large_log_file.txt`

3. head: Display the Beginning of a File


- Shows the first few lines of a file (default is 10).
- `head <filename>`: Shows the first 10 lines.
- `head -n <number> <filename>`: Shows the first specified number of lines.
- Example: `head config.ini`, `head -n 5 data.csv`

4. tail: Display the End of a File


- Shows the last few lines of a file (default is 10). Useful for monitoring logs.
- `tail <filename>`: Shows the last 10 lines.
- `tail -n <number> <filename>`: Shows the last specified number of lines.
- `tail -f <filename>`: Follows the file in real-time, displaying new lines as they are added.
- Example: `tail access.log`, `tail -f error.log`

These commands are essential for inspecting and understanding the contents of text-based
files.

You might also like