Transcript Slayt 1

Introduction to Unix:
Fundamental Commands
1
BİL101 E
Başar Öztayşi 2011
What You Will Learn
• The fundamental commands of the Unix
operating system.
• Everything told for Unix here is applicable to
the Linux operating system also.
2
BİL101 E
Başar Öztayşi 2011
What is Unix
• UNIX is a computer operating system, a control
program that works with users to
–run programs,
–manage resources, and
–communicate with other computer systems.
• Several people can use a UNIX computer at the same
time; hence UNIX is called a multi user system. Any
of these users can also run multiple programs at the
same time; hence UNIX is called multitasking.
3
BİL101 E
Başar Öztayşi 2011
Logging on to a UNIX machine
• Because UNIX is a multi user operating
system, you need to start by finding a terminal,
computer, or other way to access the system.
• Connect your terminal or PC to the UNIX
system until the point where you see a login
prompt(login:) on your screen. Use the phone
and modem to dial up the computer if you
need to.
4
BİL101 E
Başar Öztayşi 2011
Connecting a PC (MS-Windows) to
Unix System
• The machine that we are going to connect is
called hyperion.labs.itu.edu.tr
• Select Start → Run and type SshClient in the
empty box
• This will start the SSH program
5
BİL101 E
Başar Öztayşi 2011
• Choose Quick Connect, a
new window will come up to
the screen
• In the HostName section,
type ssh.itu.edu.tr
• In the UserName section,
enter your login name
• Leave other parts as their
default values.
6
BİL101 E
Başar Öztayşi 2011
• When you press Connectbutton, you will see a
password prompt.
• Enter your password exactly and press OK
button.
• Your login name and password are casesensitive.
7
BİL101 E
Başar Öztayşi 2011
8
BİL101 E
Başar Öztayşi 2011
• You are now logged into the computer and will have a prompt
that reflects the computer's name. For example, if you connect
to hyperion machine, the prompt looks like this:
[oztaysib@ssh ~]$
• Once you’ve successfully entered your account name and
password, you are shown some information about the system,
some news for users, and an indication of whether you have
electronic mail. The specifics will vary.
• At this point, you’re ready to enter your first UNIX command.
9
BİL101 E
Başar Öztayşi 2011
Shell Commands of UNIX
• Unix Commands
• When you first log into a unix system, you are
presented with something that looks like the following:
[oztaysib@ssh ~]
• That “something” is called a prompt. As its name
would suggest, it is prompting you to enter a
command.
• Every unix command is a sequence of letters, numbers
and characters. But there are no spaces.
10
BİL101 E
Başar Öztayşi 2011
• Unix is also case-sensitive. This means that cat and
Cat are different commands.
• The prompt is displayed by a special program called
the shell.
• Shells accept commands, and run those commands.
• They can also be programmed in their own language.
These programs are called “shellscripts”.
11
BİL101 E
Başar Öztayşi 2011
• There are two major types of shells in unix:
– Bourne shells
– C shells.
• Steven Bourne wrote the original unix shell sh, and
most shells since then end in the letters sh to indicate
they are extentionson the original idea
• Linux comes with a Bourne shell called bash written
by the Free Software Foundation.
• bash stands for Bourne Again Shell and is the default
shell to use running linux
12
BİL101 E
Başar Öztayşi 2011
• When you first login, the prompt is displayed
by bash, and you are running your first unix
program, the bash shell.
• As long as you are logged in, the bash shell
will constantly be running.
13
BİL101 E
Başar Öztayşi 2011
Storing information
• Unix provides files and directories.
• A directory is like a folder: it contains pieces of paper, or
files.
• A large folder can even hold other folders-directories can
be inside directories.
• In unix, the collection of directories and files is called the
file system. Initially, the file system consists of one
directory, called the “root” directory
• Inside “root” directory, there are more directories, and
inside those directories are files and yet more directories.
14
BİL101 E
Başar Öztayşi 2011
• Each file and each directory has a name.
• A short name for a file could be joe,
• while it’s “full name” would be /home/larry/joe. The full
name is usually called the path.
• The path can be divide into a sequence of directories.
• For example, here is how /home/larry/joe is read:
15
BİL101 E
Başar Öztayşi 2011
• A path could refer to either a directory or a
filename, so joe could be either.
• All the items before the short name must be
directories.
16
BİL101 E
Başar Öztayşi 2011
• To see linux commands press Tab key,
• If you want to learn commands beginning with
c you can write c then press Tab key
/home/larry# c
17
BİL101 E
Başar Öztayşi 2011
Obtaining help
• The man command displays reference pages for the
command you specify.
• The UNIX man pages (man is short for manual)
cover every command available.
• To search for a man page, enter man followed by the
name of the command to find .
[oztaysib@ssh ~]$ man ls
(press q to exit)
18
BİL101 E
Başar Öztayşi 2011
Obtaining Help
• To Exit press q
19
BİL101 E
Başar Öztayşi 2011
man ((obtaining help))
• There is also a keyword function in man.
• For example; –If you are interested in any commands that deal
with Postscript, the printer control language for Adobe
• Type man -k ps or man -k Postscript,
• you’ll get a listing of all commands, system calls, and other
documented parts of unix that have the word “ps” (or
“Postscript”) in their name or short description.
• This can be very useful when you’re looking for a tool to do
something, but you don’t know it’s name-or if it even exists!
20
BİL101 E
Başar Öztayşi 2011
LAB. EXTENSION
21
BİL101 E
Başar Öztayşi 2011
Application 3
• A. ls: “list directory contents”
– ls –al: “Show all and long listing”
– ls -F: Adds a slash after the name for directories, an asterisk
for executables, and an at sign (@) for linked files.
•
•
•
•
B. man: displays online manual pages
C. mkdir BIL101E: Creat a directory named BIL101E
D. cd BIL101E: change directory to BIL101E
E. touch: change file timestamps
– touch deneme.txt: creates the file if does not exist
22
BİL101 E
Başar Öztayşi 2011
Application 3
•
•
•
•
•
•
F. mkdir GECICI: Creat a directory named GECICI
G. cd GECICI: change directory to BIL101E
H. ls: list the directory content
I. cd ..: change directory to mother directory
J. cp deneme.txt GECICI: copy deneme.txt to GECICI directory
K. mv Deneme.txt GECICI: move Deneme.txt to GECICI
directory
• L. mv deneme.exe GECICI
• M. ls GECICI
• N. : rm remove deneme.txt in the GECICI directory
23
BİL101 E
Başar Öztayşi 2011
Application 3
• O. cd GECICI: go to GECICI directory
• P. rm Deneme.txt: remove the file in GECICI 8without declaring
the directory)
• Q. mkdir YOK: create a new directory with the name YOK
• R. rmdir YOK: remove the directory named YOK
• S. cd .. :Change directory
24
BİL101 E
Başar Öztayşi 2011
EDITORS: joe-pico-vi
• A4. pico myfile.txt [create file named myfile.txt]
– Bu benim ilke editör kullanısım
– (CTRL+ X) [close the file]
• A5. cat myfile.txt [displays the contents of a file.]
• A6. vi myfile.c
–
–
–
–
i
// Bu benim ikinci editor kullanısım
Shift-ZZ
cat myfile.c
• A7. gcc myfile.c – o myfile.exe compile the code and
create the exe file
25
BİL101 E
Başar Öztayşi 2011
-trees – chmod• A8. tree :list the content of directories in a tree-like format
• A9. ls –la : show all and long listing
• A10. permissions
•
-r-x-x-x
| filecount | user | group | size | date
1
aribas
user
102
23 May 1996
| filename with extension
myfile.c
•
•
•
•
•
Position 1 file type: d (directory) - (ordinary file) l (symbolic link)
Position 2-4 permissions for the owner: r (read), w (write) , x (execute)
Position 5-7 permissions for other users in the same group
Position 8-10 permissions for all other users
Read: 4 Write: 2 Execute : 1
•
•
•
•
A11. chmod 700 myfile.txt : all rights to the owner
A12. ls –la: show all and long listing
A13. chmod 744 myfile.txt: all rights to the owner, only read to others
A14. chmod 711 myfile.exe: all rights to the owner, only exec to others
26
BİL101 E
Başar Öztayşi 2011
-trees – chmod• A15. grep ‘Bu' myfile.c : searches the given file for lines
containing a match to the given strings or words
• A16. wc –l myfile.c : displays a count of lines in a file.
wc –w myfile.c : displays a count of words in a file.
• A17. spell myfile.c : Looks through a text file and reports any
words that it finds in the text file that are not in the dictionary.
• A18. cmp myfile.c myfile.txt: The cmp utility compares two
files of any type and writes the byte and line number at which
the first difference occurred is reported.
• A19. diff myfile.c myfile.txt : find the differences between
two files
27
BİL101 E
Başar Öztayşi 2011
• A20. tr a b translate specified characters into other characters
or to delete them.
• A21. gzip compress or expand files
• A22. tar xvf panda.tar Extract files from panda.tar.
• A23.?
• A24. ls i?u
• A25. ls –F > mylist.txt
• A26. !1 – pine / email
• A27. !2
28
BİL101 E
Başar Öztayşi 2011
Network – storage- system tools
• A28. ps –aux : displays information about a selection of the
active processes
• A29. du –kh : Summarize disk usage of each FILE in mb
• A30. df : Report how much free disk space is available
• A31. who: show who is logged on
• A32. uptime: tell how long the system has been running
• A33. whoami: user name associated with the current
effective user ID
• A34. where:
• A35. w: Show who is logged on and what they are doing
• A.36. pid: Retrieve process id
29
BİL101 E
Başar Öztayşi 2011
Network – storage- system tools
• A37. kill % terminate a process
• A38. kill -9 terminate a process based on Process ID
• A39. fg : Continues a stopped job by running it in the
foreground,
• A40. bg: Continues a stopped job in the background
• A41. ssh hyperion.labs.itu.edu.tr :OpenSSH SSH client
(remote login program)
• A42. finger : user information lookup program
30
BİL101 E
Başar Öztayşi 2011
• A43. bash : Bash is an sh-compatible command language
interpreter that executes commands read from the standard
input or from a file.
• A44. tcsh: It is a command language interpreter usable both as
an interactive login shell and a shell script command
processor.
• A45. sh: command language interpreter that executes
commands read from the standard input or from a file
• A.46. cat .profile
• A.47 cat bash.rc
– EKLER ; tail ; head ; scp
31
BİL101 E
Başar Öztayşi 2011