CP1300 Introduction to UNIX
Last modified Wednesday, 09-Aug-2000 03:59:54 UTC.
UNIX History
(Jason's Notes)
- Developed in 1969 by Ken Thompson and Dennis Ritchie at
AT&T Bell Labs
- A shared multi-user environment, compact and highly portable
- Closely related to (and in some ways based upon) the earlier Multics
operating system
- Designed for groups of users
- General purpose programming
- Used within Bell Labs until the late 1970's, when some universities
also began using it as a research environment
- Many variations have been produced over the years, among them
- Berkeley Unix (BSD)
- Ultrix and OSF/1 (the DEC versions of Unix)
- Xenix (the Microsoft version of Unix)
- SunOS and Solaris (the Sun versions of Unix)
- Linux (a PC version of Unix)
UNIX Users
- Users have a
- User name
- User groups
- Password
- Logging in
- The JCU menu (never again)
- Shell
- Prompts
- Commands (pine :-)
- Setting your password
passwd sets your password
- Logging out
UNIX File Systems
(Jason's Notes)
- The tree structure
- Directory files
- The root directory
- The current directory
pwd returns the path name of the current directory
- Your home directory
- Normal files
- ASCII files
- Binary files
- Executable binary files
- Every file has an owner and a group
- Listings
- ls lists the non-hidden files in the current directory
- ls -a causes all files to be listed
- ls -F causes files to have a type indicator appended
- Nothing for normal files
- / for directories
- * for executable binaries
- ls -l causes all details to be listed
- Special directory names
- The root directory /
- Your home directory ~
~ "magically" expands to the path name of your
home directory
- The current directory .
In this context . is followed by /
- The parent directory ..
- Moving around the tree
cd directory changes the current directory to
directory
- File names
- Individual file names
- Can contain any character
- Alphabetics are case sensitive
- Avoid using other than alphanumeric and the specials
_ . + -
- Absolute names start with / or ~
- Relative names are relative to the current directory
- Hidden files start with . not followed by /
- File name expansion
- ? stands for any character in a file name
- * stands for any number of characters in a file name
UNIX File Manipulation
(Jason's Notes)
- Viewing files
- cat filename will display
filename on the screen
- more filename will display
filename on the screen one page at a time
- less filename will display
filename on the screen one page at a time,
and allows movement up and down in the file
- Creating and changing files
- pico filename will (create and) edit
filename
- vi, vim, and emacs are better than
pico, but harder to learn
- vilearn is a tutorial for vi
- vitutor is a tutorial for vim
- rm filename removes the normal file
filename
- Creating and deleting directories
- mkdir directory will make the directory file
directory
- rmdir directory removes the empty directory
directory
- Copying files
- cp filename newname copies the normal
file filename to newname
- cp -r directory newname copies the
directory directory and its contents to
newname
- Moving files
- mv filename directory moves
filename (normal or directory) into
directory
- mv filename newname moves
filename to newname
- Moving a file is the way to rename it.
- Controlling access
- Every file has user, group, other access
control
ls -l lists this information in the format
TRWXRWXRWX
- Normal files have read, write, execute
permission flags
- Directory files have read, write, axcess
permission flags
- chmod WOP filenames changes the
permission flags for the filenames
- W can be any combination of u, g,
o, a (a means ugo)
- O can be + to add permission, - to
remove permission
- P can be any combination of r, w,
x
Compiling C++
- A text editor (pico, vim, etc) is used to
create source code
- There are two compilers cxx and g++
- cxx filename.cpp -o
outputname will compile
filename.cpp to produce
outputname
- outputname will execute the program
Self assessments
Tutorial Questions
Exam style questions
- Briefly describe how timesharing was proposed.
- What was one of the first timesharing computers?
- Briefly describe the birth of the Unix operating system.
- Briefly describe how information is organised in the unix file system.
- What are the basic file system actions.
- What is the current directory?
- What is the main account directory?
- Explain what pathnames are.
- What are the possible characters that can be used in a pathname?
- True/false:
- Every file/directory has a unique relative pathname?
- Every file/directory has a unique absolute pathname?
- Pathnames are case-sensitive?
- Explain what the meaning of the pathname "/usr/local/bin/perl"
- What sequence of unix commands will:
- display a basic contents list of the current directory
- display a list showing access permissions
- display a list showing directories differently from files
- If the current directory contains a sub-directory named: "sub1" what
sequence of commands will:
- change the current directory to be sub1
- change the current directory to be the parent of sub1
- list the contents of sub1 (while in the parent directory)
- display the absolute pathname for the current directory
- change the current directory to be the main account directory
- What Unix command to performs each of the following
independent actions:
- display the file "verySmallFile.txt"
- display the file "tooLargeFile.txt"
- rename the file "theAnswer.cc" to "42.cc"
- move the file "theAnswer.cc" to the sub-directory "42"
- move the file "theAnswer.cc" to the sub-directory "42",
renaming it to "42.cc"
- create a new sub-directory "subdir1"
- delete the empty directory "emptyDir"
- From the current directory, what sequence of commands
perform the following tasks (don't change directories):
- create a sub-sub-directory "subdir2" inside "subdir1"
(neither directory exists)
- delete the directory "dir" which contains the file "data.txt"
- if the current directory contains the file
"theAnswer.txt", create two new sub-directories "42" and
"backups". Move "theAnswer.txt" inside "42". Copy
"theAnswer.txt" inside "backups" and rename it to
"theAnswer.bak"
- What are the meanings of the letters "a, u, g, o" in the
command chmod ?
- In the current directory, there is a file "shared.txt" and
a directory "private" which contains the file "data.txt". What
sequence of chmod commands will:
- make "shared.txt" readable and writable by any user
- make "private" readable by any user, but writable only by
the account owner
- make all files and directories under the current directory
group readable
- Is it dangerous to have the main account directory
writable by any user? What can happen?