DEV Community

shun
shun

Posted on

File and Directory Operations in Windows Commands

Creating and Removing

  • echo.: Create an empty file.
  C:\> echo. > newfile.txt
Enter fullscreen mode Exit fullscreen mode

mkdir: Create a new directory.

  C:\> mkdir new_directory
Enter fullscreen mode Exit fullscreen mode
  • del: Remove files.
  C:\> del file_to_remove.txt
Enter fullscreen mode Exit fullscreen mode
  • rmdir: Remove a directory (either empty or with contents).
  C:\> rmdir /s /q directory_to_remove
Enter fullscreen mode Exit fullscreen mode

Copying, Moving, and Renaming

  • copy: Copy files.
  C:\> copy source.txt destination.txt
Enter fullscreen mode Exit fullscreen mode
  • xcopy: Copy directories.
  C:\> xcopy /s /i source_directory destination_directory
Enter fullscreen mode Exit fullscreen mode
  • move: Move or rename files or directories.
  C:\> move oldname.txt newname.txt
Enter fullscreen mode Exit fullscreen mode

Listing and Navigating

  • dir: List directory contents.
  C:\> dir
Enter fullscreen mode Exit fullscreen mode
  • cd: Display or change the current directory.
  C:\> cd \path\to\directory
Enter fullscreen mode Exit fullscreen mode

File Content Viewing

  • type: Display the entire content of a file.
  C:\> type file.txt
Enter fullscreen mode Exit fullscreen mode
  • more: View file content with pagination.
  C:\> more file.txt
  (Note: Windows doesn't have direct equivalents to `head` and `tail` commands in its basic command prompt.)
Enter fullscreen mode Exit fullscreen mode

File and Directory Information

  • dir: Display detailed information about a file or directory.
  C:\> dir file.txt
  (Note: Windows doesn't have a direct equivalent to the `file` command in its basic command prompt.)
Enter fullscreen mode Exit fullscreen mode

Searching for Files

  • dir: Search for files in a directory.
  C:\> dir /s /b \path\to\search\*pattern*.txt
Enter fullscreen mode Exit fullscreen mode

Top comments (0)