Unix User Interfaces

A user interface, or UI, refers to the software that allows a person to interact with the computer. The UI provides the look and feel of the system, and determines how easily and efficiently it can be used. ( Note that ease of use and efficiency are not the same! )

The term "MS Windows" refers to a specific proprietary operating system, and implies all of the features of that system including the API and the UI. When people think of Windows, they think of the Start menu, the Control Panel, etc. Likewise, "Macintosh" refers to a specific product and invokes images of the "Dock" and a menu bar at the top of the screen rather than attached to a window.

The term "Unix", on the other hand, implies an API, but does not imply a specific UI. There are many UIs available for Unix systems. In fact, a computer running Unix can have multiple UIs installed, and each user can choose the one they want when the log in.

Graphical User Interfaces (GUIs)

A Graphical User Interface, or GUI (pronounced goo-ee), is a user interface with a graphical screen, and icons and menus we can select using a mouse or a touch screen.

There are many different GUIs available for Unix. Some of the more popular ones include KDE, Gnome, XFCE, LXDE, OpenBox, CDE, and Java Desktop.

Gnome desktop
A FreeBSD system running Gnome desktop.
KDE desktop
A FreeBSD system running KDE desktop.
Lumina desktop
A FreeBSD system running Lumina desktop.
XFCE desktop
A FreeBSD system running XFCE desktop.

Example 3.1. Practice Break

If you have access to a Unix GUI, log into your Unix system via the GUI interface now.


All Unix GUIs are built on top of the X11 networked graphics API. As a result, all Unix systems have the inherent ability to display graphics on other Unix systems over a network. I.e., you can remotely log into another Unix computer over a network and run graphical programs that display output wherever you're sitting.

This is not the same as a remote desktop system, which mirrors the console display on a remote system. Unix systems allow multiple users in different locations to run graphical programs independent of each other. In other words, Unix supports multiple independent graphical displays on remote computers.

It is also not the same as a terminal server, which opens an entire desktop environment on a remote display.

With Unix and X11, we can have individual applications running on multiple remote computers displayed on the same desktop. Doing so is easy and requires no additional software to be installed.

Most Unix GUIs support multiple virtual desktops, also known as workspaces. Virtual desktops allow a single monitor to support multiple separate desktop images. It's like having multiple monitors without the expense and clutter. The user can switch between virtual desktops by clicking on a panel of thumbnail images, or in some cases by simply moving the mouse over the edge of the screen.

X11 on macOS

macOS is Unix compatible, derived largely from FreeBSD and the Mach kernel project, with components from GNU and other Unix-based projects.

It differs from more traditional Unix systems like BSD and Linux, though, in that it runs Apple's proprietary graphical API and GUI. Native OS X programs don't use the X11 API, but OS X can also run X11-based programs with the XQuartz add-on. See the section called “Remote Graphics” for instructions on enabling X11 for Mac.

Command Line Interfaces (CLIs): Unix Shells

There are two basic types of user interfaces:

  • Menu-driven, where choices are displayed on the screen and the user selects one.
  • Command-driven, where the user types commands that they have memorized.

