UNIX Tutorial for Beginners

The UNIX is an operating system. “It was created by Ken Thompson and Dennis Richie at AT & T’s Bell laboratory in 1969”. The UNIX operating system was firstly programmed in assembly language.

An operating system is a set of programs which is written in such a way that can communicate to the system. It manages computer hardware and software resources as well as provides the common services for a computer program. The UNIX is an operating system, which is the base for all OS such as Ubuntu, POSIX, Solaris, etc.

The UNIX can handle multiple users at the same time. It is a collection of programs which act as the link between the computer and the user. The UNIX systems also have the graphical interface similar to Microsoft windows which provide a secure environment for the user to use.

History

The UNIX project began in the mid of 1960s. In 1969, Ken Thompson wrote the first version of UNIX, which is known as UNICS. The UNICS stands for Uniplexed operating and computing system.

unix-tutorial

Dennis Richie teamed up with ken Thompson, who wrote the first C compiler. In 1973, they again wrote the UNIX kernel in C language. This version of UNIX is known as the fifth edition, and the first licensed version for the universities use. The UNIX operating system is widely used in the world for computer servers.

Features

There are some features of the UNIX operating system which are given below:

  • It supports multitasking and multi-user.
  • The UNIX operating system has a programming interface.
  • UNIX can use the files as an abstraction of the device and other objects.
  • This operating system is Built-in networking (TCP/IP standard).
  • The Persistent system service processes called “daemons” and managed by inet or init
  • The UNIX operating systems use the centralized OS kernel, which can control the system and process activities.
  • We can communicate with our system through the UNIX shell, which translates to the kernel.
  • All functions in the UNIX operating system is related to the file or process. The processes are the execution of programs, while files are the collection of data created by the user.

1. Basic Commands

The UNIX commands are the inbuilt programs that can be invoked in various ways. We can work with these commands interactively from the UNIX terminal. The UNIX terminal is a graphical program. It provides a command-line interface by using the shell program.

Various testing activities, like installation and performance testing, depends on the operating system knowledge. Most of the web servers are based on the UNIX operating system. So, the knowledge of UNIX is mandatory for the testers.

There are different types of basic commands of the UNIX operating system, which are given below:

  • cal command

The “cal” command is used to print the calendar of the current month or the whole year. It is the command-line utility to display the calendar in the terminal.

Syntax:

 $ cal [ [ month ] year]

Examples:

1. Cal 2018: It will show the whole calendar of the year 2018.

unix-tutorial-1

2. Cal 08 2000: It will show the calendar of 8th month, the year 2000.

unix-tutorial-2
  • B. date command

The “date” command in UNIX is used to display the system’s date and time. It shows the date in the time zone on which Unix/Linux operating system is configured. We can also set the date and time of our system using this command.

Syntax:

 date [OPTION]… [+FORMAT]
date [-u|- - utc|- - universal] [MMDDhhmm[[CC]YY].ss]] 

Examples:

1. Command: This command is used for the pacific daylight time.

$date

Output:

Tue Oct 10 22:55:01 PDT 2017

2. Command: The command for the date and time of 2 years ago.

$date - - date= “ 2 year ago”

Output:

Sat Oct 10 23:42:15 PDT 2015
  • banner command

The banner command of UNIX operating system is used to print the text in large size on standard output. It prints the high-resolution text banner on the system console. If we have the printer connected to the machine, we can redirect the output to the printer.

Syntax:

banner text

Example:

Print "1234567890" in large letters.
unix-tutorial-3
  • who command

This command is used to show the list of users who are currently logged into the system. The who command of UNIX is related to the w command, that provides the same information but also displays the additional data and statistics. The who command shows the information if the various options are not provided:

  1. The login name of users.
  2. Terminal line numbers in UNIX.
  3. The login time of the users when they logged into the system.
  4. The remote hostname of the user.

Syntax:

$who [OPTION]... [FILE name | ARG1 ARG2]

Examples:

1. The given command who-m-H is used to display the hostname and user associated with the standard input such as the keyboard. 

hduser@ramesh-Inspiron- 3543:~$who-m-H
NAME LINE TIME COMMENT 

2. The given command who-p-H is used to show all active processes which are spawned by the INIT process.

hduser@ramesh-Inspiron-3543:~$who-p-H
NAME LINE TIME PID COMMENT 

3. The below syntax of who command will display the list of users logged into the system

hduser@ramesh-Inspiron- 3543:~$who-u
hduser tty7 2018-03-18 19:08 01:16 3357 (:0) 

4. In the below example, the who-b-H command will show the time of the system when it booted last time.

hduser@ramesh-Inspiron-3543:~$who-b-H
NAME LINE TIME PID COMMENT
System boot 2018-03-18 19:07 

5. The who –d -H command is used to display the details of all dead processes.

