DEV Community

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

Posted on • Edited 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.

Top comments (6)

Collapse
 
joemccanndev profile image
Joe McCann • Edited

Nice quick guide! I got sick of typing cd /mnt/c/Users/Joe so I made an alias in .bash_aliases file I called called cdwin (takes you to Windows "home" folder"

  1. create .bash_aliases in your WSL Ubuntu home directory: touch .bash_aliases
  2. nano .bash_aliases
  3. Enter alias cdwin='cd /mnt/c/Users/<your_windows_username>' into .bash_aliases file
  4. ctrl + x and then Y to save aliases file.
  5. Create a symbolic link in bash shell: ln -s /mnt/c/Users/<your_windows_username> win

Now you can get to "windows home" from anywhere by typing cdwin from within WSL Ubuntu.

Collapse
 
ivayloiv profile image
Ivaylo Ivanov

That's really cool little tip!

Collapse
 
tessjedi profile image
TessJedi

You cannot use the alias without registering it with source .bash_aliases. Thanks for the tip.

Collapse
 
anonyco profile image
Jack Giffin

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

Collapse
 
dmorgorg profile image
Dave Morgan • Edited

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.

Collapse
 
ivayloiv profile image
Ivaylo Ivanov

Personally, I think that GitHub is the best place to store your projects because it is well-integrated with code editors and meant to be used by programmers. If you do not want your work to be publically accessible on GitHub, you can always create a private repository, where only you are going to have access. I do not have experience with google drive for keeping coding projects on there, but certainly, I would prefer Github.