CMD Basics
1. Change directory
'cd' stands for 'change directory' and the new directory you want to switch to is provided as the first argument.
cd tuna
Here, we're moving to the directory 'tuna.'
Switching to the previous directory
cd ..
The '..' means "previous directory."
Switching to the current directory (won't make a difference)
cd .
The '.' means "current directory."
What if we want to switch to the directory "salmon" inside "bacon" which in turn is inside "tuna"?
cd tuna/bacon/salmon
Forward slash (/) or back slash (\) represents levels of directories.
How about moving back 2 directories and switching to the directory named 'wavicle'?
cd ../../wavicle
2. Directory contents list
The command 'dir' displays the list of all contents inside a directory.
dir
3. Create directory
'mkdir' stands for 'make directory.'
mkdir test
The command above will create a directory named 'test.'
4. Remove directory
'rmdir' stands for 'remove directory.'
rmdir test
The directory named 'test' will be removed.
5. Practical example [Compiling C++]
The command will compile 'main.cpp' and create an executable 'a.exe' out of it.
g++ main.cpp
You can add the flag '-o' (where 'o' stands for 'output') to specify the name of the output file.
g++ main.cpp -o test
Here, an executable 'test.exe' will be created.
You can specify multiple source files for compilation by providing the filenames separated by spaces.
g++ main.cpp apple.cpp tuna.cpp -o main
The compiler will compile 'main.cpp', 'apple.cpp' and 'tuna.cpp' and create 'main.exe' out of them.
6. Executing programs
You can execute a program by just writing its filename:
main.exe
This will execute a program named 'main.exe.'
7. Executing multiple commands
You can run multiple commands by writing the commands with "&&" between them like this:
cd ../../wavicle && mkdir test && cd test
This will execute the 3 commands one after another.