WINDOWS COMMAND PROMPT

LESSON –
OTHER COMMANDS

 

separator-blank.png

 

GROUP WORK

 

STEP 0 – SETUP

 

·       In windows, unzip this file and copy its contents to the cmdWork folder that you created in the previous lesson.

 

·       Open the command prompt and navigate to the Lesson05Work directory which is inside the cmdWork directory.  This is where we will do our work for now.

 

STEP 1 – PROMPT

 

·       The prompt command allows you to change what is displayed in the prompt.  Try this:

         
prompt Yo

·       Try changing the prompt to something else.

STEP 2 – PROMPT /?

 

·       How can we change it back?  Try figuring it out by using:

         
prompt /?

·       Try a few of the suggested values such as $P with the prompt command.

STEP 3 – CLS

 

·       To clear the screen, try the following:

         
cls

 

STEP 4 – CONCEPT (USING & TO RUN TWO COMMANDS)

 

·       To run a command and then another command, you can use the following approach:

         
command1 & command2

·       For example, we can do the following:

         
dir a* & dir b*

·       Or this

     echo hi > fun.txt & type fun.txt

STEP 5 – FIND

 

·       In the Lesson05Work directory, go to the data directory.

·       The find command helps you search a text file for lines that contain a specific string.  Note that you cannot use wildcards in the string portion of the command.

·       Start by seeing what is in the nhl.txt file by using:

         
type nhl.txt

·       Try using the find command to see the lines that contain the string "Gretzky".

     find "Gretzky" nhl.txt

 

STEP 6 – MORE ON FIND

 

·       Try using find to figure out how many players named Alex appear in the file.  Try this:

         
find "Alex" nhl.txt

Notice that a line with Alexander is also included.

 

STEP 7 - MULTIPLE FINDS

 

·       Try the following:

 

                    find "Name" nhl.txt & find "Gretzky" nhl.txt & find "Lemieux" nhl.txt

Notice that each find command displays the filename at the top.  This can be annoying if you want the results of all three find commands to appear together.  We will see how to do this later.

 

STEP 8 – MORE

 

·       The more command is designed to display large amounts of data one screen at a time pausing for the user to read.  It is usually used with a pipe.

·      
Notice that when you use type nhl.txt that the outputted information is longer than the screen.  We can use more here.  Try it:

 

          more nhl.txt

 

STEP 9 – CONCEPT (PIPE)

 

·       We can transfer the output of one command and pass it as input to another command by using a pipe.  The symbol for pipe is the | symbol.

 

·       Piping allows us to string a few commands together on a single line.

 

STEP 10 - PIPE TYPE COMMAND TO MORE

 

·       We often do not know in advance if a command will lead to output that is too long for the screen.  So we can simply pipe its output to more.

 

·       Try the following:

 

                    type nhl.txt | more

 

STEP 11 - PIPE DIR COMMAND TO MORE

 

·       Now try the same with the dir command.

 

                    dir | more

 

·       Of course, the more command does nothing if the dir listing is small.  Maybe try this instead:

 

                    dir c:\windows | more

 

STEP 12 - CONCEPT (CLIPBOARD)

 

·       A computer’s clipboard is a temporary storage that is used when you copy (or cut) an item.  It allows for information to be pasted to other locations.

 

STEP 13 - PIPE A COMMAND TO CLIP

 

·       The clip command stores the information that it receives (via piping) to the clipboard.

·       Try the following:

 

          dir | clip

 

          And go to a program in windows and paste the information.

 

STEP 14 – CONCEPT (COMMANDS MAY DIFFER WHEN PIPING)

 

·       Some commands might work a little bit differently when working on piped information versus when working on files.

·       For example, the find command will output the file name of the file it is working on unless that content of the file was piped to it.

 

STEP 15 – PIPE TYPE COMMAND TO FIND

 

·       First, try the following:

     find "Phil" nhl.txt

 

·       Now, instead, try this:

     type nhl.txt | find "Phil"

 

Notice that this approach doesn’t involve getting the filename listed at the top.

STEP 16 – MULTIPLE FINDS WITHOUT THE FILENAME

 

·       Try the following:

type nhl.txt | find "Name" & type nhl.txt | find "Gretzky" & type nhl.txt | find "Lemieux"

 

Notice that it creates a nicely formatted output.  One that you could use to properly compare two records.

 

STEP 17 – FIND /C TO COUNT THE NUMBER OF MATCHING LINES

 

·       Instead of outputting eNowach line that matches a string, we can output simply the number of lines:

Try the following:

         
find "Mark" nhl.txt /C

 

·       And, to get the cleaner output, try the following:

         
type nhl.txt | find "Mark" /C

 

STEP 18 – FIND /V TO FIND LINES NOT CONTAINTING A STRING

 

·       First, let’s look at the content of harryPotter.txt by using:

     type harryPotter.txt

·       Now, let’s output each Harry Potter character that is a founder of one of the four houses by using the following:

         
find "Founder" harryPotter.txt

 

Again, if we wanted a cleaner output, we could use a pipe.

·       Now, let’s output every character that is not in Gryffindor by using:

         
find "Gryffindor" /V harryPotter.txt

 

STEP 19 – SORT

 

·       The sort command allows you to sort lines in a file.

·       First, view the content of the file fruit.txt by using:

     type fruit.txt

·       Now, sort the lines of fruit.txt by using:

     sort fruit.txt

 

STEP 20 – SORT STARTING AT A SPECIFIC CHARACTER NUMBER IN EACH LINE

 

·       Let’s examine the teachers.txt file using

     type teachers.txt

·       Let’s sort the file using

     sort teachers.txt

Notice that the sorting is based on the first initial.  We can change that.

·       Sort the teachers.txt file starting at character 4 of each line (the location where the last name begins) by using:

     sort teachers.txt /+4

 

STEP 21 – SORTING SOME OF THE LINES OF A FILE

 

·       We can use find to get lines that match a certain string and then pipe that information to sort that will then sort those lines.

·       For example, we can sort all characters from Gryffindor by using:

         
find "Gryffindor" harryPotter.txt | sort

 

 

 

OTHER POSSIBLE IDEAS

 

wc – Gets the number of words and characters in a file

fc – File compare

Sfc /scannow - system file checker

Ciper /E - encodes files based on your user account.  /D to decode.  Use only in a safe directory

Wmic product get name - lists are installed programs

Driverquery /FO list /v - Lists all drivers installed (Windows 10)

 

F keys are all shortcuts.  F7 (Fn + F7) gives a listing of all recent commands.

 

separator-blank.png