Welcome back to our Linux command-line journey! You’re staring at a blank terminal prompt. You know there are files in this directory—you’ve seen them with ls—but they’re just names. Black boxes. How do you see what’s inside? How do you read that README.txt? How do you check that error.log? And how do you change that config.ini file?
This is a fundamental barrier for every new Linux user. You’ve learned to navigate, but now you need to interact. In the world of Linux, where “everything is a file,” the inability to see and edit those files is like being in a library full of locked books.
Today, we’re not just giving you a key; we’re giving you a master set. We are going to explore, in exhaustive detail, the “Holy Trinity” of basic file interaction: cat, less, and nano.
cat: The simple, fast tool for a quick peek or for sticking files together.less: The powerful “pager” that lets you navigate massive log files with ease.nano: The friendly, simple text editor that lets you change files without a steep learning curve.
This isn’t just a brief overview. This is the ultimate, deep dive. By the end of this post, you will understand not just what these commands do, but why they exist, how to use their every feature, and when to choose one over the others. You will be able to confidently view, search, and edit files on any Linux system you encounter. Let’s unlock those books.
cat – The Concatenator
The first tool most users learn is cat. It’s simple, it’s fast, and its name is slightly misleading. cat stands for “concatenate,” which means to link things together in a chain. While it’s most commonly used to simply print the contents of a single file to the screen, its true, original purpose was to combine files.
Let’s explore every facet of this fundamental command.
cat Basic Syntax
The syntax for cat is as straightforward as it gets:
cat [OPTIONS] [FILE]...
[OPTIONS]are optional flags (which we’ll cover in detail) that modify the command’s behavior.[FILE]...is the list of files you want it to act on. If no file is given,catreads from “standard input” (your keyboard), a behavior we’ll explore.
Core Use Cases of cat (With Exhaustive Examples)
Let’s build from the ground up, starting with the simplest use and moving to cat‘s true power.
1. Viewing a Single, Short File
This is the most common, everyday use of cat. You have a file, story.txt, and you want to read it.
Command: cat story.txt
What Happens: cat reads the entire contents of story.txt and writes it to “standard output,” which is your terminal screen.
Example: If story.txt contains:
The quick brown fox
jumps over
the lazy dog.
The terminal will display:
$ cat story.txt
The quick brown fox
jumps over
the lazy dog.
$

The Critical Pitfall: What if story.txt wasn’t 3 lines long, but 3,000? cat would still read all 3,000 lines and dump them to your screen. The text would fly by, and you’d only see the last page of content. This is the primary weakness of cat for viewing files and the exact problem that less solves.
Rule of Thumb: Only use cat to view a file if you are sure it’s short (e.g., under 20-30 lines).
2. Viewing Multiple Files
This is where the “concatenate” name starts to make sense. You can give cat more than one file, and it will read them in order and print them all, one after the other.
Command: cat chapter1.txt chapter2.txt
Example: If chapter1.txt contains:
It was the best of times.
And chapter2.txt contains:
It was the worst of times.
The terminal will display:
$ cat chapter1.txt chapter2.txt
It was the best of times.
It was the worst of times.
$
The two files are “concatenated” to your screen.
3. Concatenating Files into a New File (The Real Power)
This is the true, intended purpose of cat. Using a shell feature called “output redirection,” we can tell the shell to send cat‘s output to a new file instead of the screen.
The > (greater-than) symbol is the redirection operator. It means “take all output from the command on the left and put it in the file on the right.”
Command: cat chapter1.txt chapter2.txt chapter3.txt > full_book.txt
What Happens:
- The shell sees
> full_book.txt. It immediately createsfull_book.txt(or truncates/erases it if it already exists. This is a critical warning!). catruns. It readschapter1.txtand sends its contents to the output.- It then reads
chapter2.txtand sends its contents to the output. - It then reads
chapter3.txtand sends its contents to the output. - All of this output, instead of going to the screen, is redirected into the new
full_book.txt. - You will see no output on your terminal, just a new prompt. But if you now run
cat full_book.txt, you’ll see the combined contents of all three chapters.

