DEV Community

Ranjith srt
Ranjith srt

Posted on • Edited on

Windows | command lines |

Go forward : cd path\to\folder 
Enter fullscreen mode Exit fullscreen mode
Go backward : cd ../..
Enter fullscreen mode Exit fullscreen mode
Show lists of files and directories : dir
Enter fullscreen mode Exit fullscreen mode
Show lists of files and directories with hidden files also : dir /a
Enter fullscreen mode Exit fullscreen mode
Clearing screen : cls
Enter fullscreen mode Exit fullscreen mode
Show specific type of files: dir *.png | dir *.jpg
Enter fullscreen mode Exit fullscreen mode
Help for a specific command: ipconfig /? | cls /?
Enter fullscreen mode Exit fullscreen mode
Create a new directory : mkdir myDir | mkdir path\to
Enter fullscreen mode Exit fullscreen mode
Remove or delete directories: if your directory is empty rmdir myDir else rmdir /S myDir
Enter fullscreen mode Exit fullscreen mode
Changing drivers : C: | D:
Enter fullscreen mode Exit fullscreen mode
Show path variables: path
Enter fullscreen mode Exit fullscreen mode
Show available drive names: wmic logicaldisk get name
Enter fullscreen mode Exit fullscreen mode
Change color: color 0B | color 90 or back to default just use color
Enter fullscreen mode Exit fullscreen mode
Creating a file : echo somecontent > file.txt
Enter fullscreen mode Exit fullscreen mode
Deleting file: del filename.ext
Enter fullscreen mode Exit fullscreen mode
Reading contents of a file: type file.ext\
Enter fullscreen mode Exit fullscreen mode
Override to a file : echo newcontent > samefile.ext
Enter fullscreen mode Exit fullscreen mode
Appending to a file : echo appendingcontent >> samefile.ext
Enter fullscreen mode Exit fullscreen mode
Copying files: copy test.txt mydir
Enter fullscreen mode Exit fullscreen mode
Introduction to Command Prompt:
Enter fullscreen mode Exit fullscreen mode

The command line in Windows is also known as Command Prompt or CMD.

On Mac and Linux systems, it's called Terminal.

Image description

To open Command Prompt, follow these steps: Open Start, search for 'Command Prompt', and select it.

Alternatively, you can click the keyboard shortcut (Windows + R), type 'cmd', and press Enter.

Image description

Image description

The first line will indicate the version we are using and the current file location by default.

Image description

Right-click on the top title bar, and the Properties screen will appear. From there,

Image description

Image description

To move from one directory to another, use the cd command followed by the folder name.

For example, to move to the 'Desktop' directory from C:\user\ranjith, type cd desktop.

C:\user> ranjith >
Cd space desktop 
Enter fullscreen mode Exit fullscreen mode

To go to the 'python' folder inside 'Desktop', type cd desktop\python.

C:\user> ranjith >
Cd desktop > python
Enter fullscreen mode Exit fullscreen mode

To return to the parent directory, use cd ... For example, if you are in C:\user\ranjith\desktop\python and want to go back two levels to

C:\user\ranjith, 
type cd ..\.. 
Enter fullscreen mode Exit fullscreen mode

To navigate directly to a specific directory in one line, you can provide the full path.

For example, to go directly to C:\user\ranjith\desktop\python,

you can type cd 

C:\user\ranjith\desktop\python.

Enter fullscreen mode Exit fullscreen mode

Image description
To list files and directories :

use the dir command.

For example, C:\user\ranjith> dir
Enter fullscreen mode Exit fullscreen mode

will show the files, folders, free space, and storage details in the current directory.

Image description

To view the contents of a specific folder, use dir followed by the folder path.

 For example, C:\user\ranjith>dir 
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Desktop\Python will display all files and folders in the Python folder on the Desktop.

Image description

To view hidden or system files, you can use the dir /a command.

 For example,

 C:\user\ranjith>dir /a
Enter fullscreen mode Exit fullscreen mode

will display all files, including hidden and system files.

Image description

To clear the command prompt screen, use the cls command.

For example, 

C:\user\ranjith> cls 
Enter fullscreen mode Exit fullscreen mode

Image description
will clear the screen and remove previous command outputs.

Opening Files and Viewing History:

To list files of a specific type in a directory, use the dir command with a filter.

For example, 

C:\user\ranjith>dir *.png will list all PNG 
Enter fullscreen mode Exit fullscreen mode

Image description

image files in the current directory.

To open a specific file, enter its filename.

Image description

For instance,

C:\user\ranjith\python>binary_search.png would open the binary_search.png file.
Enter fullscreen mode Exit fullscreen mode

Image description

To navigate through your command history, use the Up and Down arrow keys. Pressing the Up arrow key will cycle through previous commands, while the Down arrow key will move forward through the commands.


To get help on a command, use the /? option.

Image description

For example,

C:\user\ranjith>ipconfig /? will show help for the ipconfig command.
Enter fullscreen mode Exit fullscreen mode

Creating and Removing Folders:

To create a new folder, use the mkdir command followed by the folder name.

For example,

C:\user\ranjith>python>mkdir temp will create a folder named temp.
Enter fullscreen mode Exit fullscreen mode

Image description

Image description
To remove a folder, use the rmdir command followed by the folder name.

For example,

C:\user\ranjith>python>rmdir temp will delete the temp folder.
Enter fullscreen mode Exit fullscreen mode

Image description
Note that the rm command is used for files in some systems, but in Command Prompt, you use del for files and rmdir for directories.

Creating and removing directories:

