Skip to main content

Office of Information Technology (OIT)

UT Arlington
OIT: Office of Information Technology

helpdesk@uta.edu ·  Work Order · 817-272-2208 · System Status

We are your IT partner!

Introduction to UNIX

Description:

Introduction to UNIX

The " Using UNIX Guide" is available for download to read or print in PDF format.  If you choose to print this document in an ACS lab, print in ranges of 20 pages (print pages 1-20, 21-40, 41-60, etc.) To view this document on the web, follow a link below.


  1. About UNIX
    1. Logging In and Logging Out
    2. Changing Your Password
    3. Shells
    4. Getting Help
    5. Viewing Files
    6. Input/Output
    7. Pipes
  2. Managing Files
    1. The ls Command
    2. The rm Command
    3. The cp Command
    4. The mv Command
    5. The wc Command
    6. The cmp Command
    7. The diff Command
    8. The grep Command
    9. The sort Command
  3. Printing Files
  4. Managing Directories
    1. Understanding Directories
    2. Using Wildcards and Symbolic Substitution
    3. Basic Directory Commands
    4. The pwd Command
    5. The cd Command
    6. The mkdir Command
    7. The cp Command
    8. The rmdir Command
    9. Protecting Files
    10. The chmod Command
    11. Checking Existing Permissions
  5. Advanced Usage - Part 1
  6. Advances Usage - Part 2

About UNIX

The UNIX operating system was developed by Ken Thompson in 1969 at AT&T Research Division at Bell Laboratories. In 1974, several universities acquired the source code of the UNIX operating system. The UNIX operating system includes many of the features found in the Berkeley Software Distribution (BSD) V4.3.

This document presents some basic UNIX commands and concepts. If you need more information about a particular topic, please use the man command or the dxbook (or answerbook) command (for information on the man command, see "Getting Help"; for information on the dxbook (or answerbook) command, see "Accessing UNIX Documentation Using X Windows").

In all the examples given in this document, items in bold represent what you type at the keyboard. Keys that you press are represented in angle brackets. For example, the Enter key is represented by the symbol <return>. If two keys need to be pressed at the same time, they will both be included inside the angle brackets. For example, <CTRL-L> control L key. The standard input is the terminal and standard output is the screen. This document is not intended to be a complete guide to UNIX. Many of the commands discussed in this document have several options not included in the discussion. For a complete description of UNIX commands and options, please use the man command or the dxbook (or answerbook) command (for information on the man command, see "Getting Help"; for information on the dxbook (or answerbook) command, see "Accessing UNIX Documentation Using X Windows").


Logging In and Logging Out

Logging In

To use a UNIX system, you must have a valid User ID and password on that system. You can log in to a UNIX system from facilities on campus or from home.

When you log in, you'll need to type your User ID and password. When typing your User ID or password, be sure to type uppercase letters and lowercase letters as such. Case is significant. When typing your password, notice that the letters don't appear on your screen as you type them. This is for your account's security.

**If you make a mistake while typing your User ID or password, you must use the <delete> key will not work.

After entering your password, the system checks both your User ID and your password. If either your User ID or password is invalid or incorrect, then you'll see the following error message ending with another login: prompt:

login:
Password: xxxxxxxx <return>
Login incorrect
login:

After logging in to a UNIX system, you'll see three things: the date and time of your last login, any sign-on messages from the system's administration (optional), and finally the system prompt.
In the following example, the date and time of the last login (no sign-on message appears) and the system prompt are displayed:

login: jsmith <return>
Password: xxxxxxxx <return>
Last login: Thu Aug 28 8:55:28 from 129.107.1.100
%

When you log in to GAMMA or OMEGA, you'll see a prompt that includes that system's name. In this document, however, we'll use the generic C shell prompt, %. When you see your system's prompt, you are ready to enter UNIX commands.

The UNIX operating system is case sensitive. You must enter UNIX commands in lowercase letters just as you must enter your User ID in lowercase letters.

Logging Out