4. Appending to an Existing File
What if you don’t want to overwrite full_book.txt? What if you just want to add chapter4.txt to the end of it? For this, we use the “append” operator: >>.
Command: cat chapter4.txt >> full_book.txt
What Happens: The >> operator tells the shell to add the output to the end of the file, rather than overwriting it. If the file doesn’t exist, it will be created. This is much safer for adding data.
5. Creating Files (The cat > Trick)
This is a neat, old-school trick. If you run cat without a filename, it reads from standard input (your keyboard). If you combine this with redirection, you can create a file on the fly.
Command: cat > new_note.txt
What Happens: The terminal prompt will disappear. Your cursor will just sit on a blank line. You are now “in” cat. Start typing:
Hello world.
This is my new note.
I am typing this directly.
When you are finished, press Ctrl+D (holding Ctrl and pressing D). This sends the “End of File” (EOF) signal. cat will stop reading and exit. The shell will then give you a new prompt. If you now run cat new_note.txt, you’ll see the text you just typed.
This is fantastic for quick notes, test files, or pasting a snippet from your clipboard into a new file without opening an editor.
Appending with the same trick: You can also append from your keyboard: cat >> existing_note.txt …type more text… Ctrl+D The new text will be added to the end of existing_note.txt.
6. Combining with Other Commands (Piping)
cat is often used as the first command in a “pipeline” of commands, using the | (pipe) symbol. The pipe takes the output of the command on the left and “pipes” it as the input to the command on the right.
Command: cat system.log | grep "ERROR"
What Happens:
cat system.logruns, reading the entire file and dumping its contents to its output.- The
|pipe intercepts that output. - The
grep "ERROR"command receives the full file contents as its input. grepthen filters this input, line by line, and only prints the lines that contain the string “ERROR”.
The “Useless Use of cat” (UUoC) This is a famous topic in the Linux/Unix community. The command above: cat system.log | grep "ERROR" …is technically inefficient. It spawns an extra cat process just to dump a file. Most commands, including grep, are perfectly capable of reading files on their own: grep "ERROR" system.log
This second command does the exact same thing but is more efficient. It spawns only one process (grep) instead of two (cat and grep).
So why do people use cat | ...?
- Habit: It’s a simple, linear “left-to-right” way of thinking: “First, I get the file, then I filter it.”
- Readability: Some (not all) find it clearer to read.
- Flexibility: If you were-
cating multiple files, the pipeline makes sense:cat file1.log file2.log | grep "ERROR".
While it’s good to know the more efficient way, the “Useless Use of cat” is not a high crime. It’s just a common “code smell” you’ll see in the wild.
cat‘s Exhaustive Command-Line Options
This is where cat gets more interesting. These flags give you powerful formatting abilities.
-n, --number: Number all output lines. This is incredibly useful. It adds a line number, a tab, and then the line’s content.Command:cat -n story.txtOutput:1 The quick brown fox 2 jumps over 3 the lazy dog.-b, --number-nonblank: Number non-empty lines. This is often more useful than-n. It numbers the content lines but skips blank lines, making the numbering cleaner.Command: (Assumingstory.txtnow has a blank line)The quick brown fox jumps over the lazy dog.cat -b story.txtOutput:1 The quick brown fox 2 jumps over 3 the lazy dog.Notice the blank line is not numbered.-s, --squeeze-blank: Squeeze multiple adjacent blank lines. If you have a file with sections separated by 5 or 6 blank lines, this flag will “squeeze” them down to a single blank line, making the output much more compact.Command:cat -s messy_file.txt-E, --show-ends: Display$at the end of each line. This is a fantastic debugging tool. Why isn’t your script working? Maybe you have trailing whitespace (spaces or tabs) at the end of a line.cat -Emakes this invisible problem visible.Command:cat -E config.iniOutput:port=8080 $ host=localhost $ user=admin$ $You can immediately see that thehostline has extra spaces at the end.-T, --show-tabs: DisplayTABcharacters as^I. Another crucial debugging tool. In many files (like Python code or Makefiles), the difference between aTabandSpacesis critical and invisible. This flag makes tabs visible.Command:cat -T script.pyOutput:def my_function():$ ^Iprint("Hello")$You can now see that the indent is a tab.-v, --show-nonprinting: Show non-printing characters. This is a catch-all for other invisible characters (like control characters) that might be corrupting your file.-A, --show-all: The “show me everything” flag. This is the ultimate debugging flag. It is the same as running-vET. It will show non-printing chars (-v), tabs (-T), and line endings (-E). When a file is acting “weird,”cat -Ais your first step.Command:cat -A mystery_file.txtOutput:This^Ihas a tab $ and this has trailing space $ ^M$ and this has a weird windows line ending (the ^M).$
cat Gotchas and Summary
- Gotcha 1:
caton Binary Files: Don’t do it. A binary file is a non-text file, like an image (.jpg), a program, or a compressed file (.zip). If you runcat my_program, it will spew thousands of lines of meaningless gibberish (control codes) to your terminal. This can, in some rare cases, mess up your terminal session (making text invisible or garbled). If you want to find text inside a binary file, use thestringscommand. - Gotcha 2: The
cat file > fileTrap:NEVER do this.cat somefile.txt > somefile.txtYou might think this will… do nothing. Or maybe format it? WRONG. Remember: the shell processes redirection (>) first.- The shell sees
> somefile.txtand immediately truncates (erases)somefile.txt. - The shell then runs
caton the now-emptysomefile.txt. catreads 0 lines from the empty file.- The command finishes. You are left with an empty file. Your data is gone.
- The shell sees
cat Summary:
- Strengths: Simple, fast, great for viewing short files, and the standard tool for concatenating (combining) files. Its formatting options (
-n,-E,-A) make it a powerful debugging tool. - Weaknesses: Useless (and annoying) for viewing large files.
And that weakness is the perfect-seque into our next tool.
less – The Pager
less is the tool you should be using 90% of the time you want to view a file. It is a “pager,” which means it lets you view a file “page by page” (or screen by screen). Its name is a classic programmer joke. The original Unix pager was called more (because it would show you “more” of the file, one page at a time). The new, more powerful version was named less, because… “less is more.”
less is superior to more because it doesn’t need to read the entire file into memory before displaying it. It can open a 10GB log file instantly. It also allows you to scroll backward as well as forward (which more couldn’t).
less Basic Syntax
less [OPTIONS] [FILE]
Just give it a file, and it will open. less /var/log/syslog

