Download presentation
Presentation is loading. Please wait.
Published byGeraldine Montgomery Modified over 9 years ago
1
Introduction to Programming Using C An Introduction to Operating Systems
2
2 Contents Operating Systems Files & Directories UNIX Commands
3
3 Operating Systems Computer hardware does nothing without instructions In the early days, one would press a button to have the computer load and execute your program This had disadvantages – You could only run one program at a time – A human had to press a button to start a program
4
4 Operating Systems This was a drag so they wrote a program to run continuously and – Automate the loading of programs – Let more than one program run at once – Support multiple users – Make hardware transparent so that all disk drives look alike even if made by different companies This program was called an operating system
5
5 Operating Systems A computer is like an onion – Application programs are at the outer layer – They talk to the operating system at the next level – The operating system talks to the hardware in the centre hardware
6
6 UNIX UNIX is an operating system written in the 1970s by AT&T It has become a standard on which many other operating systems are modelled We will be using a command-line interface to communicate with UNIX
7
7 Shells While an application can talk to the OS, how does a user talk to the OS Via a special application called a shell Shells fall into two broad categories – Command line shells Sh, csh, ksh – Graphical shells X Windows
8
8 Command Line Shells A command line shell is a program which – Lets you type commands – Conveys your instructions to the operating system – Displays results from your programs and the operating system Shells have their own simple command language which you use to tell them what to do
9
9 Files and Directories Everything you store in a computer is in a file Files are given a name and are usually stored on a hard disk Files are organized into directories A directory can contain – Any number of files – Other directories
10
10 Files and Directories Files and directories are organized into a tree like structure “/” is the root of the file system “/” is also used to specify a path through the file system / usretc home rob ipc144
11
11 Your Home Directory Every user is assigned a home directory This is a directory in which they can store their files Usually, a subdirectory is created for every course and subdirectories in each course for each assignment
12
12 Shells A shell is the program which communicates the user’s wishes to the operating system We will be using the Korn Shell This is a command-line interface Command line interfaces are programmable, making them useful for many tasks for which GUIs are poorly suited
13
13 Logging In You can contact the computer – Via a connected terminal – Over the internet via telnet – a remote terminal Putty – a secure connection which is encrypted Once connected you login with a – User name – password
14
14 Listing Files To see the files in your directory use the ls command This has variations, specifified with command line parameters – ls –alist all files, including hidden ones – ls –llong listing showing details
15
15 Working with Directories Directories and files are named with either a relative or absolute path – Relative paths specify a file relative to the current directory ipc144/as1/as1.c – Absolute paths give a complete path from the root of the file system and do not depend on the current directory /home/rob/ipc144/as1/as1.c
16
16 Working with Directories You can find out what directory you are in by typing – pwd To change the currect directory – cd – “.” is shorthand for the current directory – “..” is shorthand for the parent directory
17
17 Command Syntax Every command – Starts with a command name – Is followed by Options Filenames or other data passed to the command Optional input / output redirection
18
18 I/O Redirection Every command reads input from – Standard input And write output to – Standard output Normally, these are connected to – The keyboard – The terminal screen However, they can be redirected to files
19
19 I/O Redirection The “<“ sign tells a program to read from a file rather than the keyboard – cat < file1.txt – This causes the cat command to read from file1.txt The “>” sign redirects output to a file – cat > file2.txt – Causes the cat command to write its output to file2.txt
20
20 End Of File A file is simply a stream of bytes Every file has and end marker called End Of File Your programs can detect this When reading from a terminal, typing CTRL- D on a line by itself and pressing RETURN will send an End Of File character to your program
21
21 Shell Programming Shell commands can be saved in files and replayed at any time The shell maintains variables to make programming easier Common variables include – HOME-- your home directory – PATH-- directories searched for commands – PS1-- prompt
22
22 Shell Programming You can set a variable by simply assigning a value – Myvar=1 To see the value type – Echo $Myvar To see the values of all variables type – set
23
23 Basic UNIX Commands cat [ ] – Concatenates one or more files into a single file – Often used to display a file on screen – Also used to combine files cd [ ] – Changes the current working directory to the absolute or relative path specified – All relative paths are prefixed with the current directory
24
24 Basic UNIX Commands chmod – Every file has an owner and a set of permissions – You can allow a file to be Read (r) Written (w) Executed (x) – These operations can be performed by The owner (u) The group (g) Everyone outside the owner or his/her group (o) All users (a)
25
25 Basic UNIX Commands The permissisons are combined into a string of the form – [rwx]±[oug] To allow anyone to read a file – chmod a+r filename Restrict access to anyone but the owner – chmod ug-rwx filename
26
26 Basic UNIX Commands clear – Clears the screen cp – Copies one or more files to another file or directory – Can be used to copy files to a directory df – Shows the amount of free disk space
27
27 Basic UNIX Commands du [ ] – Reports the disk usage for a directory finger – Provides information about a user ln – Creates a link where two filenames point to the same file
28
28 Basic UNIX Commands lpr [-P printer] – Prints a series of files on a printer lpstat [-P printer] – Lists jobs queued for the printer ls [-al] – Lists files in a directory
29
29 Basic UNIX Commands man – Provides a manual page on the command mkdir – Creates one or more new directories more – Displays a file a screenful at a time Enter advances one line Space advances one page q quits
30
30 Basic UNIX Commands mv – Moves files rather than copying – Can be used to rename a file passwd – Allows you to change your password pwd – Displays the current directory name
31
31 Basic UNIX Commands quota – Displays how much disk space you can use rm – Removes one or more files rmdir – Removes a directory if it is empty set – Displays all shell variables
32
32 Basic UNIX Commands stty – Terminal settings who – Shows who is logged on
33
33 Editing UNIX has a variety of editors – vi Everyone loves to hate this one – nled Neat little editor – Pico Another editor
34
34 Compiling The C compiler is called cc – cc –o – Compiles one or more C source files into an executable output file – Output files do not have to end in.exe – Write errors to command line
35
35
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.