To end a session on a UNIX system, type logout, exit, or press <ctrl-d> at the command prompt.
%
or
%strong>exit <return>
or
%strong><ctrl-d>

Changing Your Password



Your password on a UNIX system must follow these rules:
Your password must be at least 6 characters long and contain at least one numeric or special character.

To change your password on a UNIX system administered by Academic Computing Services, type passwd at the command prompt and enter your old password as instructed. After typing your new password, you must correctly retype it for verification. In the following example, the password is changed correctly:

% passwd <return>
Changing password for jsmith
Old password: xxxxxxxx <return>
New password: yyyyyyyy <return>
Retype new password: yyyyyyyy <return>
%

Passwords are not displayed on the screen.
In the following example, the password does not change because the new password was not retyped correctly:

% passwd <return>
Changing passwd for jsmith
Old password: xxxxxxxx <return>
New password: yyyyyyyy <return>
Retype new password: zzzzzzzz <return>
Mismatch - password unchanged.
%


Shells

After logging in to a UNIX system, you'll see the command prompt. At this point, you can enter shell commands. A shell acts as a translator between you and the UNIX operating system. The shell relays your commands to the operating system and returns any responses to you. There are two well-known shells. The first is called the Bourne shell and is named after its developer. The second shell is called the C shell and was developed at the University of California at Berkeley. All of the commands discussed in this guide are C shell commands (the majority of C shell commands are also the same as Bourne shell commands).

Shell Command Syntax

The basic syntax of a shell command is:

command [options] objects

where...
command: Is the name of the shell command.
options: Modify the way a command works. The options are usually single characters and are preceded by a dash (-).
objects: Are the objects that the command is applied against. Objects are italicized in this guide when showing the format of a command.

In the following example, the command cat n file1:
% cat -n file1 <return>

You can type several commands on the same line; just separate the commands with a semicolon (;). You can also type a command on more than one line; just place a backslash (\) at the end of the current line and continue with the rest of the command on the next line.


Getting Help

Two commands to get help on a UNIX system are help man. A third command to get help while using X Windows is dxbook or answerbook), discussed in section "Using X Windows Systems".

Typing help command for further information.

Typing man
·
Press <spacebar>

·
Press <return>

·
Type q

In the following example, the man cat
% man cat <return>
cat(1)
NAME
cat - concatenate and print data
SYNOPSIS
cat [-b] [-e] [-n] [-s] [-t] [-u] [-v] file ...
DESCRIPTION
The cat command reads each file in sequence and displays it on the standard output. Therefore, to display the file on the standard output you type:
cat file
To concatenate two files and place the result on the third you type:
cat file1 file2 > file3
.
.
.q
%


Viewing Files

There are several UNIX commands for viewing files without starting an editing session. Some of these commands are listed below. To get a complete description of these commands and the different options used with these commands, use the man dxbook answerbook command.

The cat Command

The cat
The cat command displays the contents of file.test:

% cat file.test <return>
This is just a test file
This file contains only two lines.
%

The more Command

The more cat more, you can use the following commands:
·
Press <return>

·
Press <spacebar>

·
Type q

In the following example, the more <spacebar> q commands are also used:

% more file1 <return>
This is line number 1.
This is line number 2.
This is line number 3.
.
.
.
This is line number 23.
--More--(31%) <spacebar>
This is line number 24.
This is line number 25.
This is line number 26.
.
.
.
This is line number 46.
--More--(81%) q
%

The less Command

The less, you can use the following commands:

* Press <return>
* Type b
* Type f, or press <spacebar>, to scroll forward one screen.
* Type q
In the following example, the less b, f, and q are also used:

% less file1 <return>
This is line number 1.
This is line number 2.
This is line number 3.
.
.
.
This is line number 23. f
This is line number 24.
This is line number 25.
This is line number 26.
.
.
.
This is line number 46. b
This is line number 1.
This is line number 2.
This is line number 3.
.
.
.
This is line number 23. q
%

The head Command

The head command displays the first 6 lines in file1:

% head -6 file1 <return>
This is line number 1.
This is line number 2.
This is line number 3.
This is line number 4.
This is line number 5.
This is line number 6.
%

