1 Overview

Overview

Objective

  • Introduce the *nix family of operating systems.
  • Install an operating system on a on a virtual machine.
  • Get familiar with command line syntax.
  • Get familiar with file system structure.
  • Differentiate between absolute and relative paths.

cd dnf echo ls man passwd pwd reboot shutdown sudo su useradd userdel which whoami

What is Unix?

  • Unix is a powerful multi-user, multitasking computer operating system (OS).
  • Is designed to serve many users at the same time.
  • Can operate as a member of a network, or stand alone.
  • Assumes that you know what you are doing, and that you are responsible.
  • Is popular among academic, government, engineering and scientific communities due to its:
    • Stability
    • Portability
    • Flexibility and adaptability
    • Built-in networking capabilities
    • Programming and text processing tools
    • Rich set of built-in commands and utilities
    • Raw speed

Anatomy of a Unix System

A Unix system is composed of multiple layers:

HardwareKernelShellUtilitiesCompilersDatabasesEditorsBrowsersPlayersDebuggersSheetsImages

Kernel

  • Core of the operating system (OS)
  • Built natively at install time to optimally interact with that particular system’s components and features
  • It manages
    • all interactions with hardware
    • all I/O requests
    • process creation, memory allocation, and CPU scheduling
    • files and the file system
    • security

Shell

  • Command-line interface/interpreter
  • Interface between user and OS
  • Accepts input from the user and performs the appropriate actions
  • Common shells:
    • Bourne Shell (sh)
    • C Shell
    • Korn Shell (ksh): a superset of the Bourne shell and is more user friendly.
    • POSIX Shell
    • Bourne Again Shell (bash)

For more information, refer to this article (opens in a new tab) which provides a comparison of computer shells.

Utilities

  • Programs that perform system tasks such as file management (ls, cp, …), editing and compiling.
  • Approximately 300 built-in utilities distributed as part of Unix.

Command Line Syntax

Syntax

All commands are entered in the same format:

command [-option] [argument]
  • command
    • Name of utility or tool
    • Usually in lower case
  • option
    • Usually preceded by a dash (-)
    • Often many options may be specified in one string
  • argument
    • objects of a command
    • Usually filenames or keywords
  • All are white-space separated.
  • Depending on the command, option and argument may not be required.

Example

> passwd
> ls -lF filea fileb
> ls -l -F filea fileb

Unix commands are case sensitive; therefore most commands must be entered in lower case.

Opening a Terminal Window

To open a Terminal window, press the Super key then search for Terminal and click the icon of the application to launch it. This allows you to enter command lines. This window is similar to the window that you get in a Windows environment by running cmd.exe.

Using the Manual Pages

  • Unix comes with an electronic manual set: Unix Programmer’s Manual. To get help about any command type: man command. To get help on how to use the man command itself type man man.

  • Sections of the Manual: The man pages contain sections on many topics such as commands, system calls, subroutine library, file formats, miscellany, games, special files, and system administration.

  • man can also be used to find command names using the -k option

    • Syntax: man -k keyword
    • Example: man -k editor

Managing System Users

To create/delete a user accounts, go to SettingsUsers. You should first unlock the Users dialog located on the far right top bar which requires your authentication password.

Creating a new user with a password from the command line:

> sudo useradd -m newuser
> sudo passwd newuser
New password: ••••••
Retype new password: ••••••
passwd: password updated successfully
> sudo su - newuser
> pwd
/home/newuser
> whoami
newuser
> exit

Login

Unix supports many users; each user is usually assigned their own account. An account is made up of a user id, a username, a password, and a home directory. After logging in, you can start a terminal window and switch to the super user by typing sudo command and then providing the password for your account.

> sudo su - root
[sudo] password for tux: ••••••
#

Logout

From the top bar and on the far right, the logged user name is identified. You have many options from which you can logout, suspend or shutdown the system.

> sudo shutdown -P +5
[sudo] password for tux: ••••••
Shutdown scheduled for Mon 2024-01-15 11:00:12 +03, use 'shutdown -c' to cancel.

