DEV Community

Cover image for Access the Windows file system through WSL!
Ivaylo Ivanov
Ivaylo Ivanov

Posted on • Updated on

Access the Windows file system through WSL!

Have you ever wondered, how to access the windows file system through WSL? If the answer is yes you are in the right place!

Microsoft WSL has given us an incredible way to access the windows file system, you have just to navigate through an exact path to do it. Without further due, let's dive into the topic.

1. Use the cd command in the Linux terminal.

To access the windows files you have to navigate through /mnt/your_windows_path

cd /mnt/c/Users
**OR**
cd /mnt/d/your_folder/your_folder
Enter fullscreen mode Exit fullscreen mode

Now you have access to every file in the Linux and Windows file systems.

2. Moving files between the two systems through WSL.

If you want to move files between the two operating systems you can simply use the cp or mv commands.
cp - command for copying files
mv - command for moving files
Use of cp command

cp /mnt/c/file.txt /home/username/Documents
Enter fullscreen mode Exit fullscreen mode

Use of mv command

mv  /mnt/c/file.txt /home/username/Documents
Enter fullscreen mode Exit fullscreen mode

3. Editing windows files through WSL.

To edit windows files through the Linux terminal using WSL, you have to use any text editor that can be opened in the terminal. One of the most famous text editors is nano. In our example, I am going to use the nano editor.
Type into the terminal nano and the path to the file.

sudo nano /mnt/c/Users/file.txt
Enter fullscreen mode Exit fullscreen mode

Now you can edit freely files from your terminal.

4. Creating files in windows through WSL.

To create a file in a specific windows directory you have first to navigate to it and then use the touch command to create a file.
touch - a command that creates a file.
!!! The file extension can be anything you want.

cd /mnt/c/Users/Public/Documents/ 
touch filename.txt
Enter fullscreen mode Exit fullscreen mode

The file is created and can be opened from both systems.

5. Deleting files from the windows file system through WSL.

To delete windows files using WSL, you have to navigate to the directory where the file lives and use the rm command.
rm - a command that deletes files / directories

cd /mnt/c/Users/Public
sudo rm example_file.jpg
Enter fullscreen mode Exit fullscreen mode

Congratulations you learned 5 vital skills about working with the Linux terminal. 🎺🎺🎺
If you have any questions, comment down, I will answer as soon as possible.

Discussion (2)

Collapse
anonyco profile image
Jack Giffin

Question: why would you ever run Windows in the first place?

Collapse
dmorgorg profile image
Dave Morgan • Edited on

Thoughts on keeping working code files on the windows side to keep them in OneDrive? Is it overkill? Not everything deserves a place on github.