The less Interface: Essential Navigation
When you run less, your terminal screen is “taken over.” You are now in the less application. The most important command is q (for Quit). Just press q to exit and return to your terminal prompt.
Here are the essential keys for navigation. You can use either the “vi keys” (like j/k) or the arrow keys.
q: Quit. (The most important command).- Scrolling Line-by-Line:
jorDown Arrow: Scroll forward one line.korUp Arrow: Scroll backward one line.
- Scrolling Page-by-Page:
forSpacebarorPage Down: Scroll forward one full screen.borPage Up: Scroll backward one full screen.
- Scrolling Half-a-Page:
d: Scroll forward (down) half a screen.u: Scroll backward (up) half a screen.
- Jumping to Start/End:
gorHome: Go to the very beginning of the file (line 1).GorEnd: Go to the very end of the file.
- Jumping to a Specific Line:
- Type a number, then
g. For example:100gwill jump to line 100. - Type a number, then
%. For example:50%will jump to the halfway-point of the file.
- Type a number, then
h: Help. This is your other best friend. Pressinghopens a full summary of alllesscommands, right insideless. Pressqto exit the help screen.
Searching in less (Its Killer Feature)
This is what makes less so powerful for log files.
/(Forward Search):- Press the
/key. - Your cursor will jump to the prompt at the bottom of the screen.
- Type your search term (e.g.,
Error) and pressEnter. lesswill jump to the next occurrence of “Error” in the file.- All matches will be highlighted.
- Press the

