Command Line Essentials Part 2

This is Part 2 of Command Line Essentials(Part 1). In this Part I will be focusing mainly on common basic text file utilities. Utilities are what command line programs are called.


Options, or switches control how a utility works. For example rm -i works differently than rm. Utilities can have more than one option. ex rm -i-r. This can also be typed rm -ir. There are also a long version of switches for most utilities. --help is one example.

Other Terminal Access

There are other ways to access the CLI(command line interface) than opening a terminal emulator(like gnome-terminal). For example Ctrl-Alt-[F1-f6](C-M-F7 gets you back to normal) gives you a terminal interface to your operating system. You will also encounter a CLI if you use a server most likely. At its core Linux is  a command line OS and all the graphics are just layers on top of it. This contrasts with Windows where the GUI is an integral part of the operating system.

Working With Text Files

Text files are very important in the Linux/Unix operating system(OS)


cat displays a text file.

$ cat fruit

apples oranges


less also displays a text file but in a different way. It displays  it one page at a time. You type space for the next page. When less reaches the end of file(EOF), It displays END at the bottom of the screen. Type q to exit. Less is used to display man pages.


lpr prints files. By default it prints on the default printer. To print on a specific printer use lpr -P printer file.For more info see the man page.

$ lpr text.print


nano is a simple text editor. The keyboard commands are at the bottom of the ‘window’.(^ means Ctrl ex. ^X means Ctrl-x). Nano opens a new file if no file with that name exists. Else it opens the existing file. (a very popular, but harder to use alternative is vi/vim)

$ nano filetoedit


head displays the first ten lines of a text file. Conversely tail displays the last ten. You can use an option to specify the number of lines.

$ head -2 list

the second line


grep is a very useful utility. Here I will only show the basics. Grep searches text files. The syntax is grep string file. to search only for words(ex grep for file could get therefore) use the -w option.

$ grep 'apple' favoritefruits

Ted's favorite fruit is an apple.



Commands and terminal examples are in monospace. User typed input is in bold.

Getting to the Terminal/GUI

In most Desktop environments: Applications -> Accessories -> terminal. In Unity search for terminal.

You can also use run(alt-f2) and type in gnome-terminal or xterm or something similar.


Many(or maybe most) of these commands are also in Mac OS, but since I have no experience with Macs I do not know the specifics of how it differs.


3 Responses to Command Line Essentials Part 2

  1. Pingback: Command Line Essentials Part 2 « PC and Penguin

  2. Pingback: Command Line Essentials Part 1 « PC and Penguin

  3. Pingback: 40 Must Know Linux Basic Command Line Tips |

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: