Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Command Line Mostly MS Dos with some UNIX/LINUX Copyright © 2003-2015 Curt Hill.

Similar presentations


Presentation on theme: "The Command Line Mostly MS Dos with some UNIX/LINUX Copyright © 2003-2015 Curt Hill."— Presentation transcript:

1 The Command Line Mostly MS Dos with some UNIX/LINUX Copyright © 2003-2015 Curt Hill

2 Introduction The command line interface is a modified time-sharing command interface –Predates GUIs Still important for sophisticated professionals such as Software Engineers Microsoft has been trying to remove it from Windows since before XP Much of what you have seen hides the command line stuff Copyright © 2003-2015 Curt Hill

3 Contrast Windows believes in two different styles of executables –A GUI oriented one and a console oriented on The GUI executable registers its controls and event handlers as its first order of business –By default it does not have a console A console executable does have a console –It immediately starts to do the work involved Copyright © 2003-2015 Curt Hill

4 The Console Often called the DOS box –Only interface DOS had Paradigm is that of a printing terminal or glass teletype –Sequence of lines produced by program and user Minimal editing of the line –Recall previous typed line and backspace Copyright © 2003-2015 Curt Hill

5 Command sequence Machine gives a prompt –Usually a C:...> with blinking cursor You answer with Command and If the command is valid it is executed When command is done go back to prompt Copyright © 2003-2015 Curt Hill

6 Command format A command has this format –CMD parameters and files A command must be properly spelled A parameter is some extra info to the command –DOS standard starts with a slash (/) –UNIX standard starts with a dash (-) –Most are optional It is the program itself that determines the format of the parameter Copyright © 2003-2015 Curt Hill

7 File specification How do we specify a file? –Files have several pieces for their name In DOS –File name –File extension –File directory In UNIX –The extension is just part of the name –A dot is an ordinary character Copyright © 2003-2015 Curt Hill

8 File name Originally 1-8 characters –Now they may be much larger Name is composed of –Letters –Digits –Specials –Only characters that have special meaning in DOS may not be used Name should identify the particular project UNIX is a little more restrictive Copyright © 2003-2015 Curt Hill

9 File type or extension Originally 0-3 characters –Now may be more Separated by a dot from name Used to describe the kind of stuff in the file Predefined extensions –.exe - program –.bmp – bitmap picture –.bat - DOS batch file A batch file will be discussed later Copyright © 2003-2015 Curt Hill

10 File Directory Combination of the disk letter and subdirectory In Windows/DOS disk is a letter followed by a colon –In UNIX disk are represented by load points that are named not lettered Directories and subdirectories are delimited by \ in DOS and / in UNIX –These may be discussed in a subsequent presentation Copyright © 2003-2015 Curt Hill

11 Defaults By default if subdirectory is not specified the current disk and directory are used These may be shown in the prompt –The form of the prompt may be set by the user Extension –Certain programs require certain extensions –Each program may assume an extension or not Copyright © 2003-2015 Curt Hill

12 Wildcards Wildcards are ways to specify a whole group of files at once because of similarity of name * - matches as many characters as possible –No characters need follow it until a. ? - matches one and only one character Wildcards are often interpreted by the program so usage varies Copyright © 2003-2015 Curt Hill

13 The C/C++ main function The standard main function looks like this: int main(int argc, char *argv[]) The initial int is the return value Argc is a count of command line parameters Argv is an array of character strings –The actual command line parameters The program needs to interpret these as it sees fit Copyright © 2003-2015 Curt Hill

14 Parsing the command Def: to parse is to understand the form and meaning of communication or describe the form, function and relationships of a sentence How does DOS determine what to do with the command? Lets look Copyright © 2003-2015 Curt Hill

15 Executable Location Where can an executable be and be found in the command prompt? You would think that executables must be the Windows directory or one of the Program Files directories This is partially but not fully true Executables must be on the Path The Path is an environment variable Copyright © 2003-2015 Curt Hill

