AI Reading
Quick summary of this article
This chapter introduces key Linux command-line tools for viewing and editing files in WSL Ubuntu, explaining that tools like cat, less, nano, and vim allow you to work with files entirely in the terminal without a graphical interface.
- Use cat to display the entire contents of a short file directly in the terminal, and use less to scroll through long files with search and navigation commands.
- head and tail show the first or last 10 lines of a file by default; tail -f provides live updates for log files.
- nano is a beginner-friendly text editor with simple controls like Ctrl+O to save and Ctrl+X to exit, ideal for quick configuration changes.
- vim is a powerful but advanced editor with a learning curve; basic commands include i for insert mode, :wq to save and quit, and dd to delete a line.
- Combine commands like cat filename.txt | grep "word" to search within files, and use nano ~/.bashrc to edit configuration files.
Chapter 4: Viewing and Editing Files in WSL Ubuntu (cat, nano, vim, less)
In Linux, working with files often means using the terminal. Whether you’re reading logs, editing config files, or writing scripts, you’ll rely on powerful command-line tools.
This chapter covers essential commands for viewing and editing files: cat, less, nano, and vim. Each has its strengths — and once you get comfortable, you’ll never need a GUI for quick edits.
📄 Viewing Files in the Terminal
📌 cat – View Entire File (No Scroll)
Displays the contents of a file directly in the terminal.
cat filename.txt
Good for short files. For longer files, use less.
📌 less – Scroll Through Long Files
Allows you to scroll up and down through long files easily.
less filename.txt
↑/↓orPageUp/PageDown– scrollq– quit/word– search forwardn– next result
📌 head & tail – View Top/Bottom of Files
head filename.txt # First 10 lines
tail filename.txt # Last 10 lines
tail -f logfile.log # Live updates (logs)
📝 Editing Files in the Terminal
📌 nano – Simple Text Editor
Beginner-friendly and easy to use. Ideal for quick config changes.
nano myfile.txt
Basic nano controls:
Ctrl + O– SaveCtrl + X– ExitCtrl + K– Cut lineCtrl + U– Paste line
📌 vim – Powerful Editor (Advanced Users)
vim is a highly powerful terminal editor but has a learning curve.
vim myfile.txt
Vim basics:
i– Insert mode (start editing)Esc– Command mode:w– Save:q– Quit:wq– Save and quitdd– Delete lineu– Undo
If vim is not installed, you can install it using:
sudo apt install vim
📌 Pro Tips
- Use
lessto read long log files like/var/log/syslog - Edit config files like
.bashrcusingnano ~/.bashrc - Combine commands:
cat filename.txt | grep "searchword"
🧪 Practice Task
Open Ubuntu WSL and try the following:
# Create and edit a file
nano mynotes.txt
# Type some text, save and exit (Ctrl+O, Enter, Ctrl+X)
# View with cat and less
cat mynotes.txt
less mynotes.txt
# Add more lines
echo "New line added" >> mynotes.txt
head mynotes.txt
tail mynotes.txt
# Try vim (optional)
vim mynotes.txt
✅ Summary
cat– Quick file outputless– Scrollable viewingnano– Beginner-friendly text editor</li