The tail Command

The tail command displays the last 10 lines (by default) of a file. You can specify how many lines the tail command shows by following the tail command with a hyphen and the number of lines you want displayed. In the following example, the tail command displays the last 3 lines of file1:

% tail -3 file1 <return>
This is line number 98.
This is line number 99.
This is line number 100.
%


Input/Output

Most of the commands on a UNIX system require input and produce output. For example, the cat command uses any file name following it as input and displays the contents of the file on the screen as output.

On a UNIX system, you can redirect both the source of the input and the destination of the output. This concept is called input/output redirection. Some of the redirection operators and their definitions are:

Operator
Meaning
>
Redirects standard output.
>>
Redirects and appends standard output.
>&
Redirects standard output and standard error.
>>&
Redirects and appends standard output and standard error.
<
Redirects standard input.
<<xxx
Reads input up to a line identical with xxx .
|
Redirects standard output to another command (see section "Pipes").

In the following example, the output of the cat
% cat file1 <return>
This is a line in file 1.
% cat file2 <return>
This is a line in file 2.
% cat file1 file2 > file3 <return>
% cat file3 <return>
This is a line in file 1.
This is a line in file 2.
%
In the following example, the output of the cat
%
This is line 1 in file 3.
This is line 2 in file 3.
% cat file1 <return>
This is line 1 in file 1.
% cat file1 >> file3 <return>
% cat file3 <return>
This is line 1 in file 3.
This is line 2 in file 3.
This is line 1 in file 1.
%
In the following example, the input is read from the terminal until the pattern EOF is encountered. All information received is stored in the file file1.
% cat > file1 << EOF <return>
? This is the first line in file1. <return>
? EOF <return>
% cat file1 <return>
This is the first line in file1.
%
When you want to redirect the input of a program, use the standard input redirection operator (<)*** . The input of the program is then read from a file rather than from the keyboard.


Pipes

A pipe makes the output of one command become the input of another command without creating an intermediate file. A vertical bar (|)
In the following example, the output of the cat command becomes the input to the sort command with the help of a pipe:

% cat test <return>
wc
more
head
cat
% cat test | sort <return>
cat
head
more
wc
%

Managing Files

The ls Command
The rm Command
The cp Command
The mv Command
The wc Command
The cmp Command
The diff Command
The grep Command
The sort Command

There are many UNIX commands to help you manage your files. Several of these commands are discussed in this chapter. To get a complete description of each command and its options, please use the man dxbook answerbook) command (for more information on the man command, see "Getting Help"; for information on the dxbook command, see section "Using X Windows Systems").

The ls Command

The ls command is:

ls [options ]/directory

In the following example, the ls command displays the contents of user jsmith's home directory and the /home/dept directory (for information on directories, see "Managing Directories"):

% ls <return>
file1 file2 file3 letters
% ls /home/dept <return>
jsmith bcarson
%

The rm Command

The rm command is:

rm [options ]/file

Use the rm
In the following example, the rm
% cat file1 <return>
This is the first line in file1.
% rm file1 <return>
% cat file1 <return>
file1: No such file or directory
%
Add the option -i (for interactive) to the rm command when you want to be asked to confirm deleting any files.

The cp Command

The cp command is:

cp [options ]/source.file destination.file

Use the cp command with caution. If the destination file already exists, then the copy command replaces that file with the new file.

In the following example, the cp
% cat file1 <return>
abc def ghi
% cp file1 file2 <return>
% cat file2 <return>
abc def ghi
%

Add the option -i (for interactive) to the cp command when you want to be asked to confirm replacing any file that already exists.

The mv Command

The mv command is:

mv [options ]/old.filename new.filename

Use the mv command with caution. If the destination file already exists, then the move command replaces that file with the new file.

In the following example, the mv command renames file1 as file2:

%
abc 123 45678
% mv file1 file2 <return>
% cat file2 <return>
abc 123 45678
% cat file1 <return>
file1: No such file or directory
%
Add the option -i mv*** command when you want to be asked to confirm replacing any file that already exists.