File System Concepts

  • Unix uses a hierarchical file structure to organize files and directories.
  • Each file and directory can be explicitly defined by its pathname in the hierarchy.
          • passwd
            • practice
              • practice
                  • Listing Files

                    • Use the ls command: ls [-option] [file or directory name].
                    • Used to list the contents of a directory.

                    Example

                    > ls /etc
                    abrt                        grub2.cfg                 prelink.conf.d
                    adjtime                     grub.d                    printcap
                    aliases                     gshadow                   profile
                    aliases.db                  gshadow~                  profile.d
                    ...
                    • ls accepts options which can change the way the files are listed, including:

                      OptionAction
                      -alist all files, including system files
                      -Fshow file type: * after executables, / after directories, nothing after plain files
                      -lshow extended file information
                      -rlist files in reverse order

                    Absolute Pathnames

                    • Unix uses a hierarchical or tree-like file structure.
                    • The top level of directory structure is called root (/).
                    • Every file can be unambiguously referenced by its absolute pathname.
                    • Start with the root directory and trace a route through each intermediate directory to the target file/directory.
                    • Each level is separated by a /, for example:
                      • /
                      • /bin
                      • /etc/passwd
                      • /home/tux/practice
                      • /var/spool/mail

                    Relative Pathnames

                    • File and directory names may be specified in relation to the current location using a relative path.
                    • Relative pathnames start with:
                      • a file or directory name
                      • .
                      • ..
                      • ~
                          • > pwd
                            /home/user1
                            > ls ..
                            user1  user2
                            > cd ..
                            > pwd
                            /home
                            > ls .
                            user1  user2
                            > cd ~user2
                            > pwd
                            /home/user2
                            > cd ../..
                            > pwd
                            /
                            > ls home
                            user1  user2
                            > cd /usr/bin
                            > pwd
                            /usr/bin
                            > cd ../../home/user1
                            > pwd
                            /home/user1

                            Current Directory

                            • Also called working directory.
                            • Use pwd (print working directory) to display it.
                            • Referenced as . in pathnames.

                            Example

                            > pwd
                            /home/user1
                            > ls
                            code  file  practice
                            > ls .
                            code  file  practice

                            Home Directory

                            • Assigned to each user from personal and initialization files.
                            • Initial location at login.
                            • Referenced as:
                              • $HOME (all shells)
                              • ~ (most shells)
                              • ~username (most shells)

                            Changing Directories

                            • Use the cd command to change directories: cd [directory name]
                            • Stands for change directory.
                            • Used to move from one location in the directory tree to another.
                            • If no directory name is specified, then cd takes you to your home directory.

                            Example

                                • > pwd
                                  /home/user1
                                  > cd memos
                                  > ls
                                  > pwd
                                  /home/user1/memos
                                  > cd ..
                                  > pwd
                                  /home/user1
                                  > cd ../../usr
                                  > pwd
                                  /usr
                                  > cd ~/memos
                                  > pwd
                                  /home/user1/memos
                                  > cd ~user2/memos
                                  > pwd
                                  /home/user2/memos
                                  > cd
                                  > pwd
                                  /home/user1

                                  Exercise 1

                                  Issue the following commands to navigate through some common Unix directory structures. After each command, use the pwd command to identify your current location in the file structure.

                                  Use the following tree diagram to help you navigate the hierarchy:

                                                        • > cd
                                                          > pwd
                                                          > cd /usr/bin
                                                          > pwd
                                                          > ls
                                                          > cd /tmp
                                                          > pwd
                                                          > cd
                                                          > pwd
                                                          > cd ..
                                                          > pwd
                                                          > cd .
                                                          > pwd
                                                          > cd
                                                          > cd ../..
                                                          > pwd
                                                          > cd ../etc
                                                          > pwd
                                                          > cd /usr/bin
                                                          > pwd
                                                          > cd ../lib
                                                          > cd ~
                                                          > pwd

                                                          Resources