hduser@ramesh-Inspiron-3543:~$who –d –H (No dead process in this case)
NAME LINE TIME IDLE PID COMMENT EXIT
NAME LINE TIME IDLE PID COMMENT EXIT 

6. To display the system login details, who –l –H command is used, as it is given in the below example. 

hduser@ramesh-Inspiron-3543:~$who -l -H
NAME LINE TIME IDLE PID COMMENT
LOGIN tty1 2018-03-18 19:07 3073 id=tty1 

7. Count the number of users logged on to the system, when who –q -H command is used.

hduser@ramesh-Inspiron- 3543:~$ who –q –H
hduser
#users=1 

8. To show the current run level of the system, who –r command is used.

hduser@ramesh-Inspiron – 3543:~ $who –r
run- level 5 2018-03-18 19:07 

9. The given command who-a is used to show all details of the users who currently logged in.

hduser@ramesh-Inspiron-3543:~$who –a
System boot 2018-03-18 19:07
LOGIN tty1 2018-03-18 19:07 3073 id=tty1
run – level 5 2018-03-18 19:07
hduser +tty7 2018-03-18 19:07 3357(:0) 
  • Whoami command

The whoami command is used in UNIX and LINUX as well as Windows operating system. It concatenates the strings "who," "am," "i" as whoami. The given whoami command is used to display the current user when this command is invoked by the system. It is similar to running of id command with the option –un.

Syntax:

Ramesh@HP~: whoami

Output:

Ramesh

2. The file system commands

The UNIX file system is the methodology to organize and store the large quantity of data in such a way that it makes the operating system easy to manage. The file is defined as a collection of data, which can logically view. It is the smallest unit of storage data in the UNIX file system.

The UNIX operating system has the hierarchical and structural file system with its highest-level directory called root. The root-level directories are containing different subdirectories.

The file system of UNIX consists of files, relationships to other files, as well as the attribute of each file. File attribute is the information related to the file but does not include the data contained within the file. This file attributes to the generic operating system include the information which is given below:

  1. The file type (what kind of data is in the file).
  2. Filename (which may or may not include the extension).
  3. The physical file size.
  4. The owner of the file.
  5. File protection/privacy capability.
  6. The file timestamp.

 The file system provides a tool which allows the manipulation of a file and provides the logical organization as well as services, which maps the logical organization of file to the physical devices. There are various types of file system commands which are given below:

A) touch command

The touch command is used in both LINUX and UNIX operating system. It is creating change and modifies the timestamps of the file. It can create the file without any content. So, that file is empty, which is created by the user via touch command. This command can be used when the user doesn’t have data to store at the time of file creation.

Syntax:

It is the common syntax for touch command.

touch file_name

The touch command is used to create multiple numbers of the file at the same time. These files would be empty during creation.

 Example:

unix-tutorial-4

Syntax:

The given syntax is used to create many files at the same time.

touch file1_name file2_name file3_name
unix-tutorial-5

B) cp command

The cp stands for copy, and this command is used to copy files or group of files or directory. The cp command creates an image of the data on the disk with the different file name. It requires at least two file names in its arguments.

Syntax:

cp [option] Source Destination
cp [option] Source Directory
cp [option] Source-1 Source-2 Source-3 Source-n Directory 

The first and second syntax is used to copy source file to Destination File or Directory, and the third syntax is used to copy multiple sources (files) to the directory. 

Example:

$ ls
a.txt
$cp a.txt b.txt
$ ls
a.txt b.txt 

The above example contains two file names, and then it copies the contents of the 1st file to the 2nd file. If the second file doesn't exist, then firstly the cp command creates a file, and the content is copied to it. But if that file already exists then, it is overwritten without any warning. So, we need to be careful when we choose the destination file name.

C) Mv command

The mv command is a command-line utility that moves files or directory from one place to another. It supports moving the single files, multiple files, and directories. The mv command has two distinct functions:

1. It renames the file or folder.

2. This command can move the group files to a different directory. 

No additional space is consumed on the disk during the renaming. The mv command normally works silently means no prompt for the confirmation of the command.

Syntax:

Mv [option] Source destination

Example:

$ ls
a.txt b.txt c.txt d.txt
$ mv a.txt ramesh.txt
$ ls
b.txt c.txt d.txt ramesh.txt 

D) rm command

The rm command is the basic command of UNIX and LINUX operating system. It is used to remove the objects such as computer files directories and symbolic links from file systems.

This command removes the references to the object from the file system, where those objects might have multiple references. It does not remove the directories by default.

The rm command normally works silently, and we should be very careful while running the rm command. Once the files are deleted, then we are not able to recover the contents of the files and directories. 

Syntax:

rm [option]….. FILE….

Example:

 The given example is used to Removing one file at a time.

