Windows Command Prompt TutorialIntroduction Internal and External commands Basic Commands Basic file commands Sorting the data Searching patterns in file Comparing files Variables in Windows command prompt Piping Input and Output Redirection View all processes and tasks killing tasks scheduling tasks Network commands System hardware commands
file commands in windows command promptHere is the list of basic file commands in Windows.
- cd (chdir)
- mkdir (md), rmdir (rd)
- copy con
- copy, xcopy
- move (ren or rename)
- erase and del
- Changing directory
To go to parent directory, you can use below command.
cd /d <path>
To display current directory, you can use below command.
If the name of directory contains spaces, you should enclose the name with double quotes. dir command in Windows command prompt You can use “dir” command to list of all files and directories.
To display the files and directories recursively, you can use below command.
To display the files and directories in ascending order, you can use below command.
To display the files and directories in descending order, you can use below command. Notice that only difference between above command and this command is that we have used “-N” instead of “N”
To display only directories, you can use below command.
To display only files, you can use below command.
Creating and deleting directoryYou can use “mkdir” or “md” command to create new directory.
To delete directory, you can use “rmdir” or “rd” command. Note that below command will delete only empty directories.
To delete directory containing files, you can use below option.
rmdir <directory-name> /S
move, rename (ren) commandsmove command is used to move a file or files to another location. Here is the syntax.
You can also use move command to rename a file. Alternatively you can use below commands to rename file.
move <source> <destination>
rename <old-file-name> <new-file-name> ren <old-file-name> <new-file-name>
attrib commandYou can use “attrib” command to change the attributes of files or directories. For example – To hide the directory or file, you can use below command.
To un-hide the directory or file, you can use below command.
attrib +h <directory-or-file>
attrib -h <directory-or-file>
copy con command
here is the syntax of command.
“copy con” command is used create new files.
After you hit enter, you can enter data in the file and to save file, you have to use ctrl+c hotkey.
> copy con <file-name>
assoc commandassoc command is used to display file extensions and associated file types. We can also associate extensions with file types using below command.
To delete the file extension association, you can use below command. After executing this command, system will not know how to open the .txt file.
Assoc .html=Htmlfile Assoc .txt=txtfile Assoc .exe=exefile
Copying a file using copy and xcopySyntax of copy command is given below.
You can use below command to copy file f1 to f2.
copy <source> <destination>
You can use below command to copy all files from directory d1 to d2.
copy f1 f2
When you do not specify the destination directory, files are coped to current directory.
copy d1* d2
Syntax of xcopy command is same as copy command. Only difference is that xcopy is more powerful. We have lot of options in xcopy command like copying only files with specific attributes, copying hidden and system files etc.
Deleting a fileTo delete a file “f1”, you can use below command.
We can also use “erase” command to delete files.
To delete multiple files ending with .txt, you can use below command.
tree command in Windowstree command displays files and directories in tree format. Here is the sample output of tree command.
Web development and Automation testing