Basic commands

Unix Shell Mastery - Part: 2

Learn about date, who and echo


Getting started

Get started by opening your terminal app. Whenever you see a $ this is the start of a command that we will be entering into the terminal, You do not need to enter the $ into the terminal. If you see a line that does not start with $ it is an example response to the command entered. Every unix command is executed by pressing the enter key.

Display the date and time

date

The date command tells the system to print (output) the date and time.

$ date
  Thu 27 Sep 2018 23:07:44 AEST

date prints:

  1. The day of the week
  2. The day of the month
  3. The month
  4. The year
  5. The time in 24 hour format
  6. The timezone of the system

Display which users are logged in

who

The who command displays information about all the users currently logged into the system.

$ who
  george       ttys002  Sep 16 13:22
  josh         ttys000  Sep 16 13:23
  holly        ttys001  Sep 16 13:23

In this example we can see three users are logged in. george, josh and holly. Along with each user we also get :

  1. The tty number
  2. The time and date the user logged

The tty number is a unique identification number each user is given by the Unix system.

The who command can also be used to get information about yourself:

$ who am i
  george       ttys002  Sep 16 13:22

who am i and who are actually just one command - who. When we use who am i we are just giving the who command extra information. These extra pieces of information are called arguments. am is one argument i is another.

Displaying words

echo

The echo command prints anything you type on the same line.

$ echo follow the white rabbit
  follow the white rabbit

$ echo blank        spaces are   ignored       in   Unix
  blank spaces are ignored in Unix

In the second example you will see the additional spaces are removed. This is typical of the Unix system. The words are important the space between them are only required to show that they are separate.