To create a directory, use the command mkdir txt. 
Enter fullscreen mode Exit fullscreen mode
To remove a directory and its contents, use rmdir /s txt.
Enter fullscreen mode Exit fullscreen mode

This will delete all files and subfolders in the directory as well as the directory itself.

Image description

Use Ctrl + Left Arrow to move the cursor to the beginning of the line and Ctrl + Right Arrow to move it to the end. 
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

To check the version, use ver.
Enter fullscreen mode Exit fullscreen mode

Image description

 To start multiple command boxes, use Start.
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

To exit, use Exit.
Enter fullscreen mode Exit fullscreen mode

Image description


Drives and Color Commands:

To list all drives, use: wmic logicaldisk get name. This will show all available drives.

c:\user> ranjith > 
wmic logicaldisk get name
Enter fullscreen mode Exit fullscreen mode

Image description

To switch to a different drive, type the drive letter followed by a colon (e.g., E:).

C:\user> ranjith >  E:
Enter fullscreen mode Exit fullscreen mode

To list files in the current drive, use: dir.

E :\> dir
Enter fullscreen mode Exit fullscreen mode

To view hidden files, use: dir /a.

E :\> dir /a
Enter fullscreen mode Exit fullscreen mode

Image description

To see a directory tree, use: tree.

Image description

E :\> tree 
Enter fullscreen mode Exit fullscreen mode

Changing Text and Background Colors:

E :\> color /?
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

To change the color of text and background, use: color /? to see help options.

For example, color a changes the text color to green.

Image description

E :\> color
Enter fullscreen mode Exit fullscreen mode
E :\> color a
Enter fullscreen mode Exit fullscreen mode

color fc sets a bright white background (if 'f' is not given, it defaults to black) and changes text color to bright red.

Image description

E :\> color fc
Enter fullscreen mode Exit fullscreen mode

Image description

These commands help manage files and customize the appearance of your command prompt

File Attributes:
Enter fullscreen mode Exit fullscreen mode

To view file attributes and get help, use: attrib /?.

Image description

C:\user> ranjith >  YouTube > attrib /? 
Enter fullscreen mode Exit fullscreen mode

Image description
To see the attributes of a file, use: attrib sample.txt.

Image description

Image description

C:\user> ranjith >  Desktop >youtube >
attrib sample. txt
Enter fullscreen mode Exit fullscreen mode

Replace sample.txt with your file name.
To add the "hidden" attribute to a file, use: attrib +h sample.txt.

Image description

C:\user> ranjith >  Desktop >youtube >
attrib +h sample. txt 
Enter fullscreen mode Exit fullscreen mode

To remove the "hidden" attribute, use: attrib -h sample.txt.

Image description

Image description

C:\user> ranjith >  Desktop >youtube >
attrib +r - h sample. txt
Enter fullscreen mode Exit fullscreen mode

Deleting and Creating Files:

To delete a file, use: del sample.txt.

Image description

C:\user> ranjith >  Desktop >youtube >
del sample. txt

del - delete <FileName >
Enter fullscreen mode Exit fullscreen mode

To create a new file, use: echo. > sample.txt. This creates an empty file.

Image description

C:\Users\mrkis\Desktop\Youtube>
echo > sample.txt
Enter fullscreen mode Exit fullscreen mode

To write text to a file, use: echo Kishore > sample.txt. This writes "Kishore" to the file.

Image description

Image description

C:\Users\mrkis\Desktop\Youtube>
echo Kishore > sample.txt
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

C:\Users\mrkis\Desktop\Youtube>
type sample.txt
Enter fullscreen mode Exit fullscreen mode

To view the contents of the file, use: type sample.txt.
Appending Text to Files:

Image description

C:\Users\mrkis\Desktop\Youtube>echo hello>sample.txt
Enter fullscreen mode Exit fullscreen mode

To add text to the end of a file without overwriting existing content, use: echo world >> sample.txt.

C:\Users\mrkis\Desktop\Youtube>type sample.txt
Enter fullscreen mode Exit fullscreen mode

This will add "world" to the end of sample.txt.

Image description

To see the updated content, use: type sample.txt.
Copying Files:

To copy a file to another location or with a new name, use: copy sample.txt test2.txt. This copies sample.txt to a new file named test2.txt in the same directory. If you want to specify a different directory, provide the path instead of just the filename.

Image description

Image description

C:\Users\mrkis\Desktop\Youtube>
copy sample.txt test2
Enter fullscreen mode Exit fullscreen mode

This guide helps with managing file attributes, performing file operations, and

Copying Files Between Disks:

To copy a file from one disk to another, use: copy sample.txt E:. This copies sample.txt from the current location to the E: drive.
Using XCOPY for Copying Directories:

To copy files and directories, including subdirectories, use: xcopy test1 test2 /s. This copies test1 (which can be a file or directory) to test2, including all subfolders and files.
Moving Files:

C:\Users\mrkis\Desktop\Youtube>
copy sample.txt e:
E - another disk
Enter fullscreen mode Exit fullscreen mode

To move files from one location to another, use: move test1 test2. This command moves test1 to test2. If test2 is a folder, test1 will be moved into it. If test2 is a file name, test1 will be renamed to test2.
In summary:

C:\Users\mrkis\Desktop\Youtube>
xcopy test1 test2 /s
Enter fullscreen mode Exit fullscreen mode
copy sample.txt test2
Sample. txt - endha file ah copy seiya vendum. 

S - sub files

Enter fullscreen mode Exit fullscreen mode

copy source destination copies files.
xcopy source destination /s copies files and directories, including subdirectories.
move source destination moves files or renames them

Image description

Image description
Image description

Top comments (0)