Basic file commands in Windows Command prompt
Here 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
You can use “cd” command to change the directory.
cd /d <path>
To go to parent directory, you can use below command.
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 directory
You 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) commands
move command is used to move a file or files to another location. Here is the syntax.
move <source> <destination>
You can also use move command to rename a file. Alternatively you can use below commands to rename file.
rename <old-file-name> <new-file-name>
ren <old-file-name> <new-file-name>
You 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.
attrib +h <directory-or-file>
To un-hide the directory or file, you can use below command.
attrib -h <directory-or-file>
copy con command
“copy con” command is used create new files.
here is the syntax of command.
> copy con <file-name>
After you hit enter, you can enter data in the file and to save file, you have to use ctrl+c hotkey.
assoc 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.
Copying a file using copy and xcopy
Syntax of copy command is given below.
copy <source> <destination>
You can use below command to copy file f1 to f2.
copy f1 f2
You can use below command to copy all files from directory d1 to d2.
copy d1\* d2
When you do not specify the destination directory, files are coped to current directory.
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 file
To 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 Windows
tree command displays files and directories in tree format. Here is the sample output of tree command.