If you want to be a better programmer, you should learn terminal commands. If you are a Windows user, then you should learn the CMD command to create and edit files and folders.
Open the Windows command prompt and use the following command to create and navigate the folder. You can also add and run these commands inside a .bat file (for automation purposes)
Working with Folders
To create a folder: mkdir folder_name (or Folder_name with location)
Example : mkdir D:\python books
To Navigate to that folder
cd D:\python books
Note: ‘cd' means change directory.
If CMD won't change the directory to another drive, use /d after the cd.
cd /d D:\files
You can also use the drive letter with a semicolon to change the drive
C:\> d:
To rename the folder
ren D:\python books python learning material
To list the files in the current directory
dir
Note: Use dir /? To get the build-in help documentation, to learn more about the dir command to sort fields with size, name, etc.
Move files from one location to another.
move hello.txt D:\
To move multiple files with the same file extension
Use a wildcard to specify the file pattern if you want to move multiple files.
move *.txt C:\Users\public\Desktop
Note: It will not overwrite files if they are already in the destination folder.
If you want to overwrite an existing file, then use the following command: Also, use (move /?) to get additional information and options.
move /Y *.txt C:\Users\public\Desktop
To copy Files: copy (source) (destination)
Ex: copy hello.txt D:\
To copy all files inside the folder: xcopy (source) (destination) /E /I /H
Ex: xcopy D:\rani C:\Users\Public\Desktop /E /I /H
Note:-
- /E – Copy directories and subdirectories inside the folder
- /I – Create the directory structure at the destination
- /H – Copies the hidden and system files also.
Working with Files
To create text files: Use the echo command to create text files.
echo (text) > (file name with extension)
Example : echo Hello world >mytext.txt
It will create a file named mytext.txt with the content “hello world” in the current directory.
To read a text file content
You can also use the following command to create files with other extensions, like .py or .md
notepad test.py
If you want to use the “touch” command to create files (like the videos you see on YouTube), install the npm package named touch-cli using the following command:
npm install touch-cli -g
Then try to create the file using the following command:
touch test.html
Use the type command to open and read a text file: type (filename with extension)
type mytext.txt
To change the content inside a text file
Use the echo command followed by ‘>” (redirection operator to overwrite text file content.
echo Good Morning>mytext.txt
You can also use the copy con command followed by the file name to edit the text file content.
copy con mytext.txt
Edit the content you need. Then press Ctrl + Z and press the Enter key to save the changes.
To delete a file
del mytext.txt
To delete a folder or directory (use the command be carefully. Because it will delete the folder without your confirmation)
rmdir /s /q folder_name
Or use the command with rd instead of rmdir
rd /s /q folder_name
Note: use rmdir or rd with the /s option to delete the folder.
How to start the specific application
Use the start command followed by the name or path of the file.
start chrome
or
start C:\Program Files\Google\Chrome\Application\chrome.exe
To clear previously typed commands & output on the command panel
cls
To Close the command prompt
Type exit and press Enter.
exit
Do not forget to check out our “Best Windows Shortcut Keys for Programmers” article.