Learning the Unix Operating System

I want to know more about the Unix Operating System. Most internet based servers today run on Unix or Unix like servers (about 80% - see https://en.wikipedia.org/wiki/Usage_share_of_operating_systems#Public_servers_on_the_Internet).

Date Created:
Last Edited:

References



Definitions


  • POSIX
    • The Portable Operating System Interface (POSIX) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines both the system and user-level application programming interfaces, along with command line shells and utility interfaces, for software compatability (portability) with variants of Unix and other operating systems.


Preface


  • An operating system (or "OS") is a set of programs that controls a computer. It controls both the hardware (things you can touch - such as keyboards, displays, and disk drives) and the software (application programs that you run, such as a word processor).
  • Most computers have a single user OS, which means only one person can use the computer at a time. Almost all computers can do a lot more if it has a multiuser, multitasking operating system like UNIX. These powerful OSes let many people use computer at the same time and let each user run several jobs at once.
  • UNIX was invented almost 30 years ago for scientific and professional users who wanted a very powerful and flexible OS. Some of the reasons to use UNIX:
    • It comes with a huge number of application programs. You can get many others for free on the internet. (The GNU utilities, freely available from the Free Software Foundation, are very popular). You can thus do much more at much lower cost.
    • Some versions of UNIX itself are also free. Linux is a good example.
    • Most of the development of the internet was done on UNIX systems. Many internet websites and internet service providers are NIX because it's so powerful, flexible, and inexpensive.
    • UNIX runs on almost any kind of hardware. After you learn UNIX on one system, you'll know how to use it on any other system.


Getting Started


  • Before you can start using UNIX, your system administrator has to set up a UNIX account for you. In addition to knowing your account name, you may also need to know the hostname (name) of the computer that has your account.
  • The process of making yourself known to the UNIX computer system and getting to your UNIX account is called logging in. Before you start work, you must connect your terminal or window to the UNIX computer. Then login to UNIX and identify yourself.
  • Once your logged in, you're working with a program called a shell. The shell interprets the commands you enter, runs the program you've asked for, and generally coordinates what happens between you and the UNIX operating system. Common shells include Bourne (sh), Korn(sh), and C (csh), as well as bash and tcsh.
  • Shell prompts usually contain $ or %. The prompt can be customized, though, so your shell prompt may be different.
  • When you press ENTER the shell interprets your command line and executes the program. The first word you type at a shell prompt is always a UNIX command (program name). Like most things in UNIX, command names are case-sensitive.
  • Commands
    • date - Entering the date displays the current date and time
    • who - it lists each logged-on user's username, terminal number, and login time. The who command can also tell you who is logged in at the terminal you're using (whoami).
  • Control Characters:
    • CTRL+U - Erases the whole input line; you can start over
    • CTRL+S - Parses the output from a program that is writing to the screen
    • CTRL+Q - Restarts output after a pause by CTRL+S
    • CTRL+D - Used to signal end-of-input for some programs (like cat and mail) and return you to a shell prompt. If you type CTRL+D at a shell prompt, it may also log you out of the UNIX system.
  • To end a UNIX session, you must log out. You should not end a session by just turning off your terminal. To log out, enter the command exit.
  • A UNIX session that is unresponsive is called a "hung" or "frozen" terminal or session. If the session does not respond:
    • Try pressing the RETURN key
    • Some systems have a reset command that you can run by typing CTRL+J
    • If your shell has job control, type CTRL+Z
  • Syntax of UNIX Command Lines:
    • UNIX command lines can be simple, one-word entries like the date command. They can also be more complex: you may need to type more than the command name.
    • A UNIX command may or may not have arguments. An argument can be an option or a filename. The general format for a UNX command is command option(s) filename(s)
    • Two or more commands can be written on the same command line, each separated by a semicolon.


Using Windows Systems


  • All versions of UNIX work with computer terminals that handle a single window or a single login session. Most modern UNIX versions support one or more window systems. A window system is a package of programs that let a terminal handle many sessions at once.
  • If you are using Linux, most Linux users have a windows substitute called virtual consoles that can be accessed by holding down the ALT key and one of the function keys F1 through F8 which will bring up a separate UNIX session with its own shell prompt.


Your UNIX Account


  • As an authorized system user, you have an account that gives you:
    • A place in the UNIX filesystem where you can store your files
    • A username that identifies you and lets you control access to your files and receive messages from other users.
    • A customizable environment that you can tailor to your preferences.
  • A file is a unit of storage in UNIX, as in many other systems. A file can hold anything: text (a report you are writing, a to-do list), a program, digitally encoded pictures or sound, and so on. All of those are just sequences of raw data until they are interpreted by the right program.
  • In UNIX, files are stored into directories. A directory is actually a special kind of file where the system stores information about other files. A directory can be thought of as a place, so that files are said to be contained in directories and you are said to work inside a directory.
  • You start off in the home directory
  • The working directory is the directory you are currently working in.
  • All directories on a UNIX system are organizes into a hierarchal structure that you can imagine as a family tree. The parent directory of the tree is known as the root directory and is written as a forward slash (/).
  • To specify a file or directory location, you write its pathname. A pathname is like the address of the directory or file in the UNIX filesystem.
  • On a basic UNIX filesystem, all files in the filesystem are stored on disks connected to your computer. Network Filesystems make a remote computer's files appear as if they are part of your computer's directory tree.
  • The UNIX filesystem organizes its files and directories in an inverted tree structure with the root directory at the top. An absolute pathname tells you the path of directories you must travel to get from the root directory or file you want.
  • You can also locate a file or directory with a relative pathname. A relative pathname gives the location relative to your working directory.
  • Unless you use an absolute pathname, UNIX assumes you are using a relative pathname.
  • You can go up the tree by using the shorthand ".." for the parent directory.
  • The ls -l command can be used to show you the permissions for a file / directory
The permissions control who can read, write (modify), or execute the file (if it's a program). The permissions have ten characters, The first character shows the file type (directory or plain file). The second through the fourth characters show the permissions for the file's owner - yourself if you created the file. The fifth through the seventh characters show permissions for other members of the file's group. The eighth through the tenth characters show permissions for all other users.

The home directory has many hidden files (such as .bashrc) that are shell setup files that contain commands that are automatically executed when a new shell starts - especially when you login.

You should probably only edit your startup files when you know more about UNIX.


File Management


  • A file editor lets you add, change, and rearrange text easily. Two common UNIX editors are vi and emacs.
  • You can also create a file using input / output redirection.
  • The rules for naming files and directories are the same. Filenames may contain any character except /, which is reserved as the separator between files and directories in a pathname. Filenames are usually made up of upper- and lowercase letters, numbers, "." and underscores. UNIX does not require a "." in the filename.
  • A filename must be unique in its directory.
  • You can use wildcards (also called metacharacters) to specify many files at once. These special characters are *, ?, and [ ].
  • * - An asterisk is replaced by any number of characters in a filename.
  • ? - A question mark is replaced by a single character (h?p matches hop and hip, but not help)
  • [ ] - Square brackets can surround a choice of characters you'd like to match. Any one of the characters between the brackets will be matched. For example, [Cc]hapter would match either "Chapter" or "chapter"

Copy Command:

$ cp old new # old is the pathname of the old file and new is the pathname of the new file
  • Some versions of UNIX have an rcp (remote copy) command for copying files between two computers. The syntax of rcp is like cp, but rcp also lets you add the remote hostname to the start of a file or directory pathname. The syntax of each argument is: hostname:pathname
  • hostname: is needed only for remote files. You can copy from a remote computer to the local computer, from the local to a remote, or between the two computers.
$ rcp giraffe:report.may giraffe:report.june . # Command puts copies of the working directory "." on the giraffe computer
  • To use wildcards in the remote filename, put quotation marks "" around each remote name: rcp "giraffe:foor/lunch/*"


Multitasking


  • Suppose that you are running a command that will take a long time to process. On a single-task system like MS-DOS, you would enter the command and wait for the system prompt to return, telling you that you could enter a new command. In UNIX, there is a way to enter new commands in the "foreground" while one or more commands are still running in the "background". This is called background processing.
  • To run a command in the background, add the "&" character at the end of the command line before you press the [ENTER] key. The shell will then assign and display a process ID number for the command.
$ ls &
[1] 311
$ bin
  • The process ID (PID) of this command is 29890. The PID is useful when you want to check the status of a background process or, if you need to, cancel it. You don't need to remember the PID, because there are UNIX commands to check the processes you have running. I some shells, a status line will be printed on your screen when the background process finishes.
  • On many systems, the shell have another feature called job control. You can use the suspend character (usually CTRL+Z) to suspend a program running in the foreground. The program will pause and you'll get a new shell prompt.
    • You can then use the bg and fg commands to move the process to the background and the foreground, respectively.
  • The command ftp (file transfer protocol) is a flexible way to copy files between two computers. Both computers don't need to be running UNIX, though they need to be connected by a network that ftp can use.
# To start ftp, give the hostname of the computer
$ ftp hostname
  • ftp will prompt your username and password on the remote computer. This is something like a remote login, but ftp doesn't start your usual shell. Instead, ftp prints its own prompt and uses a special set of commands for transferring files


Command

Description

put filename

Copies the file filename from your local computer to the remote computer. If you give a second argument, the remote copy will have that name.

mput filenames

Copies the named files (you can use wildcards) from local to remote.

get filename

Copies the file filename from the remote computer to your local computer. If you give a second argument, the local copy will have that name

mget filenames

Copies the named files (you can use wildcards) from remote to local

cd pathname

Changes the working directory on the remote machine to pathname (ftp usually starts at your home directory on the remote machine)

lcd pathname

Changes ftp's working directory on the local machine to pathname (ftp starts at your working directory on the local computer). Note that the fcd lcd command changes only ftp's working directory. After you quit ftp, your shell's working directory will not have changed.

dir

List the remote directory (like ls -l)

binary

Transfers plain text files, translating data if needed

ascii

Transfers plain text files, translating data if needed

quit

Ends the ftp session and takes back to a shell prompt

  • The find command can search for files in many ways.
  • You can use the locate command to search part or all of a filesystem for a file with a certain name.


Redirecting I/O


  • Your terminal keyboard is the command's standard input, and the terminal screen is the command's standard output.
  • Input/Output redirection is the term given to when you use something other than your terminal keyboard as the input or something other than the terminal screen as the output for a command.
  • You can write the results of a command to a named file or some other device instead of displaying output on the screen by using the > operator. The pipe operator (|) sets the standard output to be the standard input of the next command.
$ cat /etc/password.text > password.text # write to file
$ who > users.txt
$ date > today.txt
  • The >> operator appends the output to the end of an existing file.


Where to Go From Here


  • Almost all UNIX documentation is derived from a manula originally called the UNIX Programmer's Manual.
  • If you want to know the correct syntax for entering a command or the particular features of a program, enter the command man and the name of the command:
$ man command
  • Linux systems, and many other systems, may also have a command called info. It serves the same purpose as man: to document system commands. The info output format is different, though.
$ info ls
10.1 ‘ls’: List directory contents
==================================

The ‘ls’ program lists information about files (of any type, including
directories). Options and file arguments can be intermixed arbitrarily,
as usual.

For non-option command-line arguments that are directories, by
default ‘ls’ lists the contents of directories, not recursively, and
omitting files with names beginning with ‘.’. For other non-option
arguments, by default ‘ls’ lists just the file name. If no non-option
argument is specified, ‘ls’ operates on the current directory, acting as
if it had been invoked with a single argument of ‘.’.

By default, the output is sorted alphabetically, according to the
locale settings in effect.(1) If standard output is a terminal, the
output is in columns (sorted vertically) and control characters are
output as question marks; otherwise, the output is listed one per line
and control characters are output as-is.

Because ‘ls’ is such a fundamental program, it has accumulated many
options over the years. They are described in the subsections below;
within each section, options are listed alphabetically (ignoring case).
The division of options into the subsections is not absolute, since some
options affect more than one aspect of ‘ls’’s operation.
  • Press q to quit reading the documentation in the terminal.


  • Other Unix Books:
    • Harley Hahn's Student Guide to UNIX, second edition; McGraw-Hill; ISBN 0-07-025492-3; 1996. Not just for students, this is a complete and very readable guide to UNIX and networking.
    • UNIX for the Impatient by Paul W. Abrahams and Bruce Larson; Addison-Wesley; 1996. Terse and detailed, for people comfortable with technical material.
    • UNIX Power Tools, second edition, by Jerry Peek, Tim O'Reilly, Mike Loukides, and others; O'Reilly & Associates; ISBN 1-56592-260-3; 1997. A huge collection of tips, techniques, and concepts for making intermediate users into advanced users.
    • UNIX in a Nutshell: System V Edition by Daniel Gilly and the staff of O'Reilly & Associates; ISBN 1-56592-001-5; 1992. From user commands to programmers' utilities, this book covers UNIX with concise descriptions and illustrative examples.
    • Linux in a Nutshell by Jessica Perry Hekman and the staff of O'Reilly & Associates; ISBN 1- 56592-167-4; 1997. A complete reference for Linux.

Comments

You must be logged in to post a comment!

Insert Math Markup

ESC
About Inserting Math Content
Display Style:

Embed News Content

ESC
About Embedding News Content

Embed Youtube Video

ESC
Embedding Youtube Videos

Embed TikTok Video

ESC
Embedding TikTok Videos

Embed X Post

ESC
Embedding X Posts

Embed Instagram Post

ESC
Embedding Instagram Posts

Insert Details Element

ESC

Example Output:

Summary Title
You will be able to insert content here after confirming the title of the <details> element.

Insert Table

ESC
Customization
Align:
Preview:

Insert Horizontal Rule

#000000

Preview:


Insert Chart

ESC

View Content At Different Sizes

ESC

Edit Style of Block Nodes

ESC

Edit the background color, default text color, margin, padding, and border of block nodes. Editable block nodes include paragraphs, headers, and lists.

#ffffff
#000000

Edit Selected Cells

Change the background color, vertical align, and borders of the cells in the current selection.

#ffffff
Vertical Align:
Border
#000000
Border Style:

Edit Table

ESC
Customization:
Align:

Upload Lexical State

ESC

Upload a .lexical file. If the file type matches the type of the current editor, then a preview will be shown below the file input.

Upload 3D Object

ESC

Upload Jupyter Notebook

ESC

Upload a Jupyter notebook and embed the resulting HTML in the text editor.

Insert Custom HTML

ESC

Edit Image Background Color

ESC
#ffffff

Insert Columns Layout

ESC
Column Type:

Select Code Language

ESC
Select Coding Language