The wc Command

The wc command is used on file1:

%
This is line number 1.
% wc file1 <return>***
1 5 23 file1
%
Thus file1 contains 1 line, 5 words, and 23 characters.

The cmp Command

The cmpcmp command compares letter1 and letter2:

% cat letter1 <return>
abc
cde
fgh
ijk
% cat letter2 <return>
abc
fgh
ijj
% cmp letter1 letter2 <return>
letter1 letter2 differ: char 5, line 2
%

The diff Command

The diff command is:

diff [options ]/file1 file2

The option -e command produces a script of a, c, and d commands for the ex editor.

In the following example, the diff -e option is also used:

% cat letter1 <return>
abc
cde
fgh
ijk
% cat letter2 <return>
abc
fgh
ijj
% diff letter1 letter2 <return>
2d1
< cde
4c3
< ijk
---
> ijj
% diff -e letter1 letter2 <return>
4c
ijj
.
2d
%

The grep Command

The grep command is:

grep/string file

If grep
%
abc
cde
efg
ijk
% grep efg letter1 <return>
efg
% grep "abc def" letter1 <return>***
%

The sort Command

The sort
In the following example, the sort
% cat file1 <return>
hello
help
elephant
%
elephant
hello
help
%

Printing Files

The lpr
% lpr file1
%
To determine your default print queue, view the file /etc/printcap and search for the queue name with the entry lp. To print a file at another ACS computing facility, or to another print queue at the default site use the -P print queue lpr*** command. Refer to the ACS document "Using ACS Printers" for a complete list of print queues available.

Managing Directories

Using Wildcards and Symbolic Substitution

Understanding Directories

On a UNIX system, a directory contains a list of files and subdirectories. After logging in, you are placed in a directory called your home directory. Your home directory is the first level directory where you can save your files.

At the very top of the directory structure is the root directory, denoted by a single slash (/). Subdirectories are denoted by a slash followed by the subdirectory's name. Figure 1 represents a sample directory structure. In Figure 1, the home directory is a subdirectory of the root directory, departmental directories are subdirectories of the home directory, and individual user's directories are subdirectories of their departmental directory.
 
Figure 1. A Sample Directory Tree Structure
According to Figure 1, three files, file1, file2, and file3, as well as the subdirectory /letters are in user jsmith's home directory. (User jsmith's home directory is /home/dept/jsmith which is a subdirectory under the dept directory which is a subdirectory under the home directory).

Two hidden files exist in each subdirectory, one designated by a single period (.) and the other designated by two periods (..). The single period file (.) is a pointer to the current working directory, whereas the double period file (..) is a pointer to its parent directory. A tilde (~) always represents your home directory.

Using Wildcards and Symbolic Substitution

You can use special characters known as wildcards to help you find file names that match a certain pattern. The two most common wildcards are the question mark (?) (*). The rules for using ? * are:

?
Matches any one character.
*
Matches any group of zero or more characters.
You can also use metasequences to find file names. A metasequence is simply a list of characters, any one of which can be matched. To use a metasequence, simply place the characters to be matched between the brackets [ ].
The following table lists examples of wildcards and metasequences:
*.*
Filenames containing a period (.).
*.com
Filenames ending with .com.
?.out
Filenames with one character preceding the period and ending with .out.
a[bc]
Filenames ab and ac.
pq[a-z]
Filenames containing 3 characters in the range pqa through pqz.

Basic Directory Commands

The pwd Command
The cd Command
The mkdir Command
The cp Command
The rmdir Command

All of the examples given in this section refer to the directory structure described in Figure 1 of section " Understanding Directories". As shown in Figure 1, user jsmith's home directory is /home/dept/jsmith.

The pwd Command

The pwd
%
/home/dept/jsmith
%

The cd Command

