In Windows, if you do not want to use Cygwin Terminal, you can also use the Windows Command Prompt. To launch this program, type cmd in the Search Box. (Command Prompt also works, but cmd is much shorter). This author would suggest you right-click on the application and pin it to the task bar:
When you launch the Command Prompt, you will notice the Microsoft notification at the top together with a copyright, and then you see the current working directory followed by a greater-than symbol prompting you for input:
To get a directory listing of all sub-directories of the current working directory together with any files in the current working, use the dir command:
dwharder@CHURCHILL ~ C:\Users\dwharder>dir Volume in drive C is OSDisk Volume Serial Number is 5415-E708 Directory of C:\Users\dwharder 2019-05-21 05:32 PM <DIR> . 2019-05-21 05:32 PM <DIR> .. 2019-05-21 05:33 PM <DIR> .eclipse 2019-05-17 03:44 PM <DIR> 3D Objects 2019-05-17 03:44 PM <DIR> Contacts 2019-05-28 05:03 PM <DIR> Desktop 2019-05-21 02:04 PM <DIR> Digital Signature 2019-05-21 01:27 PM <DIR> Documents 2019-05-28 04:09 PM <DIR> Downloads 2019-05-23 05:34 PM <DIR> eclipse 2019-05-28 02:42 PM <DIR> eclipse-workspace 2019-05-17 03:44 PM <DIR> Favorites 2019-05-17 03:44 PM <DIR> Links 2019-05-17 03:44 PM <DIR> Music 2019-05-18 03:47 PM <DIR> OneDrive 2019-05-17 03:46 PM <DIR> Pictures 2019-05-17 03:44 PM <DIR> Saved Games 2019-05-17 03:44 PM <DIR> Searches 2019-05-17 03:44 PM <DIR> Videos 0 File(s) 0 bytes 19 Dir(s) 404,651,388,928 bytes free
As you can see, there is already the eclipse and eclipse-workspace sub-directories, so we can change to the workspace sub-directory by using the change directory command cd:
C:\Users\dwharder>cd eclipse-workspace C:\Users\dwharder\eclipse-workspace>
If you want to change to a parent directory, use cd .., where .. is always an alias for the current working directory's parent directory.
C:\Users\dwharder\eclipse-workspace>cd .. C:\Users\dwharder>cd .. C:\Users>cd .. C:\Users>dir Volume in drive C is OSDisk Volume Serial Number is 5415-E708 Directory of C:\Users 2019-05-21 12:06 PM <DIR> . 2019-05-21 12:06 PM <DIR> .. 2019-05-17 11:44 AM <DIR> Administrator 2019-05-21 05:32 PM <DIR> dwharder 2019-05-21 12:11 PM <DIR> ece 2019-05-21 12:06 PM <DIR> pc-admin 2019-05-17 11:40 AM <DIR> Public 0 File(s) 0 bytes 7 Dir(s) 404,650,082,304 bytes free
To navigate back down, there are some short-cuts that can be used. For example, if you now start typing the first letter of your username in Windows, such as
C:\Users>cd dw
and then press the Tab key, it will find all files or directories that start with those letters and by repeatedly pressing the Tab key, you can cycle through them until you find the one you want:
C:\Users>cd dwharder
Next, type a backslash and ec:
C:\Users>cd dwharder\ec
and again press Tab. It will now cycle through eclipse and eclipse-workspace. Choose the latter.
C:\Users>cd dwharder\eclipse-workspace C:\Users\dwharder\eclipse-workspace>dir Volume in drive C is OSDisk Volume Serial Number is 5415-E708 Directory of C:\Users\dwharder\eclipse-workspace 2019-05-28 02:42 PM <DIR> . 2019-05-28 02:42 PM <DIR> .. 2019-05-21 05:32 PM <DIR> .metadata 2019-05-28 03:21 PM <DIR> Project 0 0 File(s) 0 bytes 16 Dir(s) 404,648,574,976 bytes free
We can change into the project directory:
C:\Users\dwharder\eclipse-workspace>cd P
and press the Tab key. You will now see
C:\Users\dwharder\eclipse-workspace>cd "Project 0"
The directory name is in double quotes because this tells the prompt that the space is part of the name.
C:\Users\dwharder\eclipse-workspace\Project 0>dir Volume in drive C is OSDisk Volume Serial Number is 5415-E708 Directory of C:\Users\dwharder\eclipse-workspace\Project 0 2019-05-28 05:31 PM <DIR> . 2019-05-28 05:31 PM <DIR> .. 2019-05-21 06:04 PM 12,640 .cproject 2019-05-21 06:04 PM 838 .project 2019-05-21 06:04 PM <DIR> .settings 2019-05-21 06:17 PM <DIR> Debug 2019-05-21 06:16 PM 176 main.cpp 3 File(s) 13,654 bytes 4 Dir(s) 404,648,267,776 bytes free
You will see your source file main.cpp and other files and directories. You can ignore the rest for now.
and pressing the Tab key:
dwharder@CHURCHILL /cygdrive/c/Users/dwharder/eclipse-workspace/ $ cd Project\ 0/
The \ that appears in front of the space indicates that the space is part of the name of directory. The backspace is the escape character in Cygwin Terminal (we will discuss escape characters in class when we describe strings). If you do not have spaces in your project names you will not ever have to deal with escape characters while using the Cygwin Terminal.
If you do a directory listing, you will see that your source file is there, but Eclipse also created a Debug directory:
dwharder@CHURCHILL /cygdrive/c/Users/dwharder/eclipse-workspace/Project 0 $ ls Debug main.cpp
We will ignore the debug directory and look at compiling the source file. The compiler is a program that takes a source file as an argument and compiles that source file into an executable.
dwharder@CHURCHILL /cygdrive/c/Users/dwharder/eclipse-workspace/Project 0 $ g++ main.cpp dwharder@CHURCHILL /cygdrive/c/Users/dwharder/eclipse-workspace/Project 0 $ ls a.exe Debug main.cpp
The default name of the executable is a.exe. You can change the name by using the output option -o:
dwharder@CHURCHILL /cygdrive/c/Users/dwharder/eclipse-workspace/Project 0 $ g++ -o main.exe main.cpp dwharder@CHURCHILL /cygdrive/c/Users/dwharder/eclipse-workspace/Project 0 $ ls a.exe Debug main.cpp main.exe
To delete a file, you can either to back into Windows and remove the file using the File Explorer application, or you can use the remove command:
dwharder@CHURCHILL /cygdrive/c/Users/dwharder/eclipse-workspace/Project 0 $ rm a.exe dwharder@CHURCHILL /cygdrive/c/Users/dwharder/eclipse-workspace/Project 0 $ ls Debug main.cpp main.exe
Okay, now let's run this executable file:
dwharder@CHURCHILL /cygdrive/c/Users/dwharder/eclipse-workspace/Project 0 $ main.exe -bash: main.exe: command not found
But the file is there!? You may be wondering why it is not found, especially if you are already familiar with Window's Command Prompt.
You may recall that when you installed Cygwin, you had to update the Path environment variable. There is a similar PATH environment variable in Unix:
dwharder@CHURCHILL /cygdrive/c/Users/dwharder/eclipse-workspace/Project 0 $ echo $PATH /usr/local/bin:/usr/bin:/cygdrive/c/Program Files (x86)/Common Files/O racle/Java/javapath:/cygdrive/c/windows/system32:/cygdrive/c/windows:/ cygdrive/c/windows/System32/Wbem:/cygdrive/c/windows/System32/WindowsP owerShell/v1.0:/cygdrive/c/windows/System32/OpenSSH:/cygdrive/c/Progra m Files/MiKTeX 2.9/miktex/bin/x64:/cygdrive/c/Program Files/PuTTY:/cyg drive/c/Program Files/MATLAB/R2019a/runtime/win64:/cygdrive/c/Program Files/MATLAB/R2019a/bin:/cygdrive/c/Cygwin64/bin:/cygdrive/c/Users/dwh arder/AppData/Local/Microsoft/WindowsApps
These are the only places that Cygwin Terminal will look for an executable to run, and it does not include the current working directory. Rather than looking at this text, here are these directories:
You can even ask where an executable is:
dwharder@CHURCHILL /cygdrive/c/Users/dwharder/eclipse-workspace/Project 0 $ which g++ /usr/bin/g++ dwharder@CHURCHILL /cygdrive/c/Users/dwharder/eclipse-workspace/Project 0 $ which ls /usr/bin/ls dwharder@CHURCHILL /cygdrive/c/Users/dwharder/eclipse-workspace/Project 0 $ which pwd /usr/bin/pwd dwharder@CHURCHILL /cygdrive/c/Users/dwharder/eclipse-workspace/Project 0 $ which cd which: no cd in (/usr/local/bin:/usr/bin:/cygdrive/c/Program Files (x8 6)/Common Files/Oracle/Java/javapath:/cygdrive/c/windows/system32:/cyg drive/c/windows:/cygdrive/c/windows/System32/Wbem:/cygdrive/c/windows/ System32/WindowsPowerShell/v1.0:/cygdrive/c/windows/System32/OpenSSH:/ cygdrive/c/Program Files/MiKTeX 2.9/miktex/bin/x64:/cygdrive/c/Program Files/PuTTY:/cygdrive/c/Program Files/MATLAB/R2019a/runtime/win64:/cy gdrive/c/Program Files/MATLAB/R2019a/bin:/cygdrive/c/Cygwin64/bin:/cyg drive/c/Users/dwharder/AppData/Local/Microsoft/WindowsApps)
You will note that almost all commands are executable files, with very few exceptions like cd.
If you want to execute a file in the current directory, you must give either an absolute path relative path to the directory. You will recall that the alias for the current directory is ., so the following works:
dwharder@CHURCHILL /cygdrive/c/Users/dwharder/eclipse-workspace/Project 0 $ ./a.exe Hello world!
If you want to edit your source file, there are many options:
There are hundreds of other editors available: you are welcome to ask your peers and friends what they use.