$ rm a.txt
$ ls
b.txt c.txt d.txt e.txt 

 This syntax is used to Removing more than one file at a time

$ rm b.txt c.txt
$ ls
d. txt e.txt 

E) mkdir command

The mkdir command is used to create directories or folders. It can create multiple directories at once and set permissions when it makes the directory.

It is important to note that when the user executes mkdir command, the user must have enough permission to create the directory in the parent directory. Otherwise, the user may receive the error ‘permission denied'. 

Syntax:

Mkdir [options……] [directories…..]

Examples:

1. - - version: The given example shows the version number and some information regarding the license.

Syntax:

Mkdir - -version.

Output:

unix-tutorial-6

2. - - help: It shows the help related information and exits.

Syntax:

Mkdir - - help

Output:

unix-tutorial-7

3. –v or - -verbose: It is used to display the message for every directory.

Syntax:

Mkdir -v [directories]

Output:

unix-tutorial-8

3. The processes control commands

The process control command is a single running program. It may be the system program or program initiated by the user. It gives the unique number to each process when the UNIX operating system runs the process. The process is the sequence of instructions, and every process has a block of controlled data to associate with it.

 The process table contains information about all processes which are currently running in the operating system. The primary purpose of this table is to manage the running processes effectively. The different type of information exists in the process table, which is given below:

  • The process ID of any process.
  • The parent process ID should present in the process table.
  • State of the processes is related to the process table.
  • Usage of the central processing unit exists in the process table in the UNIX operating system.

The different state of the process in the UNIX operating system depends on the various circumstances. It may trigger the state of the process and needs to wait for the read or write operation to complete. Several commands are available to review and manipulate the process.

A) Ps command

The ps command is used to display the currently running process. The UNIX is the multitasking and multi-user operating system, so ps command allows multiple methods to operate simultaneously without interfering with each other. The processes are the executing instance of the program and carry out the various tasks within the operating system.

Syntax:

ps [options]

Examples:

1. View process

 The given ps-A and ps-e command is used to view all the running processes.

[root@rhe17~]#ps -A
[root@rhe17~]#ps -e 

2. The given below example is used to view all the process except session leaders.

[root@rhe17~]#ps -d

B) top command

The top command is used to display system summary information as well as the list of processors or threads which are currently managed by the kernel. This command provides the dynamic real-time view of the running system.

Syntax:

top [options]

Examples:

1. Batch mode: This syntax of the top command is used to send the output to file or any other program with the help of batch mode.

top-b

2. Secure mode: The given top-s command is used in a secure mode.

top-s

C) bg command

The bg command is used to job control. It is the ability to stop or suspend the execution of processes and continue their execution as per our requirements. The bg command is used to locate the foreground job in the background.

Syntax:

bg [job_ spec….]

Example:

bg - -help: Given bg- -help command is used to display the help information.

unix-tutorial-9

D) fg command

The fg command in UNIX operating system is used to position the background job in the foreground.

Syntax:

fg [job_spec] 

Example:

fg - - help: The fg - - help command is used to show the help information.

unix-tutorial-10

E) clear command

The clear command is mainly used to clear the terminal screen. This command will ignore every command-line parameter if present. It doesn’t take any argument and similar to cls command.

Syntax:

$clear

Example:

The terminal looks like that before executing the clear command.

unix-tutorial-11

After the execution of the clear command, the terminal is looking like this.

unix-tutorial-12

F) history command

The history command is used to view the previously executed command. This command is used in every version of the UNIX operating system. It is mainly used to view history.

Syntax:

$history

Examples:

1. To display the limited number of commands in history, we can use syntax like this

$ history 5
unix-tutorial-13

4. The Utilities program commands

The UNIX is divided into two parts the kernel and the utilities program command. A kernel is the heart of the UNIX system. It resides in the computer's memory from the time when the computer is turned on and booted until it is shut down.

The utilities program commands are resided on the computer’s disk and brought into the memory according to user’s request. Every command of UNIX is classified as the utility.

A) man command

The man command of UNIX is used to display the user manual of any command that can run on the terminal. It provides a detailed view of command, which include:

NAME, SYNOPSIS, DESCRIPTION, OPTION, EXIT STATUS, RETURN VALUES, ERRORS, FILES, VERSIONS, EXAMPLES, AND AUTHORS. Each manual page is divided into some sections which are given below:

  1. The Executable Programs or shell commands in the terminal.
  2. System calls, these are the functions provided by the kernel.
  3. The Library calls which are the functions within the program libraries.
  4. Every manual page is divided into the game section.
  5. The System administration commands.
  6. The routines of the kernel.
  7. The file formats and conventions

 Syntax:

$man[OPTION]…….. [COMMAND NAME]…….

 Example:

1. No option: The given syntax of man command shows the whole manual of the command.

