What is UNIX?
UNIX is an operating system which like all other operating systems act as a master of ceremonies since their jobs are to accept and dispatch user commands and directing the system response to the appropriate place. UNIX is referred to as a multi-user, multitasking operating system, since multi users may each execute multiple commands simultaneously.
Note: There is an operating system called Linux. It is a free open-source operating system within the UNIX family. The difference between UNIX and Linux are almost invisible on a user-level. There are lots of commands transparent between the two systems. So you can learn about Linux from this session.
There are three main parts of the UNIX operating systems:
- The kernel – the core of the program which is loaded up when you start.
- The shell – the program where you enter your commands to the operating system.
- The file system – where your files and data are stored.
![]() |
The UNIX Filesystem
The UNIX operating system is built around the concept of a filesystem which is used to store all of the information at constitutes the long term state of the system.
Every item stored in a filesystem belongs to one of four types:
- Ordinary files: ordinary file contain text, data, or program information. Files cannot contain other files or directory. This is type of file that you usually work with.
- Directory: directories are containers or folders that hold files, and other directories.
- Devices: to provide applications with easy access to hardware. UNIX allows them to be used in much the same way as ordinary files. There are two types of devices in UNIX: block-oriented devices which transfer data in blocks (e.g. hard disk) and character-oriented devices that transfer data on a byte-by-byte basis (e.g. terminals)
- Links: A link is a pointer to another file. There are two type of links - a hard link to a file is indistinguishable from the file itself. A soft link (symbolic link) provides an indirect or short cut to a file.
Typical UNIX Directory Structure
The UNIX filesystem is laid out as a hierarchical tree structure which is anchored at a special top level directory know as the rood.
![]() |
Directory Typical Contents
/ The “root” directory
/bin Essential low-level system utilities
/usr/bin Higher level system
/bin and /sbin Hold system binaries. These are different
from the program in /usr/bin in that they
are design as the basic program to run the
the system.
/etc hold system-wide configuration files.
/var hold log file, cache, and spool directories
/tmp is meant for temporary storage by users.
/home is a typical location of users.
Logging into (and out off) UNIX Systems
SSH or text-based (TTY) terminal:
When you connect to a UNIX computer remotely (client computer) or when you login locally using terminal, you will see the prompt:
login: At this prompt, type in your username and hit enter or return key. You should be prompted for password:
login: bobcat
password: your password won’t display on the screen as you type it in
username or password is incorrect, you will get an appropriate message from the computer and you will be presented with the login prompt again. Otherwise, you should be presented with a shell prompt which looks something like this:
either $ or % or bobcat@computer’s name:
e.g bobcat@go:/>![]() |
![]() |
When you are ready to leave, you can log out by typing one of many commands:
bobcat@go:>exit
bobcat@go:>logout
Introduction to UNIX commands
Basic form is
command name option(s) argument(s)Example 1
date - find out the date and time
ls –l - list a directory with more information
mv old_data new_data - Moving a file and renaming it
- To display the on-line manual page about a command: man command_name
Typical UNIX Key commands
ls List file – list files and sub directories in
the current directory
mkdir Make directory
e.g :/>mkdir music
cd Change directory
pwd Print working directory
rm Remove (delete) a file
rmdir Remove (delete) a directory
chmod Change the permission of a file or dir.
man Manual the help files
cat Concatenate files or display them
more/less Display files by screen
mv Move or rename files or directories
head Show the first few lines of a file
tail Show the last few lines of a file
cmp Compare two files, byte by byte.
diff Compare to file, line by line.
grep Matching a pattern
e.g :>grep ‘txt’ hello.txt
gzip Reduces the size of one or more files
gunzip Decompress file. It is equivalent gzip –d.
tar Archive utility
e.g :> tar cvf /home/bill <-- Creating
e.g :> tar xvf /home/jack <--Extracting
ssh Remort login program
![]() |
Useful Shortcuts
The UNIX shell provides very nice shortcuts. These make your life easier when working in the terminal.
History: The shell remembers all the commands you typed. You can scroll through your last commands with the arrow keys (Up and Down). Additionally, you can type history to list all commands you have been used.
bobcat@go:> history |grep -i keywordPipes: it let you use the output of one command as the input of another one.
Example 2
bobcat@go:> ls –l | sort
bobcat@go:> history | more
File and directory permission
Every file or directory in a UNIX file system has three types of permission that define whether certain actions can be carried out.
read(r): A user who hasreadpermission for a file may look at its contents or make a copy of it. For directory, read permission enables a users to find out what file are in that directory.write(w): A user who haswritepermission for a file can alter or remove the contents of that file. For directory, the user can create and delete file in that directory.execute(x): A user who hasexecutepermission for a file can execute the contents of that file to be executed. For directory, execute permission allows a user to change to that directory.
For each file and directory, the read, write, and execute permission may be set separately for each of the following classes of users:
User(u): The user who owns the file or directory.Group(g): Several users purposely lumped together so that they can share access to each other’s files.Other(o): The remainder of the authorized users of the systems
Alternatively, specify permission by three-digit sequence. The first digit designates owner permission; the second, group permission; and the third, other permission. Permissions are calculated by adding the following octal values:
4 Read2 Write1 Execute
Display information about files and directories by using ls command with –l option.
bobcat@go> ls –l myfile.java
-rw-r--r-- 1 bobcat users 198 2006-01-25 18:27 myfile.java
bobcat@go:> ls –l
-rw-rw-rw 1 bobcat users 198 2006-01-25 18:27 myfile.java
(to allow read and write permission for all users
Change group(chgrp): can be used to change the group that a file or directory belong to.
bobcat@go:> chgrp admin myfile.java
bobcat@go:> ls –l myfile.java
-rw-rw-rw 1 bobcat admin 198 2006-01-25 19:27 myfile.java
Working with Text Editor
Vi - Text Editor
bobcat@go:> vi filename <-- vi myfile.java
filename into a buffer, and display the file on the screen. It the file is larger than the screen can display, the screen will act as a window into the file. At the beginning of a session, the screen will display the first part of the file.
If filename does not exist, vi will create it.
bobcat@go:> vi filename <-- start the editorGet in and out of vi
vi [filename] <-- Enter vi
[esc]:wq <-- leave the editor and save the file
[esc]:q! <-- leave the editor without save the file
![]() |
Insert text mode
Hit [esc] key to return to common modei <-- for insert text to the left cursora <-- use to insert(append) text to the right cursorA <-- insert(append) text to the end of current lineo <-- open new line for inserting text below cursor lineO <-- open a new line for inserting text above cursor line
Deleting and changing text mode
Hit [esc] key to return to common modex <-- deletes one character under cursor5x <-- another way to repeat the deletion command.dw <-- deletes word under and to right of cursor.dd <-- deletes the cursor line.D <-- deletes from cursor to the end of line.cw <-- changes word under and to right cursor to new text.cc <-- changes current line to new text you enter.s <-- substitutes character under cursor with new text.S <-- substitutes current line with new text you enter.r <-- replace character under cursor with new character..
Command to join two lines search keyword
Hit [esc] key to return to common modeJ <-- joins next line to the end of the cursor./keyword or /string <-- searches forward through text.
Quiz
Write a UNIX command line to do each of the following:
Exercise 1
Show the full pathname of the current directory:
Solution
...
Exercise 2
Show the online documentation for the “sort” command:
Solution
...
Exercise 3
Show how to allow the following access to the existing file ‘BIS141.txt’: all permissions for you, only read and write permissions for members of your group, and only read permission for other users:
Solution
...
Exercise 4
Rename the existing file, “UCMerced.txt”, to the new name, “UCM.text”:
Solution
...
Exercise 5
Copy the file ‘genome’ from your current directory to /usr/local/access:
Solution
...
Exercise 6
Delete all files in the directory /home/ucmerced/backup:
Solution
soon
Exercise 7
Delete the directory /home/ucm/backup:
Solution
...
Exercise 8
Show to change a working directory to /home/ucmerced/genome:
Solution
...
Exercise 9
Show the name, sizes, dates of all files in the current directory:
Solution
...
Exercise 10
Show the content of a zipped file, ‘ucmerced.zip’:
Solution
...
Exercise 11
Show the current date and time:
Solution
...
Exercise 12
Show how to logout from the current Unix/Linux session:
Solution
...
Answer the next questions about the text editor, vi.
Exercise 13
Write ONE command to initiate an insert mode:
Solution
i
Exercise 14
Write command(s) to delete a word:
Solution
...
Exercise 15
Write ONE command to save modifications and leave from the vi session:
Solution
...



UNIX Command Summary
Introduction to Linux
UC Merced - Center for Computational Biology






