Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mostly MS Dos with some UNIX/LINUX

Similar presentations


Presentation on theme: "Mostly MS Dos with some UNIX/LINUX"— Presentation transcript:

1 Mostly MS Dos with some UNIX/LINUX
The Command Line Mostly MS Dos with some UNIX/LINUX Copyright © 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 © Curt Hill

3 Brief History First time sharing systems are in 1960s
Enter a command from a printing terminal Central CPU executes UNIX developed in early 1970s Command format is the name of any program followed by parameters DOS 1 adopts this approach Single user Syntax modifications Copyright © Curt Hill

4 Contrast Current Windows believes in two different styles of executables A GUI oriented one and a console oriented one 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 © Curt Hill

5 Shells The notion of a shell dates back to early versions of UNIX or before A shell is a command interpreter It gave an interactive means for a user to use the system UNIX allowed anyone to create their own shell, while Windows was less forthcoming in this respect On most previous versions of Windows this is the DOS command prompt – now it is PowerShell Copyright © Curt Hill

6 Shell Scripts If the shell can accept commands from a file instead of the console this is called a shell script UNIX has a command redirection feature that enabled this The > and < on the prompt A shell script is a full but simple programming language with variables, flow of control and other features we expect in programming languages Copyright © Curt Hill

7 The Console Often called the DOS box
Only interface DOS had Recently PowerShell became the default console 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 © Curt Hill

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

9 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 In Windows it is the program itself that determines the format of the parameter Copyright © Curt Hill

10 Programs The DOS box is actually cmd.exe in the Windows directory
PowerShell is powershell.exe UNIX/LINUX calls this thing a shell It has a variety of shells Consistent with the UNIX philosophy Whether a DOS box or UNIX shell they are all command interpreters In early versions they were only command interpreter Now the GUI part interprets some commands Copyright © Curt Hill

11 File specification How do we specify a file? In DOS In UNIX
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 © Curt Hill

12 File name Originally 1-8 characters Name is composed of
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 © Curt Hill

13 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 .ps1 – PowerShell script Copyright © Curt Hill

14 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 © Curt Hill

15 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 © Curt Hill

16 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 © Curt Hill

17 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 © Curt Hill

18 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 © Curt Hill

19 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 © Curt Hill

20 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 © Curt Hill

21 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 © Curt Hill

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

23 Advanced Copyright © Curt Hill

24 Environment Variables
Copyright © Curt Hill

25 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 © Curt Hill

26 Search for 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 © Curt Hill

27 Search 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 There used to be a .com format as well 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 © Curt Hill

28 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 © Curt Hill

29 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 © Curt Hill

30 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 © Curt Hill

31 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 Copyright © Curt Hill

32 Parameters The typical parameter of a command is a file
Certain commands may take wildcards The internal commands usually have options started with / The option /? will give a page showing the format and options Non MS programs may have /h or /help instead Next screen shows this for dir Copyright © Curt Hill

33 Dir options Copyright © Curt Hill

34 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 Copyright © Curt Hill

35 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 © Curt Hill

36 DEL (ERASE) Removes the file from the disk Accepts wildcards DEL *.bak
UNIX uses rm with different options Copyright © Curt Hill

37 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 Copyright © Curt Hill

38 The Screen The DOS screen emulates the printing terminal or glass teletype It displays the lines you typed in as well as the responses that the commands provided Since it is in its own window we can use the scrollbar and see that which happened before The CLS command will clear it Copyright © Curt Hill

39 Cursor Keys We may use the cursor keys to modify the current command
The left and right keys allows moving in the current command The delete and backspace change Insert toggles whether characters are inserted or overwritten Using the up and down key moves us through the list of commands we have used Makes it easier to reuse the typing of a previous command Copyright © Curt Hill

40 Help command DOS still retains the HELP command which will show the commands that exist Following the HELP you may also specify the command that you wish to know more about, such as: HELP COPY Copyright © Curt Hill

41 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 © Curt Hill

42 Addendum: Long file names
The original FAT file system believed only in the 8.3 name Later, long file names were allowed These also allowed blanks as a valid character There was an algorithm that would convert that long name into an 8.3 name This produced two versions of the name that co-existed The 8.3 name always had a tilde ~ in it Copyright © Curt Hill

43 Blanks The command processor has been modified to handle the blanks in a name A long file name may be enclosed in double quotes Then even if it has blanks it can be processed Another trick that helped is for the CD command A tab will fill in one of the available directories Copyright © Curt Hill

44 Conclusion We now have the basics
Next we learn about redirection, pipes and standard files Then batch files briefly We restart with PowerShell Copyright © Curt Hill


Download ppt "Mostly MS Dos with some UNIX/LINUX"

Similar presentations


Ads by Google