?(Backward Search):- Press the
?key. - Type your search term and press
Enter. lesswill jump to the previous occurrence of that term.
- Press the
n(Next Match):- After a search, press
nto jump to the next match (in the same direction as your original search).
- After a search, press
N(Previous Match):- Press
Nto jump to the previous match (in the opposite direction of your original search).
- Press
&(Filter / “Grep” mode):- This is an amazing, little-known feature.
- Press the
&key. - Type a pattern (e.g.,
sshd) and pressEnter. lesswill hide all lines that do not matchsshd. You are now only viewing the filtered lines.- To exit this filter mode and see the whole file again, type
&and pressEnterwith no pattern.
less‘s Exhaustive Command-Line Options
You can supercharge less before you even open it.
-N, --LINE-NUMBERS: Show line numbers. This is essential. It adds a line number gutter to the left side, just likecat -nbut interactively. I recommend this almost always.Command:less -N /var/log/syslog-i, --ignore-case: Case-insensitive search. If you search for/error, it will also find “ERROR” and “Error”. This flag makes it case-insensitive only if your search term is all lowercase. If you type/Error(with a capital), it will only search for “Error”. This is a “smart case” search.-I, --IGNORE-CASE: Force case-insensitive search. This is always case-insensitive, even if your pattern has uppercase letters.-S, --chop-long-lines: Disable line wrapping. This is the other essential flag for log files. Log lines are often very, very long. By default,lesswill wrap them, making them unreadable.less -Sdisables wrapping. Long lines will just go off the right side of the screen. You can then use theLeft ArrowandRight Arrowkeys to scroll horizontally.Pro-Tip: Runless -NS /var/log/syslog. This is the “God Mode” for log viewing: Line Numbers (-N) and No Wrapping (-S).-F, --quit-if-one-screen: Automatically quitslessif the entire file fits on one screen. This makeslessbehave likecatfor small files, but “do the right thing” (open the pager) for large files. Some people setlessas their default pager with this flag.-X, --no-init: Normally,lessclears the screen when you quit, returning you to your clean terminal. This flag prevents that. When you pressq, the file’s contents remain on your screen, and your prompt appears below. This is useful if you want to copy-paste something after quitting.-R, --raw-control-chars: If you’re viewing a file that has color codes (like the output ofgit logorls --color),lesswill normally show the ugly control codes (e.g.,[31m).less -Rrenders these colors correctly. Try this:ls -la --color=always /etc | less -R+command: Run a command on startup. This is a power user feature. The “command” is anylesskeystroke you would normally use.- Start at the end of a file:
less +G large.log(It will open scrolled to the end). - Start at a specific line:
less +150 config.ini - Start and search:
less +/Error system.log(It will open and immediately jump to the first instance of “Error”).
- Start at the end of a file:
Using less with Pipes
less is the ultimate “end of the pipe” command. Any command that produces a lot of output should be piped to less.
ls -la /etc | less(Browse a huge directory listing)ps aux | less(Browse all running processes)dmesg | less(Browse kernel messages)history | less(Browse your command history)
less is also the default pager for many commands. When you type man ls, you are actually inside less!
Advanced less Features (Inside the Pager)
F(Follow Mode): This is thelessequivalent oftail -f. PressShift+F(capital F) while viewing a file.lesswill go to the end of the file and “follow” it, printing new lines as they are added. This is perfect for monitoring a log file in real-time. To stop following, pressCtrl+C. You are then back in normallessmode, able to scroll and search.m[letter](Mark): Pressmfollowed by any letter (e.g.,ma). This “marks” your current position in the file with the letter ‘a’. Scroll somewhere else, and then…'[letter](Go to Mark): Press'(single-quote) followed by the letter you used (e.g.,'a).lesswill jump instantly back to your marked position.v(Edit): While viewing a file, pressv.lesswill launch your system’s default text editor (defined by the$EDITORenvironment variable) and open the current file at the current line. When you save and exit the editor, you will be right back inless. This is an incredible workflow for finding an error (/), and then instantly jumping to edit it (v).
less Summary
- Strengths: The best tool for viewing files, especially large ones. Opens instantly. Powerful search, navigation, and filtering. Can be used in any pipeline.
- Weaknesses: It is a viewer, not an editor. (Though the
vkey bridges that gap!)
Now that we can view anything, let’s learn how to change it.
nano – The Beginner-Friendly Editor
You’ve found the line you need to change with less. Now what? You could use a complex, powerful editor like vim or emacs, but those have a learning curve like a sheer cliff. You need to change one line, now.
Enter nano.
nano (short for “Nano’s ANOther editor”) is a simple, modeless, “what you see is what you get” text editor for the terminal. It was created as a free clone of the pico editor, which was popular for its simplicity.
nano‘s greatest feature is that it is discoverable. It tells you exactly how to use it.
nano Basic Syntax
nano [OPTIONS] [FILE]
nano new_script.sh(This will createnew_script.shand open it)nano existing_config.ini(This will open the existing file)
The nano Interface: Your Friendly Guide
When you open nano, you’ll see your file content (or a blank screen) and, most importantly, a two-line menu at the bottom.

This menu is the key. The ^ symbol means the Ctrl key.
^X Exit: MeansCtrl+Xwill exit the editor.^O WriteOut: MeansCtrl+Owill save the file.^W Where Is: MeansCtrl+Wwill search the file.
If you see M- (which stands for “Meta”), that means the Alt key.
M-U Undo: MeansAlt+Uwill undo your last action.
You don’t have to memorize anything. The most common commands are always visible.
The “Big Four” nano Commands (How to Live in nano)
You only need to know these four commands to be 100% productive in nano.
^X(Exit): This is how you quit. When you pressCtrl+X, one of two things will happen:- If you didn’t change the file: It just exits.
- If you did change the file: It will prompt you at the bottom:
Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ?You now have three choices:- Press
Yfor “Yes” (to save). - Press
Nfor “No” (to discard your changes and exit). - Press
Cfor “Cancel” (to not exit, and go back to editing). If you pressedY, it will ask for theFile Name to Write:. The current name will be filled in. Just pressEnterto confirm and save to that file (or type a new name to “Save As”).
- Press
^O(WriteOut / Save): This is the “Save” command (likeCtrl+Sin GUI apps). It saves your file without exiting. It will promptFile Name to Write:. Just pressEnterto confirm. You can now keep editing. It’s good practice to do this often.^W(Where Is / Search): This is how you find text.- Press
Ctrl+W. - The bottom menu changes. It will prompt
Search:. - Type your search term and press
Enter. - The cursor will jump to the first match.
- To find the next match, just press
Alt+W(M-Win the menu).
- Press
^G(Get Help): This isnano‘s other superpower. If you forget a command, pressCtrl+G. This opens a detailed help document insidenano. You can scroll through it (using the arrow keys, just like a normal file) to find the command you need. PressCtrl+Xto exit the help screen and return to your file.
Navigation and Editing: It Just Works
This is the beauty of nano.
- The Arrow Keys move the cursor.
Page UpandPage Downwork.HomeandEndwork.DeleteandBackspacework.- You just type. There is no “insert mode.” You are always in “insert mode.”
Cut, Copy, and Paste in nano
This is the only slightly tricky part, but it’s still simple.
- To Cut a Line: Move your cursor to the line and press
^K(Cut). The entire line is cut and placed innano‘s clipboard (the “cut buffer”). - To Paste a Line: Move your cursor to where you want to paste and press
^U(Uncut).
How to Cut/Copy a Selection (not the whole line):
- Move your cursor to the start of the text you want to select.
- Press
Alt+A(M-A). You’ll see[Mark Set]at the bottom. - Now, use your arrow keys to move the cursor. The text between the “mark” and your cursor will become highlighted.
- Once you’ve highlighted the text:
- Press
^K(Cut) to cut the selected text. - Press
Alt+6(M-6) to copy the selected text.
- Press
- Move your cursor where you want to paste and press
^U(Uncut).
nano‘s Exhaustive Command-Line Options
You can customize your nano session from the start.
+LINEor+LINE,COL: Go to Line/Column. This is incredibly useful.nano +150 server.conf(Opens the file and jumps to line 150)nano +10,5 script.py(Opens and jumps to line 10, column 5)-l, --linenumbers: Show line numbers. This is a must-have. It adds a line number gutter on the left, just likeless -N.nano -l script.py

-m, --mouse: Enable mouse support. Lets you use your mouse to click to set the cursor and use the scroll wheel to scroll. Very intuitive.-i, --autoindent: When you pressEnteron an indented line, the new line will automatically have the same indentation. Essential for coding.-w, --nowrap: Disables automatic line wrapping. Long lines will just continue off-screen, and the screen will scroll horizontally. This is much better for editing config files or code.-c, --constor--constantshow: Constantly show the cursor’s position (line, column) at the bottom, instead of only on-demand.-v, --view: View mode. Opens the file as read-only. You can’t accidentally break a system config file.-B, --backup: When you save a file, this flag will create a backup of the original file. For example, savingconfig.iniwill createconfig.ini~containing the old version. This is a lifesaver.
Permanent Customization: The .nanorc File
All those command-line options are great, but it’s annoying to type nano -limw every time. You can make these settings permanent by creating a file in your home directory called .nanorc.
Command: nano ~/.nanorc
Now, inside this new file, you can just write the settings you want. Use set for on/off flags.
Example .nanorc file:
# My permanent nano settings
set autoindent
set linenumbers
set mouse
set nowrap
set const
set backup
# Enable syntax highlighting
include "/usr/share/nano/*.nanorc"
Save and exit (^O, Enter, ^X). Now, every time you open nano, it will automatically have line numbers, auto-indent, mouse support, no wrapping, and will make backups!
Syntax Highlighting: nano‘s Secret Weapon
That last line in the .nanorc file is the most important: include "/usr/share/nano/*.nanorc"
This tells nano to load all the default syntax highlighting definitions. nano comes with highlighting for Python, Bash, C, HTML, CSS, and dozens of other languages. When you open a file (e.g., script.py), nano will recognize the .py extension and automatically color your code.

This makes it immeasurably easier to read code, spot typos, and edit scripts.
More nano Features (From the Help Menu)
Alt+U(Undo) andAlt+E(Redo): These are critically important.nanohas full undo/redo.^R(Read File): Prompts you for a filename. It will then insert the entire contents of that other file at your cursor’s current position.^T(To Spell): Runs a spell-checker (if one is installed on the system).^C(Cur Pos): Reports the current line, column, and character position.
nano Summary
- Strengths: Incredibly easy to learn. No modes. Discoverable (commands are on-screen). Can be customized with
.nanorcto be a surprisingly powerful and pleasant editor with syntax highlighting, line numbers, and mouse support. - Weaknesses: Not as powerful as
vimoremacsfor complex, large-scale code refactoring (but for everyday use, it’s perfect).
cat vs. less vs. nano – When to Use What
You now have three powerful tools in your arsenal. The final piece of the puzzle is knowing which one to grab for the job.
Here is your simple, scenario-based guide:
Scenario 1: “I need to see what’s in this README.md file. I’m pretty sure it’s short.”
- Tool:
cat README.md - Why: It’s the fastest way to just dump the content to your screen. If you’re wrong and it’s huge, you can press
Ctrl+Cto stop it and runless README.mdinstead.
Scenario 2: “I need to find a specific error in a 2GB server.log file.”
- Tool:
less -NS server.log - Why:NEVER use
cat.lesswill open the file instantly, no matter the size.- Use
-Nfor line numbers. - Use
-Sto prevent line wrapping (log lines are long). - Press
/and type your error message to search. - Press
nto find the next one.
- Use
Scenario 3: “I need to change the port number in config.ini.”
- Tool:
nano -l config.ini(or justnano config.iniif your.nanorcis set up). - Why: It’s an editor.
nanoopens the file.- Press
^W(Where Is) and typeportto find the line. - Use the arrow keys to go to the number, delete it, and type the new one.
- Press
^O(WriteOut/Save),Enterto confirm the filename. - Press
^X(Exit).
- Job done in 10 seconds.
Scenario 4: “I need to combine my three report_part_X.txt files into one final_report.txt.”
- Tool:
cat report_part_1.txt report_part_2.txt report_part_3.txt > final_report.txt - Why: This is the job
catwas born to do. It concatenates the files and the>redirects the combined output into a new file.
Scenario 5: “I want to monitor my web server’s access log in real-time.”
- Tool:
less +F /var/log/nginx/access.log - Why: Open
lessand use the+Fcommand to start in “Follow” mode. It’s liketail -fbut has all the power ofless(searching, filtering) built-in. Just pressCtrl+Cto stop following and start scrolling/searching.
You are no longer just staring at a terminal. You’ve graduated from a passive observer to an active participant. You have the fundamental keys to unlock, read, search, navigate, and change the files that form the bedrock of the entire Linux operating system.
What’s your favorite nano trick? Do you have a .nanorc setting you can’t live without? Did we miss a less feature you love? Leave a comment below and share your knowledge!








