Setting up custom commands that take effect permanently in WSL

Introduction

Win10 system supports the installation of wsl, which is the built-in subsystem linux. The advantages are hanging VM, easy to use, high performance and small occupation. In daily life, many things that are not supported or compatible with Windows systems can be left to Linux, and you can also easily write some shell scripts to complete the work more efficiently. Press win + r and enter wsl. You can directly access the Linux system and play around with various commands, which is very uncomfortable. At this time, because the traditional windows directory is distinguished by /mnt/disk/ in wsl (it supports perfect sharing!), every time you switch to the corresponding directory, It's more troublesome. Using alias takes effect temporarily, so some personalized commands need to take effect permanently.

Instructions

  1. Search for .bashrc files. Generally, there will be three. As shown in the figure below, they are user, main configuration, and root. If you create N users, there will be N .bashrc based on the user, and the .bashrc file content It comes from the main configuration, that is, modifying the /etc/ske1/.bashrc file will affect subsequent new users. Root does not need to explain too much.

    sudo find / -name .bashrc
    

    Insert image description here

  2. Modify it according to your personal needs, because I am actually the only one using wsl. After thinking about it, I modified the main configuration file.

    sudo vi /etc/skel/.bashrc
    
  3. Add the information alias goproject='cd /mnt/h/project', as shown in the figure below, and save it.
    Insert image description here

  4. Effective configuration

    source /etc/skel/.bashrc
    
  5. You're done, now you can set up many customized personalized configurations.
    Insert image description here

PS: Later it was found that modifying the above files did not achieve the effect. It may be related to the startup sequence of the wsl mechanism. Subsequent modifications to the /etc/bash.bashrc file will take effect and the operation will be as normal. Note that there are no dots.

Guess you like

Origin blog.csdn.net/weixin_43832080/article/details/125465226