Basic
UNIX Commands
Content
¡¤ Unix account
¡¤
Logging in Unix server
¡¤
Directory operations
¡¤
File operations
¡¤
Other useful commands
The main
server for graduate students and research is flame. This is a multi-user UNIX
server that can be used for doing assignments, checking email, and hosting a
web page. Every student who takes a computer science class automatically
receives a Unix account. If you are a graduate
student, you will receive an account on flame.cs.dal.ca. You may also login the
undergraduate server torch (torch.cs.dal.ca) using the same
username. The initial password is the user's student ID (Banner) number. (Don't forget
that Unix system is case sensitive, so ¡°B¡± is not same
as ¡°b¡± in this system)
All users
with a Unix Account are also entitled to a
Windows Account. Windows accounts are administered by the Novell file server
called Skywalker (csskywalker.cs.dal.ca). New
Novell accounts have the same username as their corresponding Unix account. The initial password is the user's student ID
(Banner) number.
Now you can
use your username and password to login graduate computers.
Back to top
You can log in to flame.cs.dal.ca by either sitting at a Sun workstation
or by using an ssh program
such as putty to log into torch.cs.dal.ca.
When using a Sun workstation:
1. Type your
username to the system login prompt.
2. Type your
password to the system password prompt.
When
using putty:
1. Login a
Windows computer with your Windows account username and password.
2. Start up
Putty, which is a program installed on all Windows computers in the Computer
Science building.
3. Enter the host
name of the server in the Host Name field. eg. flame.cs.dal.ca
4. Click on the SSH
radio button
5. Click the Open
button. If this is the first time you connect to this server you will be asked
to store the server's key fingerprint. Click yes to save the key and continue.
Note: If the connection has been listed in the session
list, it means that this configuration has already been saved. Then you can
skip step 3~5, select the connection name from the session list directly and
click the Load button. Then click the Open button to establish the connection.

6.
Type
your username to the login prompt.
7.
Type
your password to the system password prompt.
Back to top
Ø Listing files
and directories
ls
Command Description: list the
contents of your current working directory
Ø Create a new
directory
mkdir newdirectory
Command Description: make a new
subdirectory in your current directory. For example, when you
type:
mkdir dir1
A new subdirectory called ¡°dir1¡±
is created in your current working directory.
Ø Change to
specified
directory
cd directory
Command Description: change the current working directory to
¡®directory¡¯. The specified directory path ¡®directory¡¯ must exist. For example,
when you type:
cd
dir1
the
directory ¡°dir1¡± will become your current directory.
and
cd ..
will take you one directory up the directory
hierarchy.
Ø Copy
directory
copy ¨Cr directory1
directory2
Command Description: copy the directory1 and its contents to
directory2. The directory1 will be a subdirectory of directory2 after this
operation.
Ø Remove a empty directory
rmdir directoryname
Command Description: remove the directory. This directory must be empty first, that is, no file exists in this
directory.
Ø Remove a
non-empty directory
rm ¨Cr directoryname
Command Description: remove the
directory as well as all its contents.
Ø Show current
directory pathname
pwd
Command Description: lists your current location with respect to
your root directory
Back to top
Ø copy file to another filename
cp sourcefile targetfile
Command Description: Copy
the source file to a new file (target file). The source file must be a current
file, and the target file might be a new file name or current file for over- writing.
Both source and target can include directory paths.
Ø
move
file to directory/rename file
mv sourcefile
newfilename
Command Description: rename the source file by
giving it a new file name.
mv sourcefile
directoryname
Command
Description: move the source file from original place
to another directory. This command has the effect of moving rather than copying
the file, so you end up with only one file rather than two.
Ø
remove
/delete file
rm filename
Command Description: remove/delete the file. The file
name can include a directory path.
Ø
Display
file content
cat filename
Command Description: display the contents of the
file on the screen. If the contents of the file are longer than the size of the
window, they will scroll past screen so that part of them may be unreadable.
less filename
Command Description: display the contents of a
file on the screen one page at a time. Press ¡°space¡±
on keyboard if you want to see another page,
type ¡°q¡±
if you want to quit reading.
Back to top
Ø
Change
access permission
chmod n1n2n3 filename/directoryname
Command Description: change
the permissions of the file/directory (only the owner of this file/directory
can use this command to change its access permissions.
Where n1, n2, n3 are numbers ranging from 0 to 7:
n1 is a number
that represents access permissions for the owner
n2 is a number
that represents permissions for the group, where group is defined by the host
administrator (e.g. all students, all grad students etc.)
n3 is a number
that represents permissions for the others.
n1, n2, and n3 can be calculated as
follows:
Each file/directory has three types
of access properties:
¡¤
r, indicates read permission. For a file, it means the permission to read
and copy the file. For a directory, it means the permission to list files in
this directory
¡¤
w, indicates write permission. For a file, it means the permission to
change a file. For a directory, it means the permission to delete files from
this directory or move files into it
¡¤
x, indicates execution permission. For a file, it means the permission to execute
a file. For a directory, it means the right to access files in the directory
(you can read files in the directory provided you have read permission on the
individual files).
Thus for a file/directory, each field (owner, group, others) may have a
total of three properties associated with this field and each property has a
numerical value:
¡¤
Read (4)
¡¤
Write (2)
¡¤
Execute (1)
For example, if you want to give yourself Read, Write and Execution
permission to a file, called 'sample.txt', give the group members Read, and
Execution permission, but deny any access to others. Here n1, n2, n3 can be
calculated as:
n1
is calculated for owner: Read(4) + Write (2) + Execute(1) = 7;
n2
is calculated for group members: Read(4) + Execute(1) = 5;
n3
should be zero since you do not give any permission of this file to others;
So we type
chmod 750
sample.txt
to change the access permission of this file.
Ø
Editing
There are several text editors like vi, pico, emacs. Here we use pico as an example.
pico filename
Command
Description: start pico vi to edit the text file. If no filename is provided,
the command will start pico with a new file.
Commands for
this editor are across the bottom of the window. The "^" indicates
the "ctrl" key on keyboard. For example: the command ¡®^X¡¯ implies
pressing "ctrl" and the character ¡®X¡¯ at the same time. Here are
detail descriptions of some useful commands in pico:
¡¤
^G
display the help text.
¡¤
^R
insert external file at the cursor position.
¡¤ ^O
write buffer to a file and save it. If no filename is
provided when pico starts, a prompt will appear on
screen. Type the filename under the prompt.
¡¤
^X
quit pico and save buffer.
¡¤
^W
search string in the text.
¡¤
^
^
mark the current cursor position as the beginning of selected text.
¡¤
^K
cut the selected text (from the marked beginning of the text to the current
cursor position.)
¡¤
^U
paste the cut text to the current cursor position.
¡¤
^V
move forward a page of the text.
¡¤
^Y
move backward a page of the text.
¡¤
^A
move to the beginning of the current line.
¡¤
^E
move to the end of the current line.
Ø
Get
online help
Man command
Command Description: get on-line manual of this
command. The manual pages tell you which options a particular command can take,
and how each option modifies the behaviour of the
command.
whatis
command
Command Description: gives a one-line
description of the command, but omits any information about options etc
You can find
more Unix commands here
Back to top
last revised: July 2004