HomeWinBuzzer TipsHow to Open a File or Folder in Terminal in Windows 11

How to Open a File or Folder in Terminal in Windows 11

We show you how to quickly open a file or folder in Command Prompt or PowerShell how to change directory from ther in Windows 11 using a series of commands.

-

Navigating the Windows Terminal to open files and folders is a skill that enhances productivity and efficiency, particularly for those who prefer command-line interfaces (CLI) over graphical user interfaces (GUI). Windows Terminal, a modern application in Windows 11, integrates traditional command-line environments like Command Prompt (CMD) and PowerShell, providing a robust platform for performing a variety of tasks.

To open a file using CMD within Windows Terminal, you first need to navigate to the directory where the file resides using the cd command. Once there, the start command, followed by the file name, will open the file with its default application. In the case of PowerShell, navigating to the file’s directory is similar.

Windows Terminal is not just limited to file and folder management; it offers a range of features and customization options, from appearance settings like themes and color schemes to functionality enhancements such as multiple tabs and panes. It also supports various command-line tools, including SSH, Azure Cloud Shell Connector, and the Windows Subsystem For Linux (WSL), making it a versatile tool for developers, system administrators, and power users.

For those new to Windows Terminal or seeking to refine their command-line skills, these fundamental operations form the basis of a much broader set of capabilities. The Terminal’s integration of CMD and PowerShell in a single application, coupled with its extensive customization options, underscores its utility in a modern computing environment. Whether managing files, editing settings, or developing scripts, Windows Terminal in Windows 11 offers a powerful interface for advanced users and novices alike to harness the full potential of their system’s command-line tools.

How to Open a File in Terminal using Command Prompt (CMD)

Opening a file using CMD in Windows Terminal involves navigating to the directory where the file is located and then executing it with its associated application. This method is straightforward and effective for users who prefer or require the use of Command Prompt for their tasks. It’s particularly useful when operating in environments where graphical user interfaces (GUIs) are unavailable or when automating tasks through scripts.

  1. Launch Windows Terminal
     
    Start by right-clicking the Start button and selecting “Windows Terminal (Admin)”.
     
    Windows 11 - Open Elevated Windows Terminal

  2. Choose Interface
     
    In the Terminal, click the dropdown next to the plus icon. For CMD, select “Command Prompt”.
     

    Windows 11 - Elevated Windows Terminal - Open Command Prompt

  3. Navigate to the File Folder and Open the File

     
    For example, our file is in the “wonder” folder on our desktop. To get there, you would type:
     
    cd C:\Users\User Name\Desktop\wonder
     
    We know that the file is called “cafe” and is a jpeg filetype, so to open it we can just type "cafe.jpg" and press Enter.
     
    If you’re unsure what your file is called, you can run the commandDIR while in a folder. This will list every file inside of it in CMD.
     
    Windows 11 - Elevated Windows Terminal - Command Prompt - Enter the Cmds to Open File

  4. The File Opens in the Default Program
     
    The file will now open in the application associated with its file type.
     
    Windows 11 - Elevated Windows Terminal - Command Prompt - Enter the Cmds to Open File - File Opened

  5. Try opening a different file type

     
    This trick works not just with images, but documents and basically any file on your PC that you have the software to open. In the example below, we navigate to a folder on the desktop and then open an Excel worksheet:
     
    cd C:\Users\Maria Winbuzzer\Desktop\wonder
     
    "2019.xlsx"
     
    Windows 11 - Elevated Windows Terminal - Command Prompt - Enter the Cmds to Open File

  6. Your Excel workbook will open in its default program: Excel
     

    Windows 11 - Elevated Windows Terminal - Command Prompt - Enter the Cmds to Open File - File Opened

How to Open a File in Terminal using PowerShell

Using PowerShell to open a file in Windows Terminal expands upon CMD’s capabilities by offering more advanced scripting features and cmdlets. PowerShell is a powerful tool for managing Windows systems, and opening files through it can involve more sophisticated commands and scripts. This method is ideal for users who need to incorporate file operations into larger automation tasks or who prefer PowerShell’s extensive command set.

  1. Launch Windows Terminal
     
    Start by right-clicking the Start button and selecting “Windows Terminal (Admin)”.
     
    Windows 11 - Open Elevated Windows Terminal

  2. Choose Interface
      
    In the Terminal, click the dropdown next to the plus icon. Select “PowerShell”.
     

  3. Navigate to your desired folder with “cd”, then type your file name in quotes

     
    For example, our file is in the “downloads” folder. To get there, you would type:
     
    cd C:\Users\User Name\downloads
     
    We know that the file is called “cafe” and is a jpeg filetype, so to open it we can just type "start "cafe.jpg" and press Enter.
     
    If you’re unsure what your file is called, you can type ls while in a folder. This will list every file inside of it in PowerShell.
     

  4. Your file will open in its default program
     
    Windows 11 - Elevated Windows Terminal - Command Prompt - Enter the Cmds to Open File - File Opened