The cd
% pwd <return>
/home/dept/jsmith
% cd letters <return>
% pwd <return>
/home/dept/jsmith/letters
%
In the following example, user jsmith returns to the directory above the current working directory:
% pwd <return>
/home/dept/jsmith/letters
% cd .. <return>
% pwd <return>
/home/dept/jsmith
%
In the following example, user jsmith changes to the root directory:
% cd / <return>
% pwd <return>
/
%
You can change to your home directory from any other directory by using the cd
% pwd <return>
/
% cd <return>
% pwd <return>
/home/dept/jsmith

The mkdir Command

The mkdir command is:

mkdir/directory

In the following example, user jsmith uses the mkdir
% pwd <return>
/home/dept/jsmith
% mkdir newdir <return>
% ls <return>
file1 file2 file3 letters newdir
%

The cp Command

The cp mv
%
/home/dept/jsmith
% ls <return>
file1 file2 file3 letters newdir
% cp file1 newdir <return>
%
% ls <return>
file1 file2 letters newdir
% ls newdir <return>***
file1 file3
%***

The rmdir Command

The rmdir command is:

rmdir/directory

In the following example, user jsmith uses the rmdir
% pwd <return>
/home/dept/jsmith
% rmdir newdir <return>
rmdir: newdir: Directory not empty
%
% ls <return>
file1 file3
% rm file1 <return>
%
% ls <return>
% cd <return>
%
/home/dept/jsmith
% rmdir newdir <return>***
%*** ***

Protecting Files

The chmod Command
Checking Existing Permissions

On a UNIX system, the user's world is divided into three categories: User, Group, and Other.
The User
The Group
The Other
You may grant users in any of these categories permission to access your files. There are three kinds of permission:
Read permission (r) Permission to read a file.
Write permission
Execute permission (x) Permission to run an executable file.

The chmod Command

The chmod command has the following format:

chmod [mode ]/file

The mode field consists of three parts:
The category of users to be affected: user group
The action to be performed: add absolute
The permission to be affected: read write*** (x). 

Checking Existing Permissions

You can check what permissions are currently in effect by using the ls ls -l*** command to check existing permissions:

% pwd <return>
/home/dept/jsmith
% ls -l <return>
total 8
-rw------- 1 jsmith 1865 Nov 19 12:00 file1
-rw-rw---- 1 jsmith 256 Nov 01 09:05 file2
-rw----rw- 1 jsmith 865 Dec 25 05:00 file3
drw-rw-rw- 2 jsmith 512 May12 11:23 letters %
The first character in the file description describes the type of file. A "d" in the first column means that the file is a directory (the name of a subdirectory) and a "-" in the first column means the file is a plain file containing ASCII or binary information.

The next nine columns list the file protection for user, group, and other, in that order.

The information after the list of file protection describes the number of links to the file, the owner of the file, the size of the file in bytes (a byte = 1 char), the last date and time the file was modified, and the name of the file.

A link is a logical connection between files and directories, or between directories. A file has at least one link to the directory file in which it resides. A directory file has at least two links, one to itself and one to its parent directory file.

In the following example, user jsmith uses the chmod command with the subdirectory letters and the file file3 (note that the absolute action performed on letters replaces any existing permissions):

% pwd <return>
/home/dept/jsmith
% ls -l <return>
total 8
-rw------- 1 jsmith 1865 Nov 19 12:00 file1
-rw-rw---- 1 jsmith 256 Nov 01 09:05 file2
-rw----rw- 1 jsmith 865 Dec 25 05:00 file3
drw-rw-r-- 2 jsmith 512 May12 11:23 letters
% chmod o=w letters <return>
% chmod g+r file3 <return>
%
total 8
-rw------- 1 jsmith 1865 Nov 19 12:00 file1
-rw-rw---- 1 jsmith 256 Nov 01 09:05 file2
-rw----rw- 1 jsmith 865 Dec 25 05:00 file3
drw-rw--w- 2 jsmith 512 May12 11:23 letters***

*** *** *** *** *** *** *** *** ***







Available To:

  • Students Admitted to UT Arlington
  • Vendors
  • Retirees
  • Visitors and Guests
  • Departments and Offices at UT Arlington
  • Faculty (currently appointed) and Staff
  • Event-Based

System requirements: None, Solaris, Linux