Syntax:

$ man [COMMAND NAME]
$man printf 

Output:

unix-tutorial-14

In this output, the Printf command is executed and returns manual pages as the output.

B. sudo command

The sudo command stands for "superuser do." It allows the user to run programs with the security privileges of another user. This command also supports the security privileges from the superuser by default.

Syntax:

Sudo –V/ -l / -v / -K / -k / -s / [-H] [-P] [-S] [-b] /
[- p prompt ] [-c class /-] [-a auth_type ] [- r role ] [-t type ]
[- u username / # uid ] commandsudo –V / -h / -l / -L / -v /-k/ -K/ -s/ [-H] [-p] [-S] [-b]
/
[-p prompt] [-c class / -] [-a auth_type] [-r role ] [-t type]
[-u username / # uid ] command 

Example:

1.-V: The sudo command given below is used to print the version number and exit from the terminal.

unix-tutorial-15

C. find command

The find command is used to search one or more directory trees of the file system. This command performs subsequent operations on files and directories. It supports the searching by file, folder, name, creation date, modification date, owner, and permissions.

Syntax:

$ find [where to start searching from]
[ expression determines what to find] [-options] [what to find] 

Example:

 The given syntax is used to Search the file with its specific name.

Syntax:

$ find. / GFG – name sample.txt

Output:

unix-tutorial-16

UnixInstallation

1. Go to www.virtualbox.org and click on download virtual box.

unix-tutorial-17

2. Select the windows hosts on this page.

unix-tutorial-18

3. Click the button, power on the virtual machine.

unix-tutorial-19

4. Select the option Install or upgrade an existing system.

unix-tutorial-20

5. The given page shows requested files of the UNIX operating system are loaded in a virtual machine.

unix-tutorial-21

6. Select a Skip or OK button according to the user’s requirement.

unix-tutorial-22

7. Click on the Next button.

unix-tutorial-23

8. Select the language according to the user's need.

unix-tutorial-24

9. After selecting the language, click next option.

unix-tutorial-25

10. Select the Basic Storage Device Button.

unix-tutorial-26

11. It is the Warning page for the storage device; here we select the yes button. So, we got the space in the storage device.

unix-tutorial-27

12. Then, we need to set the Hostname.

unix-tutorial-28

13. Select the time zone according to the user's choice.

unix-tutorial-29

14. Set the root password on this page.

unix-tutorial-30

15. Select the Create Custom Layout option.

unix-tutorial-31

16. Create the standard partition of the virtual machine.

unix-tutorial-32

17. Similarly, create two more partitions of the virtual machine.

unix-tutorial-33

18. Select the format button.

unix-tutorial-34

19. Then, click on the button, write changes to disk.

unix-tutorial-35

20. After click on the create button, the formatting of the disk gets started.

unix-tutorial-36

21. Install the boot loader.

unix-tutorial-37

22. Installing process of UNIX is started after the process completion, clicks the next button.

unix-tutorial-38

23. Select the primary server option and click on customize now button.

unix-tutorial-39

24. Check the dependency of the server.

unix-tutorial-40

25. End

Advantage

The UNIX operating system has various advantages which are given below:

  • The main advantage of UNIX is multitasking with the protected memory.
  • Multiple users can run multiple programs at the same time without interfering with each other and crashing the system.
  • The UNIX operating system is available on a wide variety of machines.
  • It is an optimized operating system for program development.
  • This operating system is the lean kernel which does the basic task but doesn’t get in the way when we try to do the unusual.
  • The UNIX OS is very efficient virtual memory; so that many programs can run with the modest amount of physical memory.
  • The UNIX has a rich set of small commands and utilities that can do the specific task well. These commands cannot create clusters. This operating system has stocked toolbox.
  • The UNIX operating system has strong access control and security. All users must be authenticated by the valid account and password to use the system. A particular account owns the whole files, and the owner can decide that others have read or write access to his data.
  • The UNIX has a powerful unified file system, and everything is stored in this operating system such as data, programs, and physical devices.

Disadvantage

There are several disadvantages to this operating system which are given below:

  • The traditional command-line shell interface in the UNIX operating system is user-hostile. It is only designed for the programmer, not for the casual user.
  • To use the UNIX operating system completely, we need to understand some of the main design features. We should know how to make commands and programs which can interact with each other.
  • The UNIX is designed in the text-based command line, so it is not easy to use. This Operating System is for normal users,
  • The modern version of UNIX has graphical interfaces except for macOS.

Conclusion

The UNIX operating system is used in workstations and servers. UNIX environment and client-server program are very important for the development of internet and remapping of the computer system as keeping the keyframe of networking.

It is portable and time-sharing configuration operating system. There are several layers of interaction in UNIX. These layers occur in between the computer hardware and the user.