How to Open a Folder from Terminal using Command Prompt (CMD)

Opening a folder from CMD in Windows Terminal allows users to quickly access directories in File Explorer directly from the command line. This method streamlines the process of switching between the CLI and the GUI, facilitating easier file and directory management. It’s particularly handy when you need to visually inspect the contents of a directory or manipulate files using the GUI after locating them via the command line.

  1. Type the following command and Press Enter

     
    With Command Prompt selected in your terminal type the following command and substitute the folder path with one to the folder you want to open:

    start %windir%\explorer.exe "C:\Users\Maria Winbuzzer\Desktop\wonder"

    Windows 11 - Elevated Windows Terminal - Command Prompt - Enter the Cmd to Open Folder

  2. The Folder Opens
     
    The specified folder will appear in File Explorer.
     
    Windows 11 - Elevated Windows Terminal - Command Prompt - Enter the Cmd to Open Folder - Folde Opened

How to Open a Folder from Terminal using PowerShell

PowerShell offers a similar functionality to CMD for opening folders, but with the added flexibility and power of PowerShell scripting. Opening a folder in File Explorer from PowerShell within Windows Terminal can be part of a larger script or simply a quick way to access GUI-based file management. This approach is well-suited for users who are already working within a PowerShell session and want to maintain a streamlined workflow.

  1. Type the following command and Press Enter

     
    With PowerShell selected in terminal, type the following command and substitute the folder path with one to the folder you want to open, like in our case “C:\Users\” for the personal user folder.

    & "$env:windir\explorer.exe" /select "folder path"

     Windows Terminal - PowerShell - Open Folder in Windows Explorer

  2. The Folder Opens
     
    The specified folder will appear in File Explorer.
     

FAQ – Frequently Asked Questions About Handling Files, Folders, and Tasks in Windows Terminal

How do I open a file in a specific application from Windows Terminal?

To open a file with a specific application via Windows Terminal, use the command start application.exe “file path” in CMD, where application.exe is the executable name of your application and “file path” is the full path to your file. In PowerShell, use Start-Process -FilePath “application.exe” -ArgumentList “file path”. This explicitly specifies the file path to the application and the argument list with the file you wish to open. Ensure the application can open the file type you’re working with.

How do I create a new file from Windows Terminal?

To create a new file in CMD, navigate to your desired directory and execute echo.> filename.ext, where filename.ext is the name and extension of your new file. This creates a file with minimal content. In PowerShell, the command New-Item filename.ext -ItemType “file” creates a new file in the current directory. Replace filename.ext with the intended name and extension of your file.

How do I copy or move files using Windows Terminal?

In CMD, use copy “source path” “destination path” to copy files, and move “source path” “destination path” to move files. Replace the paths with your file’s current and desired new locations. In PowerShell, use Copy-Item -Path “source path” -Destination “destination path” to copy, and Move-Item -Path “source path” -Destination “destination path” to move files. These commands allow for file management within the terminal environment.

How can I delete a file or folder through Windows Terminal?

To delete a file in CMD, use the command del “filename”. For folders, use rmdir /S /Q “foldername”. In PowerShell, the commands are Remove-Item “filename” -Force for files and Remove-Item “foldername” -Recurse -Force for folders. The -Force and -Recurse parameters in PowerShell ensure deletion of read-only files and all contents within a folder, respectively.

How do I list all files of a specific type in a directory using Terminal?

In CMD, to list files of a specific type, use dir *.ext, replacing *.ext with the desired file extension. This displays all matching files in the current directory. In PowerShell, the command Get-ChildItem -Filter *.ext lists files of a specific type, with the -Filter parameter allowing you to specify the desired file extension or pattern.

How do I see hidden files in a directory from Windows Terminal?

To list hidden files in CMD, use the command dir /A:H. In PowerShell, the equivalent command is Get-ChildItem -Force, which reveals hidden files and directories in the listing by overriding the default behavior to hide certain items.

How can I change file attributes from Windows Terminal?

In CMD, use attrib +AttributeType filename to add an attribute or attrib -AttributeType filename to remove an attribute from a file, where AttributeType could be R (read-only), H (hidden), S (system), or A (archive). In PowerShell, use Get-Item “filename” | Set-ItemProperty -Name Attributes -Value “ReadOnly, Hidden” to manage file attributes in a more structured manner.

How do I find the current version of Windows from Terminal?