16 Environment Variables A set of name value pairs that affect how things operate Both Windows and UNIX have the concept Both systems have a TEMP variable which identifies a directory where a program may create temporary files Both also have the PATH variable Copyright © 2003-2015 Curt Hill

17 The Path The Path environment variable is a string of directory names When a command needs an executable the Path directories are searched –If there are multiple files of the same name, the first one found is used Windows has two paths –A global one for all users –A local one for each user –The two are merged Copyright © 2003-2015 Curt Hill

18 Finding the Path Like all good Windows options there are multiple ways to examine or set Control Panel / System Advanced System Settings Copyright © 2003-2015 Curt Hill

19 Advanced Copyright © 2003-2015 Curt Hill

20 Environment Variables Copyright © 2003-2015 Curt Hill

21 Command Interpretation Suppose that at the prompt the command: XYZ /z abc.def is entered – what happens? The first word is the command name –This may be prefixed by the disk, subdirectory etc. –xyz is assumed to be name of command and /z and abc.def is passed to the command for inspection Copyright © 2003-2015 Curt Hill

22 Searching for the command 1 First the internal commands are searched for this command –The internal commands are in the command processor –They do not have file representations –They include dir, type, ren, del, copy, etc If it is found then it is executed, otherwise the search continues Copyright © 2003-2015 Curt Hill

23 Searching 2 Next we look in the current directory –There are two extensions that can be executed:.EXE.BAT –They will be searched in that order: first xyz.exe and finally xyz.bat If they are not found there, then the path is checked –The order of the directories in the path command is then the order they will be searched Copyright © 2003-2015 Curt Hill

24 Path searches Like in the current directory, the first directory on the path is searched for xyz.exe and then xyz.bat Only if it is not found do we go to the second and subsequent directories If all the directories are searched and the command is not found, then we declare that this is an unknown file or command Copyright © 2003-2015 Curt Hill

25 Advantages The OS does not distinguish between its own external commands and foreign commands Internal commands have an advantage over other commands However external commands are just files like any other If we want to redefine we can If we want to write a new kind of command that makes life easier all we have to do is put it on the path Copyright © 2003-2015 Curt Hill

26 Commands We next want to consider various commands that may be useful These are typically file manipulation command Any executable can be used –If it generates a window it may still be started from the command line –Windows distinguishes between GUI and non-GUI executables Copyright © 2003-2015 Curt Hill

27 DIR Short for directory Displays the files present in the local Command alone shows all files in current directory You may also use file names and wild cards DIR is an internal command UNIX used ls with different options

28 COPY Make an identical copy of a file COPY source destination COPY a.dat b.dat –Make a copy of a.dat –Same disk, directory, etc –Retains same date as the a.dat UNIX uses cp with different options

29 Copy Again Accepts wildcards in source file and matching in destination COPY must give it a new name or copy it elsewhere, since a directory can only have 1 identically named item Concatenation of files is allowed using + between file specs for source –COPY b.dat+c.dat all.dat Copyright © 2003-2015 Curt Hill

30 DEL (ERASE) Removes the file from the disk Accepts wildcards DEL *.bak UNIX uses rm with different options

31 RENAME Gives a new name May abbreviate to REN May use wildcards UNIX uses mv which moves rather than renames A rename is move to same location with different name

32 CLS Clear the screen Copyright © 2003-2015 Curt Hill

33 Directory Commands Cd or chdir changes the current directory Md or mkdir creates a new directory –Rd or rmdir destroys The directory name follows the command Two specials –Single dot refers to the current directory –Two dots refers the ancestral Copyright © 2003-2015 Curt Hill

34 Conclusion We now have the basics Next we learn about redirection, pipes and standard files Then batch files


Download ppt "The Command Line Mostly MS Dos with some UNIX/LINUX Copyright © 2003-2015 Curt Hill."

Similar presentations


Ads by Google