A GUI is a type of menu-driven interface, where the menu items may be text or graphical icons. Some menu systems are simply text selected by entering a number on the keyboard.

               ___         __           ___       __          _     
              /   | __  __/ /_____     /   | ____/ /___ ___  (_)___ 
             / /| |/ / / / __/ __ \   / /| |/ __  / __ `__ \/ / __ \
            / ___ / /_/ / /_/ /_/ /  / ___ / /_/ / / / / / / / / / /
           /_/  |_\__,_/\__/\____/  /_/  |_\__,_/_/ /_/ /_/_/_/ /_/ 
           _________________________________________________________
                  
                  Portable Command-line Systems Management
                      https://acadix.biz/auto-admin.php
           _________________________________________________________

This menu system encompasses only a small fraction of the total auto-admin
functionality.  To see what else is available via the command-line, choose
"List available auto-admin scripts" below.

Full documentation is in the works and will be included in a future release.

1.. Update system
2.. User management
3.. Software management
4.. Network management
5.. Power management
6.. File system actions and settings
7.. Security settings
8.. System settings
9.. Services manager
10.. List available auto-admin scripts
Q.. Quit

Selection? 
            

While all modern Unix systems have GUIs, much Unix work is still done via the command line interface (CLI). A CLI requires the user to type in commands, rather than select them from a menu, much like short-answer questions vs multiple choice.

Menu-driven systems are easier to use if the system has limited functionality and you're new to the system or use it infrequently. However, menus are cumbersome where there is too much functionality to offer in a simple menu. Even simple menu systems can become cumbersome for everyday use.

If a user needs access to dozens or hundreds of features, they cannot all be displayed on the screen at the same time. Hence, it will be necessary to navigate through multiple levels of menus or screens to find the functionality you need. Doing this repeatedly becomes annoying rather quickly. A command line interface, on the other hand, provides instant access to an unlimited number of commands.

An ATM (automatic teller machine) is a good candidate for a menu interface. It has only a few functions and people don't use it every day. An ATM with a command-driven interface would likely be unpopular among banking customers.

You might be surprised to learn that CAD (Computer Aided Design) systems have CLIs. While CAD is inherently graphical in nature, CAD users cannot efficiently access their vast functionality through menus. Most CAD users quickly learn to use the CLI to draw, move, and edit objects via keyboard commands.

Because menu systems slow us down, most support hot keys, special key combinations that can be used to access certain features without navigating the menus. Hot keys are often shown in menus alongside the features they activate. For example, Command+q can be used on macOS and Ctrl+q on Windows and most Unix GUIs to terminate many graphical applications, as shown in Figure 3.1, “Hot Keys”.

Figure 3.1. Hot Keys

Hot Keys

It is also difficult to automate tasks in a menu-driven system. Some systems have this capability, but most do not, and the method of automating is different for each system. Command-driven interfaces are easy to automate by placing commands in a script, a simple text file containing a sequence of commands that might otherwise be run directly via the keyboard. Scripting is covered in Chapter 4, Unix Shell Scripting.

Perhaps the most important drawback of menu-driven systems is non-existence. Programming a menu system, and especially a GUI, requires a lot of grunt-work and testing. As a result, the vast majority of open source software does not and never will have a GUI interface. Open source developers generally don't have the time or programming skills to build and maintain a comprehensive GUI interface.

Caution

If you lack command-line skills, you will be limited to using a small fraction of available open source software.

In the tight competition for research grants, those who can use the command-line more often win.

The small investment in learning a command line interface can have a huge payoff, and yet many people try to avoid it. The result is usually an enormous amount of wasted effort dealing with limited and poorly designed custom user interfaces before eventually realizing that things would have been much easier had they learned to use the command line in the first place. It's amazing how much effort people put into avoiding effort...

A shell is a program that provides the command line interface. It inputs commands from the user, interprets them, and executes them. ( By "execute", we mean "run", not what happened to Socrates. ) Using a shell, you type a command, press enter, and the command is immediately executed.

The word "shell" comes from the view of Unix as three layers of software wrapped around the hardware:

Unix layers
A 3-layer Model of Unix
  • The innermost layer, which handles all hardware interaction for Unix programs, is called the kernel, named after the core of a seed. The Unix kernel effectively hides the hardware from user programs and provides a standard API. This is what allows Unix programs to run on different kinds of hardware without modification. Application programs never "see" the hardware interface. They only see the kernel interface, which is the same regardless of hardware.
  • The middle layer, the libraries, provide a wealth of standard functionality for Unix programmers to utilize. The libraries are like a huge box of Legos that can be used to build all kinds of sophisticated programs. They include basic input/output functions, math functions, character string functions, graphics functions, etc.
  • The outermost layer, the CLI, is called a shell.
Terminals

All that is needed to use a Unix shell is a keyboard and a screen. In the olden days, these were provided by a simple hardware device called a terminal, which connected a keyboard and screen to the system through a simple communication cable. These terminals typically did not have a mouse or any graphics capabilities. They usually had a text-only screen of 80 columns by 24 lines, and offered limited capabilities such as moving the cursor, scrolling the screen, and perhaps a limited number of colors, usually 8 or 16.

Hardware Terminal

Hardware terminals lost popularity with the advent of cheap personal computers, which can perform the functions of a terminal, as well as running programs of their own. Hardware terminals are still used in some settings that require extreme security, such as banking, where a PC's capabilities would aid in stealing information by saving it to an external device or transmitting it across a network. A dumb terminal ensures that information can be sent to the user on the screen and nowhere else.

Hardware terminals have been largely replaced by terminal emulators. A terminal emulator is a simple program that emulates an old style terminal within a window on your desktop.

Terminal emulator
A Terminal emulator.

All Unix systems come with a terminal emulator program. There are also free terminal emulators for Windows, which are discussed in the section called “Logging In Remotely”.

For purists who really want to emulate a terminal, there's Cool Retro Terminal (CRT for short, which also happens to stand for cathode ray tube). This emulator comes complete with screen distortion and jitter to provide a genuine nostalgic 1970s experience.

Cool Retro Terminal
Cool Retro Terminal
Basic Shell Use

Once you're logged in and have a shell running in your terminal window, you're ready to start entering Unix commands.

The shell displays a shell prompt, such as "FreeBSD coral.acadix bacon ~ 1011:" in the image above, to indicate that it's waiting for you to enter the next command. The shell prompt can be customized by each user, so it may be different on each Unix system you use.

Note

For clarity, we primarily use the following to indicate a shell prompt in this text:

shell-prompt:
            

To enter a Unix command, you type the command on a single line, edit if necessary (using arrow keys to move around), and press Enter or Return.

We can also enter multiple Unix commands on the same line separated by semicolons.

Modern Unix shells allow commands to be extensively edited. Assuming your terminal type is properly identified by the Unix system, you can use the left and right arrow keys to move around, backspace and delete to remove characters (Ctrl+h serves as a backspace in some cases), and other key combinations to remove words, the rest of the line, etc. Learning the editing capabilities of your shell will make you a much faster Unix user, so it's a great investment of a small amount of time.

If you have access to a Unix system now, do the practice break below. This practice break is offered again in the section called “Logging In Remotely” for those who will be using a remote Unix system.

Example 3.2. Practice Break

Note

For this, and all practice breaks that follow, students should do the exercises shown. If you are reading this for a class, then these exercises are meant to be done in class. Try them on your own, do your best to understand what is happening, and ask the instructor for clarification if necessary.

Remotely log into another Unix system using the ssh command or PuTTY, or open a shell on your Mac or other Unix system. Then try the commands shown below.

Unix commands are below preceded by the shell prompt "shell-prompt: ". Other text refers to input to the program (command) currently running. You must exit that program before running another Unix command.

Lines beginning with '#' are comments to help you understand the text below, and not to be typed.

Don't worry if you're not clear on what these commands do. You do not need to memorize them right now. This exercise is only meant to help you understand the Unix CLI. Specific commands will be covered later.

# Print the current working directory
shell-prompt: pwd

# List files in the current working directory (folder)
shell-prompt: ls
shell-prompt: ls -al

# Two commands on the same line.  A ';' is the same as a newline in Unix.
shell-prompt: ls; ls /etc

# List files in the root directory
shell-prompt: ls /

# List commands in the /bin directory
shell-prompt: ls /bin

# Search the directory tree under /etc
shell-prompt: find /etc -name '*.conf'

# Create a subdirectory
shell-prompt: mkdir -p Data/IRC

# Change the current working directory to the new subdirectory
shell-prompt: cd Data/IRC

# Print the current working directory
shell-prompt: pwd

# See if the nano editor is installed
# nano is a simple text editor (like Notepad on Windows)
shell-prompt: which nano

    If this does not report "command not found", then do the following:

# Try the nano editor.  Nano is an add-on tool, not a standard tool on
# Unix systems.  Some systems will not have it installed.
shell-prompt: nano sample.txt

# Type the following text into the nano editor:

This is a text file called sample.txt.
I created it using the nano text editor on Unix.

# Then save the file (press Ctrl+o), and exit nano (press Ctrl+x).
# You should now be back at the Unix shell prompt.

# Try the "vi" editor
# vi is standard editor on all Unix system.  It is more complex than nano.
# It is good to know vi, since all Unix systems have it.
shell-prompt: vi sample.txt

    Type 'i' to go into insert mode
    Type in some text
    Type Esc to exit insert mode and go back to command mode
    Type :w to save
    Type :q to quit
    
    # "ZZ" is a shortcut for ":w:q"

shell-prompt: ls

# Echo (concatenate) the contents of the new file to the terminal
shell-prompt: cat sample.txt

# Count lines, words, and characters in the file
shell-prompt: wc sample.txt

# Change the current working directory to your home directory
shell-prompt: cd
shell-prompt: pwd

# Show your login name
shell-prompt: id -un

# Show the name of the Unix system running your shell process
shell-prompt: hostname

# Show operating system and hardware info
shell-prompt: uname -a

# Today's date
shell-prompt: date

# Display a simple calendar
shell-prompt: cal
shell-prompt: cal 2023
shell-prompt: cal nov 2018
shell-prompt: cal jan 3000

# CLI calculator with unlimited precision and many functions
shell-prompt: bc -l
scale=50
sqrt(2)
8^2
2^8
a=1
b=2
c=1
(-b+sqrt(b^2-4*a*c))/2*a
2*a
quit

# Show who is logged in and what they are running
shell-prompt: w
shell-prompt: finger

# How much disk space is used by the programs in /usr/local/bin?
shell-prompt: du -sh /usr/local/bin/

# Copy a file to the current working directory
shell-prompt: cp /etc/profile .
shell-prompt: ls

# View the copy
shell-prompt: cat profile

# View the original
shell-prompt: cat /etc/profile

# Remove the file
shell-prompt: rm profile
shell-prompt: ls

# Exit the shell (which logs you out from an ssh session)
# This can also be done by typing Ctrl+d, which is the ASCII/ISO
# character for EOT (end of transmission)
shell-prompt: exit
    

Practice

Note

Be sure to thoroughly review the instructions in Section 2, “Practice Problem Instructions” before doing the practice problems below.
  1. What is a UI?

  2. What is a GUI?

  3. What is the difference between Unix and other operating systems with respect to the GUI?

  4. How is Unix + X11 different from remote desktop systems and terminal servers?

  5. What is a virtual desktop?

  6. What are the two basic types of user interfaces? Which type is a GUI?

  7. What is a CLI?

  8. What types of applications are better suited for a menu-driven interface? Why?

  9. What types of applications are better suited for a command-driven interface?

  10. Which is easier to automate, a menu-driven system or a CLI? Why?

  11. How many scientific programs offer a menu-driven interface? Why?

  12. What is a shell?

  13. What is a kernel?

  14. What are libraries? What kinds of functionality do they provide?

  15. What is a terminal?

  16. What is a terminal emulator?

  17. Do people still use hardware terminals today? Explain.

  18. What is a shell prompt?