In CMD, systeminfo | findstr /B /C:”OS Name” /C:”OS Version” filters the output to show only the OS name and version. In PowerShell, use Get-ComputerInfo -Property “OsName”, “OsVersion” to display the operating system name and version in a formatted output, providing a clear view of your current Windows version.

How do I terminate a running process using Windows Terminal?

In CMD, use taskkill /IM “processname.exe” /F to forcibly terminate a process, replacing “processname.exe” with the actual process name. The /F parameter forces the command to stop the specified process. In PowerShell, the command Stop-Process -Name “processname” -Force achieves a similar outcome, with -Name specifying the process by name and -Force ensuring the process is terminated, providing a method to manage running processes effectively.

How can I view the network configuration and active connections in Terminal?

In CMD, ipconfig displays the current network adapter configuration, while netstat lists active connections and listening ports. In PowerShell, Get-NetIPConfiguration provides detailed network configuration info, and Get-NetTCPConnection shows active TCP connections, offering insights into network activity with structured output and filtering options.

How do I schedule tasks from Windows Terminal?

CMD’s schtasks utility allows for comprehensive task scheduling, such as creating, modifying, and querying tasks. Use schtasks /create with appropriate parameters to set up new tasks. In PowerShell, combine New-ScheduledTask, New-ScheduledTaskAction, and Register-ScheduledTask for granular task scheduling, with each cmdlet providing specific functionalities for creating and managing scheduled tasks in a more detailed manner.

How do I compress or extract files using Windows Terminal?

To compress files in CMD, use compact /c /s:”directory” “filename” and expand “source” “destination” to extract. PowerShell’s Compress-Archive and Expand-Archive cmdlets offer straightforward commands for compressing and extracting files, respectively, providing a simple and efficient way to manage file compression and extraction within Windows Terminal.

How can I update Windows from the Terminal?

Although CMD doesn’t provide a direct command for Windows updates, PowerShell enables launching the update interface with Start-Process “ms-settings:windowsupdate”. This command opens the Windows Update settings, allowing manual check and installation of updates, serving as a bridge to Windows Update functionality from the Terminal.

How do I repair system files from Windows Terminal?

The sfc /scannow command in CMD scans and repairs system files by replacing corrupted files with a cached copy. This tool is crucial for system integrity. In PowerShell, the same command can be used to perform system file checks and repairs, maintaining system health and troubleshooting issues effectively.

How can I manage Windows Firewall settings through Terminal?

CMD provides netsh advfirewall commands for Windows Firewall configuration, such as enabling/disabling the firewall and setting rules. PowerShell introduces cmdlets like Get-NetFirewallRule and New-NetFirewallRule for viewing and creating firewall rules, offering a structured approach to firewall management with detailed rule configuration parameters, enhancing security management capabilities within the Terminal.

Related: How to Open Command Prompt with the “Open Command Window Here” in File Explorer

When you want to open CMD in a folder you have to navigate there manually via commands. If you’re a heavy CMD user, this gets frustrating pretty quickly. In our other guide, we show you how to return the “open command window here” entry to your File Explorer.
 
How to return the 'Open command window here' option to Windows 10's context menu

Related: How to Enable PowerShell Scripts via PowerShell Execution Policy

PowerShell is a powerful tool that many, including myself, don’t use to its full potential. That’s why most of us rely on PowerShell scripts crafted by others, but this can have its own hurdles. Often, you’ll see errors like “PowerShell: running scripts is disabled on this system”. To Enable PowerShell scripts in Windows, you must first set the execution policy. In our other guide, we show you how to enable PowerShell scripts in Windows by setting your execution policy via the command-line.
 
How to Set PowerShell Script Execution Policy in Windows 10

Related: How to Stop, Start, and Restart a Service with Command Prompt

As we mentioned, there are hundreds of things you can do with Command Prompt rather than using the UI. One of them is managing your services. You can learn how by following our dedicated guide here.

Related: How to Run Microsoft Defender from the Command Line (CMD)

Knowing how to run Microsoft Defender (formerly Windows Defender) from the command line can be very useful. Perhaps you’ve been locked out of its UI due to malware, are trying to run a scan from recovery media, or are using a GUI-less Windows Server install. In any of these situations, knowing a scan command or two can save you a lot of trouble. In our other tutorial, we show you how to use Microsoft Defender via CMD commands.
 

Last Updated on April 22, 2024 11:49 am CEST

Markus Kasanmascheff
Markus Kasanmascheff
Markus has been covering the tech industry for more than 15 years. He is holding a Master´s degree in International Economics and is the founder and managing editor of Winbuzzer.com.
Table of Contents:
Mastodon