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
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
Use of mv command
mv /mnt/c/file.txt /home/username/Documents
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
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
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
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)
Nice quick guide! I got sick of typing
cd /mnt/c/Users/Joe
so I made an alias in.bash_aliases
file I called calledcdwin
(takes you to Windows "home" folder"touch .bash_aliases
nano .bash_aliases
alias cdwin='cd /mnt/c/Users/<your_windows_username>'
into .bash_aliases filectrl + x
and thenY
to save aliases file.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.That's really cool little tip!
You cannot use the alias without registering it with
source .bash_aliases
. Thanks for the tip.Question: why would you ever run Windows in the first place?
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.
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.