First Step in Command Line

First Step in Command Line

Some Familiar Terms

A Shell is a computer interface to an operating system which expose the OS's services to the human user or other programs.

The shell takes our command and gives them to the operating system to perform.

It's named a "shell" because it is the outer layer around the OS, like the shell around an oyster.

A Terminal is a program that runs a shell. Originally, terminals were physical devices but these days, we work with software terminals.

On most Linux based systems, the default shell program is Bash. There are many other shells but Bash is currently the most popular.

The name "Bash" is an acronym for "Bourne Again SHell", a reference to Stephen Bourne, the creator of Bash's direct ancestor shell, sh.

Bash runs on pretty much all Unix and Unix-like systems.

The Prompt

When we open up our terminal, we'll see our prompt which will likely include your username@machinename, followed by a ~ symbol and a dollar sign $.

The prompt is what we'll see whenever the shell is ready to accept new input.

All we need to do is type some commands and then hit enter.

if we try typing some gibberish, the shell attempts to find a command with that name before telling us "command not found".


Our very first commands

Let's begin with the most basic and easy command, the date command.

It may not be the most useful command of all time, but it is a great place to start.

Try typing date in your terminal and then hit enter. You should see the current date printed out.


Case Matters

Commands are case sensitive, so Date is not the same thing as date.

- If you're using OS X, some commands are not case sensitive but others are. So it is safe to assume that all commands are case sensitive.


ncal Command

Try typing ncal in your prompt and hit enter. You should see the current month's calendar printed out.

ncal stands for "new cal". There is also a "cal" command that does the exact same thing but ncal adds some fancier functionality.

If the ncal command is not available in your Linux terminal, you can install it with this command,

sudo apt install ncal        


The Arrow Keys

In the terminal, we can use the left and right arrow keys to move through a line of text, one character at a time.

The up arrow key can be used to access the previously entered commands, saving you tons of typing.

Command Structure

Most commands support multiple options that modify their behavior. We can decide which options to include, if any, when we execute a command.

Similarly, many commands accept arguments (the things that the command acts upon or uses).

command -options arguments        

Arguments

The terms "argument" and "parameter" are often used interchangeably to refer to values we provide to commands.

The echo command is extremely simple example. It takes the arguments we provide to it and and prints them out. It echoes them back at us.


Arguments in ncal

Similarly, the ncal command accepts values to control the specific month(s) and year it displays.

If we specify only an year, ncal will print out the calendar for that entire year.

If we specify a month and an year, ncal will print only that specific month's calendar.


Options

Each command typically supports a host of options that we can choose to use when executing a command. These options modify the behavior of the command in predefined ways.

Options are prefixed by a dash, as in -h or -3.

command -option        

Example

By default, the ncal command highlights today's date in the output. We can provide the -h option to turn off the highlighting of today's date.


More options

The -j option tells ncal to display a calendar using Julian days (days are numbered starting from Jan 1st).

We can provide the -M option to tell ncal to use Monday as the first day of the week instead of Sunday.


The -3 option tells ncal to display the previous, current and next month.


Combining Options

We can provide multiple options at once. This example uses the -3 option to display the previous, current and next month AND the -h option to turn off the highlighting of the current date.


Another syntax

When we provide multiple options to a single command, we can use a shorter syntax where we only need a single dash (-) character.


Long Form Options

All these short one-character options can get confusing! Some options also support equivalent long format options that are usually full words and are prefixed with two dashes instead of just one.

For example, the date -u option is used to print the date in Coordinated Universal Time (UTC). We can instead use date --universal to accomplish the same end result.


Options with Parameters

Some options require us to pass in an additional value. For example, ncals's -A option is used to display a certain number of months AFTER a specific date. We need to tell it how many months to display.

In this example, ncal -A 1 prints out the current month with one month afterwards.

Note: this can also be written as ncal -A1 (no space between A and 1).


There is also a -B option to print a number of months BEFORE the specific date. We need to pass it a number of months.

In this example, ncal -B2 prints out the current month with two previous months.


This example prints out the calendar for July 1969, with one month before (June) and two months later (August and September).



要查看或添加评论,请登录

Shivm Soaini的更多文章

  • Pipelines

    Pipelines

    Pipes are used to redirect a stream from one program to another program. We can take the output of one command and…

  • The Standard Streams and Redirection

    The Standard Streams and Redirection

    The three standard streams are communication channels between a computer program and its environment. They are:…

  • Working with Files

    Working with Files

    The cat command The cat command concatenates and prints the contents of files. cat filename will read the contents of…

  • The Shortcuts

    The Shortcuts

    We can speed up our command-line experience by taking advantage of the many built-in shortcuts. These shortcuts are…

  • Deleting, Moving and Copying

    Deleting, Moving and Copying

    The rm command We use the rm (remove) command to remove files from our machine. For example, rm app.

  • The Nano Text editor

    The Nano Text editor

    Nano is a simple text editor that we can access right from the terminal. It's far more accessible than other popular…

  • Making Files and Folders

    Making Files and Folders

    The touch command To create a new file from the command line, use the touch command. Provide a filename, and that file…

  • Navigating the CLI Sea

    Navigating the CLI Sea

    The root directory The starting point for the file system is the root folder. We call it the root, but its actual…

  • Getting Help in Command Line Interface

    Getting Help in Command Line Interface

    Sometimes it's difficult to wrap our head around some of the commands we encounter. In this scenario, man pages can…

  • A Brief History of Linux

    A Brief History of Linux

    The world of operating systems has many residents, but they can be segregated into two tribes: The Microsoft NT…

社区洞察

其他会员也浏览了