Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to UNIX and Linux.  Written by Dennis Ritchie and Ken Thomsom at Bell Labs in 1969  Initially written in assembly language and a high-level.

Similar presentations


Presentation on theme: "Introduction to UNIX and Linux.  Written by Dennis Ritchie and Ken Thomsom at Bell Labs in 1969  Initially written in assembly language and a high-level."— Presentation transcript:

1 Introduction to UNIX and Linux

2  Written by Dennis Ritchie and Ken Thomsom at Bell Labs in 1969  Initially written in assembly language and a high-level language called B. Later converted from B to C language.  Linux written by Linus Torvalds (an undergraduate student at the Univ. of Helsinki, Finland) in 1991.  IEEE developed a standard for UNIX, called POSIX, that most versions of UNIX now support.  Most popular operating systems  Internet runs on UNIX and Linux 2

3 3 UNIX is basically a Simple Operating System But YOU have to be a GENIUS to understand the Simplicity Dennis Ritchie

4  UNIX has a hierarchical file system structure consisting of a root directory with other directories and files hanging under it  In a command-line user interface, typed commands are used to navigate the system  Directories and files are specified by pathnames speicfying the location of the file  cmp320/assignments/assign1.c  /home/students/courses 4

5 5

6 6 faculty aliasifzia personalcourses cmp320ICS370 … … … …

7 /The root directory is the directory that contains all other directories. When a directory structure is displayed as a tree, the root directory is at the top. /binThis directory holds binary executable files that are essential for correct operation of the system /bootThis directory includes essential system boot files including the kernel image. 7

8 /devThis directory contains the devices available to on the machine /etcLinux uses this directory to store system configuration files /homeThis is where every user on a Linux system has a personal directory /libShared libraries and kernel modules are stored in this directory 8

9 /rootThe home directory for the superuser /sbinUtilities used for system administration (halt, ifconfig, fdisk, etc.) are stored in this directory /tmpUsed for storing temporary files. Similar to C:\Windows\Temp. 9

10 /usrTypically a shareable, read-only directory. Contains user applications and supporting files for those applications. /varThis directory contains variable data files such as logs (/var/log), mail (/var/mail), and spools (/var/spool) among other things. 10

11 11 A shell command can be internal/built-in or External The code to execute an internal command is part of the shell process, e.g., cd, pwd. The code to process an external command resides in a file in the form of a binary executable program file or a shell script, e.g.ls, mkdir. The general syntax of a shell command is command [option(s)] [argument(s)] To get the help against the use of a command, type man command

12 Browsing the File Hierarchy  lsDisplay contents of a directory  cdChange directory  pwdPrint working directory  mkdirCreate directory  rmdirRemove directory  cpCopy file  mvMove file  rmRemove file 12

13 Browsing the File Hierarchy ls (list) The ls command lists the contents of your current working directory. % ls (short for list) Ls does not show those files whose name s not begin with a dot (.) Files beginning with a dot (.) are known as hidden files and usually contain important program configuration information. To list all files in your home directory including those whose names begin with a dot, type % ls -a 13

14 Browsing the File Hierarchy mkdir (make directory) % mkdir unixstuff cd (change directory) To change to the directory you have just made, type % cd unixstuff mkdir ~/courses/OS/programs Create the ‘programs’ directory in your ~/courses/OS directory (.. ) means the parent of the current directory, so typing % cd.. will take you one directory up the hierarchy (back to your home directory). Typing cd / will take you to the root. Current working directory (.) Note: typing cd with no argument always returns you to your home directory. This is very useful if you are lost in the file system. 14

15 Browsing the File Hierarchy ~ (your home directory) Home directories can also be referred to by the tilde ~ character. It can be used to specify paths starting at your home directory. So typing % ls ~/unixstuff will list the contents of your unixstuff directory, no matter where you currently are in the file system. pwd (print working directory) Pathnames enable you to work out where you are in relation to the whole file-system. % pwd The full pathname of your current directory will be displayed. 15

16 Important Shell Commands cp (copy) cp file1 file2 makes a copy of file1 in the current working directory and calls it file2 mv (move) mv file1 file2 moves (or renames) file1 to file2 This has the effect of moving rather than copying the file. It can also be used to rename a file, by moving the file to the same directory, but giving it a different name. rm (remove), rmdir (remove directory) To delete (remove) a file, use the rm command. You can use the rmdir command to remove a directory (make sure it is empty first). 16

17 17 CommandDescription datePrints or sets the system date and time cal Displays the calendar for a specified month or a year whoami, who,User Information look up programs PasswdUsed to change the user password man [-k]Displays online documentation clearClear the terminal screen logout/exit/^D

18 vi / vim Editor History: Vim is a text editor released by Bram Moolenaar in 1991 for the Amiga computer. The name "Vim" is an acronym for "Vi IMproved“ because Vim was created as an extended version of the vi editor, with many additional features designed to be helpful in editing program source code. Introduction: Vim editor is very useful for editing programs and other plain ASCII files. All commands are given with normal keyboard characters. Vim is case sensitive. 18

19 vi / vim Editor History: Vim is a text editor released by Bram Moolenaar in 1991 for the Amiga computer. The name "Vim" is an acronym for "Vi IMproved“ because Vim was created as an extended version of the vi editor, with many additional features designed to be helpful in editing program source code. Introduction: Vim editor is very useful for editing programs and other plain ASCII files. All commands are given with normal keyboard characters. Vim is case sensitive. 19

20 vi / vim Editor Opening / Creating a File $vim practice The vim editor has three modes: 1. Command/Normal mode: This is the default mode, whenever you starts vim, the vim starts in this mode. This mode is used to give commands to vim, eg. save file, copy/paste/delete text, quit etc. You can switch to this mode by pressing the ESC key. 2. Insert mode: In this mode text is written/inserted in the file. One can enter insert mode by pressing "i", "I", "a", "A", "o", or "O". 3. Execute mode / Last line mode: From command mode you can enter this mode by typing ":" which puts the command line entry at the foot of the screen. 20

21 vi / vim Editor Editing a File Press i (move command mode to insertion mode) Exiting the Editor Press Esc. Followed by: :wq Write to file and quit :eq Exit without saving :w write(save) changes without quitting :eAbandon changes since last save 21

22 Writing a C program $ vi prog1.c Press i to move command mode to insertion mode Type the following program. #include int main(){ printf(“Hello World \n”); } Press Esc. Followed by :wq to save the file and exiting from the editor. 22

23 Compiling and Running C program Use any editor to type your program and then to compile use gcc compiler: $ gcc prog1.c This will create an executable file a.out in the pwd. Now to execute the file $./a.out If you just type $ a.out, it will say a.out not found. So either use./ before the exe name Once you compile another program in the same directory, the executable name is again a.out, which will overwrite the previous executable file. To over come this use –o flag when compiling your source file. $ gcc prog1.c –o prog1 Now this will create an executable file with the name as the second argument i.e., prog1 in this case. To execute the file give following command. $./prog1 23


Download ppt "Introduction to UNIX and Linux.  Written by Dennis Ritchie and Ken Thomsom at Bell Labs in 1969  Initially written in assembly language and a high-level."

Similar presentations


Ads by Google