What is Command Line ?
Over many years I have had need to use windows command line.
In fact I still have DOS based programs running on lots of equipment I am responsible for maintaining
http://ss64.com/nt/
How to start command line,
- Launch The Command Prompt Using Search Or Cortana type cmd and select cmd.exe (or command prompt)from under programs
- Launch the Command Prompt using the Run window (press Win+R on your keyboard to open it). Then, type cmd or cmd.exe and press Enter
- If you are using Windows 7, open the Start Menu and go to All Programs -> Accessories. There you will find the Command Prompt shortcut.
- In Windows 10, open the Start Menu and go to All apps -> Windows System. There you will find the Command Prompt shortcut.
- Windows 8.1 and Windows 10 include a hidden menu for power users that can be accessed from the Desktop.
The quickest way to launch it is to press Win+X on your keyboard. The menu includes many useful shortcuts, including two shortcuts for the Command Prompt.
- open Windows Explorer (in Windows 7) or File Explorer (in Windows 8.1 & Windows 10).
Then, open the partition where Windows is installed and browse to Windows -> System32. click on cmd.exe
to change drive from your drive c to lets say your usb stick drive F (or whatever your new drive letter is)
you can't just cd to another drive
Redirection Commands and conditional processing
Using Redirection
> useage command > filename Redirect command output to a file
>> useage command >> filename APPEND into a file
Using Ampersand
& useage command1 & command2 - Cmd.exe runs the first command, and then the second command.
&& useage command1 && command2 - Cmd.exe runs the first command, and then the second command only if the first command completed successfully.
Using Pipe
| useage commandA | commandB Pipe the output from commandA into commandB
|| useage commandA || commandB Run commandA, if it fails then run commandB
Windows Environment Variables
Environment variables are mainly used within batch files. Variables have a percent sign on both sides: %ThisIsAVariable%
The variable name can include spaces, punctuation and mixed case: %_Another Ex.ample%
There are Standard (built-in) Environment Variables and paths which can be specified in command line
and to make this easy a user home directory can be shortened to %USERPROFILE% there are more examples at
http://ss64.com/nt/syntax-variables.html
Example of Command Line in Use
To search folder C:\users\ for .exe files
dir C:\users\*.exe /s /b | find ^"temp^" /v /i | findstr /e .exe > UserExecutablePaths.txt
dir /s Lists the files in the folder and also the ones in the subfolders recursively.
dir /b Lists the subfolders/files names in bare format.
find /v exclude "temp" string
find /i not case sensitive
findstr /e : Matches the pattern .exe if at the end of a line
greater than ">" outputs to file UserExecutablePaths.txt
Add Environment Variables
Add computer name to the file by using envirnmet variable %computername%
Use ampersand "&" to separate multiple commands on one command line
Output to file change the second greater than ">" from previous example to double ">>" so you concatenate the "&" output.
echo Computer Name = %computername% > UserExecutablePaths.txt & dir C:\users\*.exe /s /b | find ^"temp^" /v /i | findstr /e .exe >> UserExecutablePaths.txt
This example starts playing the test.wav using media soundplayer
while ($true)
{
(new-object Media.SoundPlayer "%USERPROFILE%\Documents\powershell\test.wav").play();
sleep -seconds (30*1)
}
Jump to Command Line and me on....
Jump to Ubuntu, Linux and me on....