Terminal is an application that runs commands given by user, actually there is a special program inside Terminal called Shell – which reads in commands and execute them on Mac OS operating system.Terminal’s only job is to open windows and manage shells, while shells actually do real work of Command Execution. You can enter commands in Terminal and then Shell Program running inside terminal will execute those commands.
Commands are a kind of way to interact with Operating System and File System. These can be used for creating files/directories or checking status of processes being run by the Operating System. That’s why these can be really useful, moreover terminal commands can be used for building programming projects as well. Like you can build a Django Framework based website just from Terminal. Moreover, Terminal can be used for compiling/executing multiple files in a large Software Engineering Project. That’s why every beginner in Software Engineering should be aware about What is Terminal, How does it works and what are commands which can be used in it? Also if in case you already don’t know what is terminal then check out this article – What is Terminal in MAC OS?.
Anyway let’s get into what File Viewing Operations can be used in Mac Terminal.
Table of Contents
File Viewing Operations Commands
Below is a table containing commands which can be used for viewing files in the file system in Mac.
File Viewing Commands | Description |
---|---|
cat | For viewing entire content in a file |
less | For viewing text files one page at a time |
head | For viewing just few first lines of a text file |
tail | For viewing just last lines of a text file |
nl | For viewing text files with their lines numbered |
cat – File Viewing Command
For viewing entire content in a file.
cat command in general can be written as cat [options] [files]
For example – In the below picture, cat index.html command shows all of content in the HTML File.

Options for cat command
Options for cat command | Description |
---|---|
cat -v filename | For printing out any nonpriniting character |
cat -t filename | Kind of similar to -v option, but can also print tab |
cat -e filename | Similar to -v option, but also print newlines as $ |
cat -n filename | Prepend line number to every line |
cat -b filename | Prepend line numbers to nonblank lines |
cat -s filename | Squeeze each sequence of blank lines into a single blank line |
cat -v filename example

cat -t filename example

cat -e filename example

cat -n filename example

cat -b filename example

cat -s filename example

less – File Viewing Command
For viewing text files one page at a time and also can be used for editing the file.
less command in general can be written as less [option][filename]
For example – In the below picture, less index.html command opens up file in an editable mode.

Options for less command
Options for less command | Description |
---|---|
less -c filename | Clears the screen before displaying the content in file |
less -m filename | Displays the percentage of the file displayed so far in Terminal window |
less -N filename | Displays line numbers |
head – File Viewing Command
For viewing just few first lines of a text file.
head command in general can be written as head [option][filename]
For example – In the below picture, head index.html just shows some few first lines in index.html file.

Options for head command
Options for head command | Description |
---|---|
head -N filename | Print first N lines in file |
head -c N filename | Print first N bytes of file |
head -N filename command example

head -c N filename command example

tail – File Viewing Command
For viewing just last lines of a text file.
tail command in general can be written as tail [options][filename]
For example – In the below picture, tail index.html command shows some content of index.html file from end of file.

Options for tail command
Options for tail command | Description |
---|---|
tail -N filename | Prints last N lines of a file |
tail -c N filename | Prints out last N bytes of a file |
tail -N filename command example

tail -c N filename command example

nl – File Viewing Command
For viewing text files with their lines numbered.
nl command in general can be written as nl [options][filename]
For example – In the below picture, nl index.html command prints out content of index.html file with lines being numbered.

Options for nl command
Options for nl command | Description |
---|---|
nl -v N filename | Prints out lines of a file being numbered, starting with integer N |
nl -i N filename | Prints out lines of a file being numbered, incrementing number of line by N each time while moving from one line to next line |
nl -s S filename | Prints out lines of a file being numbered, but inserter S string inbetween number and line |
nl -v N filename

nl -i N filename

nl -s S filename

No Comments
Leave a comment Cancel