← Linux & the Command Line tutorial
Viewing & Editing Files
cat file dumps a whole file's contents to the screen —
fine for short files, unwieldy for long ones. less file
opens a scrollable, searchable viewer for longer files.
Example: choosing the right tool for the file's size
$ cat README.txt
$ less deploy.log
$ nano README.txt
Use cat for something short enough to fit on one screen;
switch to less the moment a file is longer than that — it
lets you scroll and search (press / then type to search,
q to quit) without flooding your terminal with hundreds of
lines at once. nano opens a simple in-terminal text editor
for quick edits, when a full IDE is overkill or simply unavailable, as is
often the case when connected to a remote server.
$ cat README.txt
$ nano README.txt
cat prints the file's full contents immediately; less opens it for scrollable, searchable reading; nano opens it for interactive editing directly in the terminal.