WSL: Change the current directory converting a Windows path to a Linux Path

function _cd() { local dir; dir="$(sed -e 's~\([a-z]\):~/mnt/\L\1~gi' <<< "${*//'\'/"/"}" )"; if [ -d "$dir" ]; then cd "$dir" || exit; fi; }
The Windows Subsystem for Linux (WSL) is a compatibility layer for running binary Linux executables natively in Windows. A folder such as "C:\Program Files (x86)\Common Files" is represented as "/mnt/c/Program Files (x86)/Common Files". This function allows you to change the current directory to a Windows folder.
Sample Output
function _cd() { local dir="$(sed -e 's~\([a-z]\):~/mnt/\L\1~gi' <<< "${*//'\'/"/"}" )"; if [ -d "$dir" ]; then cd "$dir"; fi; }

# quotes are necessary:
_cd 'C:\Program Files (x86)\Common Files';

# result: cd '/mnt/c/Program Files (x86)/Common Files'

What Others Think

In searching for the best online services for writing, you must consider the promos that they give to customers. It helps a lot because some are practical. This may also help on getting loyal customers. If you are searching for it, you may try https://www.bestessay.org/bestessays_discount_code.php They are simply the best.
againy · 86 weeks and 5 days ago
asasa
againy · 86 weeks and 5 days ago
Finally, I have learned the basic information about WSL which h a very useful system for online businessmen. I hope it will bring a nice change in my business career that’s why the reason I have decided to get full advantage from this latest system. I always love to visit writeessaysonline.com/is-edubirdie-legit-three-different-perspectives source to read authentic reviews about the website to write essays before hiring one to assist me in my writing work about commands.
HayleyRice · 48 weeks and 4 days ago
post a guide pls types of couples therapy
geebranz · 35 weeks and 4 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: