There are a few possibilities, but in all cases, keep in mind that accessing files on the Windows drive from WSL/Ubuntu is drastically slower than having them in the virtual ext4 filesystem. If you experience performance issues, consider moving the files into your Ubuntu home directory (~
).
Also, there's no need to cd ../..
from your home directory. Just start the path with /
, as in cd /mnt/c/Users/nyck33
to make it an absolute path rather than a relative one. Do this at least once "manually" in order to make it repeatable using some of the history-search options below.
With that in mind, here are a few (perhaps too many) ways to simplify access to your Windows Documents directory from inside WSL/Ubuntu. My recommendation is the fzf
option (second below), with the symlink option (third) as a close second. There's no reason you can't use both:
Option 1: Reverse History Search
You can use the reverse history search in Bash (and other shells) to quickly repeat the cd /mnt/...
command.
Advantage: No additional configuration required.
First press Ctrl+R to bring up the reverse history search. You'll see:
(reverse-i-search)`':
Start typing Doc
and Bash will find the most recent command with Doc
in it. If this isn't the cd
command, then continue to press Ctrl+R to cycle backward in the search results until you find it, then press Enter to repeat it.
Option 2: Reverse history search with fzf
fzf
, the "command-line fuzzy finder" is a popular utility for "filtering lists". In this case, the list is your shell command history.
sudo apt install fzf
source /usr/share/doc/fzf/examples/key-bindings.bash
# Add the source line above to your ~/.bashrc for future use
Pressing Ctrl+R will now bring up a search/filter of your history. Typing cd Doc
will narrow down the list, likely to the exact cd mnt/c/Users/nyck33/Documents
you want. Simply hit Enter to repeat it.
Option 3: Symlink in your home directory
You can create a symlink in your Ubuntu home directory leading to your Windows home directory:
ln -s /mnt/c/Users/nyck33/Documents/ ~/windocs
With this in place, you can simply cd ~/windocs/
to get to that location. There is no need for any ~/.bashrc
modification since the symlink is simply permanently stored in your home directory.
Option 4: A shell alias:
You can create a Bash (or other shell) aliases to easily move to that directory:
alias windocs="cd '/mnt/c/Users/nyck33/Documents/'"
Executing windocs
as a command from Bash will then take you to that location.
You can, of course, add the alias
to your ~/.bashrc
to have it always available.
Option 5: A shell variable
As mentioned in the comments, you can define your Windows Documents directory as a shell variable and then cd
to it:
windocs="mnt/c/Users/nyck33/Documents"
cd $windocs
The variable declaration can be made permanent by adding it to ~/.bashrc
homework=/mnt/c/Users/nyck33/Documents
then accessing it by typing incd $homework
to take you right there. You can always add thehomework=
line to the bottom of your~/.bashrc
file. – Terrance Jan 13 '23 at 05:53~/.bashrc
– mLstudent33 Jan 13 '23 at 09:04