把WSL安装到指定目录下的简易完美方法

旧版 WSL 的手动安装步骤 (Microsoft Learn)

用Microsoft Store安装比自己下载AppxBundle快很多、下载的文件小(差不多是60MB vs 120MB),后者还可能断线(还不能续传)。

下面以Debian为例:

  1. 导出安装为tar文件:wsl --export debian e:\debian.tar
  2. 删除旧安装:wsl --unregister debian
  3. 导入新安装到指定目录:wsl --import debian d:\debian e:\debian.tar
  4. 然后可以再wsl --export一次,到别的机器上装时就方便了。

之后开始菜单里的快捷方式依然可用,只是默认用root登录,可编辑.profile,在最后加3行:

cd /home/user # 你的用户名
su -l user # switch_user -login 你的用户名
exit

解决vim打开文件时默认进入REPLACE模式的办法:在~/.vimrc中加入2行 [stackoverflow]:

syntax on
set noek

在vim里:help noek 'esckeys' 'ek' boolean (Vim default: on, Vi default: off) global

  • Function keys that start with an <Esc> are recognized in Insert mode. When this option is off, the cursor and function keys cannot be used in Insert mode if they start with an <Esc>. The advantage of this is that the single <Esc> is recognized immediately, instead of after one second. Instead of resetting this option, you might want to try changing the values for 'timeoutlen' and 'ttimeoutlen'. Note that when 'esckeys' is off, you can still map anything, but the cursor keys won't work by default.
  • NOTE: This option is set to the Vi default value when 'compatible' is set and to the Vim default value when 'compatible' is reset.
  • NOTE: when this option is off then the |modifyOtherKeys| functionality is disabled while in Insert mode to avoid ending Insert mode with any key that has a modifier.

编辑器还可以用nano. 当然,WSL嘛,MadEdit, vscode, UltraEdit...

debian.tar 260MB, d:\debian占用255MB. 然后再开始在debian下装软件。

Debian 11 (bullseye) 国内软件源  [吃饱了撑的用https, http能用的;把我的皮肤钱捞回来:-)]

deb http://mirrors.163.com/debian/ bullseye main non-free contrib
deb-src http://mirrors.163.com/debian/ bullseye main non-free contrib
deb http://mirrors.163.com/debian-security/ bullseye-security main
deb-src http://mirrors.163.com/debian-security/ bullseye-security main
deb http://mirrors.163.com/debian/ bullseye-updates main non-free contrib
deb-src http://mirrors.163.com/debian/ bullseye-updates main non-free contrib
deb http://mirrors.163.com/debian/ bullseye-backports main non-free contrib
deb-src http://mirrors.163.com/debian/ bullseye-backports main non-free contrib

鼠标右键粘贴。apt-get clean; apt-get update; apt-get install vim build-essential gcc [...get 95.2 MB...350 MB will be used]

WIN10系统右击开始菜单没有属性选项怎么办 [不好使。暂时满足于点Debian能打开,具体啥命令不知道]

  • wsl --exec, -e <命令行> 执行指定的命令而不使用默认的 Linux shell [Debian应该是Windows\System32\wsl.exe的快捷方式]
  • wsl --user, -u <用户名> 以指定用户身份运行。[改不了快捷方式可以改.profile]

说微软啥好呢?费劲的做了,加个压缩生成.tar.gz, .xz, .bzip2……不做?压缩的专利该过期了吧?

wsl --help
 --export <分发版> <文件名>
        将分发导出到 tar 文件。对于标准输出,文件名可以是 -。
 --import <分发版> <安装位置> <文件名> [选项]
        将指定的 tar 文件作为新分发进行导入。对于标准输入,文件名可以是 -。

C:\Program Files\7-Zip>7z --help
Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...] [@listfile]
 <Commands>
  a : Add files to archive
  x : eXtract files with full paths

 <Switches>
  -si[{name}] : read data from stdin
  -so : write data to stdout
  -m{Parameters} : set compression Method
    -mmt[N] : set number of CPU threads
    -mx[N] : set compression level: -mx1 (fastest) ... -mx9 (ultra)

D:\>type 1.tar | 7z a -si2 -mmt8 -mx9 3.7z
  3.7z里一个2文件,-si和2之间不能有空格
D:\>7z x -so 3.7z >2.tar
  解压到2.tar
D:\>fc/b 1.tar 2.tar
  正在比较文件 1.tar 和 2.TAR FC: 找不到差异

如果D盘出现了资源管理器里删不掉的WindowsApps和Program Files目录,可用如下方法删掉:以管理员身份运行cmd:

takeown /f WindowsApps /r
takeown /f "Program Files" /r
icacls "Program Files" /grant:r user:f /inheritance:e

user要换成你的用户名。我的用户名就是user。f是full

D:\>cacls
注意: 不推荐使用 Cacls,请使用 Icacls。显示或者修改文件的访问控制列表(ACL)

这不是方便病毒,恶心用户吗?Linux下的su,如果病毒不知道用户的密码,su不了吧?takeown和icacls也不问密码啊?

tar is able to search directories on its own and takes the list of files or directories to be backed up from command line arguments. cpio archives only the files or directories it is told to, but does not search subdirectories recursively on it's own.

  • apt-get install g++ flex bison [...1,991...4,948 kB]
  • gcc version 10.2.1 20210110 (Debian 10.2.1-6)
  • D:\debian占用835MB
posted @ 2022-12-28 22:59  Fun_with_Words  阅读(1096)  评论(0编辑  收藏  举报









 张牌。