Skip to content

Chapter 3 of 7

Inspecting and Editing Files

Inspecting the contents of files is a frequent task. cat filename concatenates and prints the whole file to the screen, which is fine for short files but unwieldy for large ones. Piping through less, as in cat file | less, allows page-by-page navigation using Space to advance, b to go back, and q to quit. For quick checks, head filename shows the first ten lines and tail filename shows the last ten; the -n flag adjusts that count, and tail -f follows a file in real time, making it ideal for watching logs grow.

When you need to create or modify file contents directly from the terminal, two editors dominate. nano is the friendlier option: open a file with nano file, save with Ctrl+O, and exit with Ctrl+X. Vim is more powerful but has a steeper learning curve. It operates in modes — Normal mode for navigation and commands, Insert mode (entered with i) for typing, and Visual mode (v) for selecting text. From Normal mode, :w saves, :q quits, and :wq saves and quits together.

Whenever you are unsure how a command behaves, Linux offers built-in documentation. command --help prints a short usage summary, while man command opens the full manual page, navigated with the same keys as less and exited with q. These references are invaluable for discovering flags and behaviors without leaving the terminal.

All chapters
  1. 1Introduction to the Linux Command Line
  2. 2Navigating and Managing the Filesystem
  3. 3Inspecting and Editing Files
  4. 4Permissions, Searching, and Data Flow
  5. 5Processes, Resources, and Shell Customization
  6. 6Networking and Package Management
  7. 7Archiving, Compression, and Automation

Drill it

Reading is not remembering. These come from the Linux Command Line deck:

Q

What is the Linux command line interface (CLI)?

The Linux CLI is a text-based interface for interacting with the operating system using commands entered via a terminal emulator, allowing users to perform task...

Q

What is a shell in Linux?

A shell is a program that interprets commands entered into the CLI, processes them, and communicates with the kernel; common shells include Bash (Bourne Again S...

Q

How do you open a terminal in Linux?

Use keyboard shortcuts like Ctrl+Alt+T on Ubuntu or search for 'Terminal' in the applications menu; it launches a shell session for command execution.

Q

What does the <code>pwd</code> command do?

The pwd (Print Working Directory) command displays the absolute path of the current working directory, helping users confirm their location in the filesystem.