AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 690680
Accepted
JayRugMan
JayRugMan
Asked: 2022-02-15 15:00:26 +0800 CST2022-02-15 15:00:26 +0800 CST 2022-02-15 15:00:26 +0800 CST

无法从 Windows 10 Enterprise 上的 Ubuntu 子系统中删除文件

  • 772

这可能是错误的论坛,但无论如何我都会试一试。我在 Windows 10 Enterprise 中运行 ubuntu 子系统:

root@hostname:/directory/stuff# cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS"

该文件位于 repo 中,并显示为lsand git status,但不在 GUI 中(在资源管理器视图选项中检查了“隐藏文件”)或dir在 cmd 中显示。这是一个“隐藏”文件,当您打开 Excel 电子表格时会显示 - 只有电子表格被关闭。即使我再次打开和关闭,它也无法移除。chmod我可以用and修改所有权和权限chown,这很奇怪,我不能做任何其他事情:

root@hostname:/directory/stuff# ll
total 14600
...
-rwxrwxrwx 0 my_name my_name     165 Feb 14 13:25 '~$Copy of Full Compilation of Databases for Audit.xlsx'*
root@hostname:/directory/stuff# chown root: ~\$Copy\ of\ Full\ Compilation\ of\ Databases\ for\ Audit.xlsx 
root@hostname:/directory/stuff# ll
total 14600
...
-rwxrwxrwx 0 root    root        165 Feb 14 13:25 '~$Copy of Full Compilation of Databases for Audit.xlsx'*

我试过了:

root@hostname:/directory/stuff# ls -i
...
1688849860795414 '~$Copy of Full Compilation of Databases for Audit.xlsx'
....
root@hostname:/directory/stuff# find . -inum 1688849860795414 -exec rm {} \;
rm: cannot remove './~$Copy of Full Compilation of Databases for Audit.xlsx': No such file or directory
....
root@hostname:/directory/stuff# rm -i -- ./*
...
rm: remove regular file './~$Copy of Full Compilation of Databases for Audit.xlsx'? y
rm: cannot remove './~$Copy of Full Compilation of Databases for Audit.xlsx': No such file or directory
....
root@hostname:/directory/stuff# ls -1b
...
~$Copy\ of\ Full\ Compilation\ of\ Databases\ for\ Audit.xlsx
root@hostname:/directory/stuff# rm ~$Copy\ of\ Full\ Compilation\ of\ Databases\ for\ Audit.xlsx
rm: cannot remove '~ of Full Compilation of Databases for Audit.xlsx': No such file or directory
....
root@hostname:/directory/stuff# mv ~\$Copy\ of\ Full\ Compilation\ of\ Databases\ for\ Audit.xlsx just_a_file.xlsx
mv: cannot move '~$Copy of Full Compilation of Databases for Audit.xlsx' to 'just_a_file.xlsx': No such file or directory

任何人都可以添加到这将是伟大的!

更正: 在上面,我说我看不到来自CMD的文件dir,但我可以dir /a- 所以 windows 在某种程度上可以看到它。但是,即使从 CMD 中,我仍然无法删除它(奇怪的是它在此处完成制表符)。

C:\Users\me\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\rootfs\directory\stuff>dir /a
 Volume in drive C has no label.
...
2022-02-14  13:25               165 ~$Copy of Full Compilation of Databases for Audit.xlsx
...

C:\Users\me\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\rootfs\directory\stuff>del "~$Copy of Full Compilation of Databases for Audit.xlsx"
Could Not Find C:\Users\me\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\rootfs\directory\stuff\~$Copy of Full Compilation of Databases for Audit.xlsx
ubuntu filesystems
  • 2 2 个回答
  • 1691 Views

2 个回答

  • Voted
  1. NotTheDr01ds
    2022-02-16T12:20:08+08:002022-02-16T12:20:08+08:00

    您很可能有某种 WSL 文件系统损坏。我不会这么快就得出这个结论,但是:

    • 很明显,您使用的是 WSL 版本 1,因为您可以rootfs从 CMD 中看到目录。这在 WSL2 中是不可能的,因为它将其文件系统存储在一个虚拟磁盘 ( ext4.vhdx) 中,该磁盘无法从 CMD 访问。

    • 您正在rootfs从 Windows 应用程序(例如 CMD)访问该目录。如果您这样做是为了删除该文件,我担心您使用相同的路径从 Excel 创建或编辑文件。

    • 已知访问该目录会导致 WSL 文件系统损坏。从该页面引用:

      在任何情况下,都不要%LOCALAPPDATA%使用 Windows 应用程序、工具、脚本、控制台等访问、创建和/或修改文件夹内的 Linux 文件。

      使用某些 Windows 工具打开文件可能会读取锁定打开的文件和/或文件夹,从而阻止更新文件内容和/或元数据,从而导致文件/文件夹损坏。

      从 Windows 创建/更改您的 Appdata 文件夹中的 Linux 文件可能会导致数据损坏和/或损坏您的 Linux 环境,需要您卸载并重新安装您的发行版!

    这听起来像你正在经历的。

    (旁注,尽管它不适用于您的情况:无论位置如何,说“不要访问 ... Linux 文件rootfs”更准确,因为您可以将 WSL1 实例放置在AppData.)

    如果在任何时候,您使用 Excel、Windows 版 Git 或任何其他 Windows 工具访问了该路径,则很容易导致您看到的锁定。

    请注意,如果您的用例(和计算机)支持使用 WSL2,则 WSL2 的文件系统更加健壮。

    另请注意,正如 Microsoft 博客所述,您可以从 Windows 访问 WSL 文件。只是您需要使用\\wsl$\<distroname>路径才能安全地执行此操作。


    对于“建议的解决方案”,我将从几天前在 Ask Ubuntu 上提供的类似问题的答案中复制/粘贴,尽管我从未收到该海报关于他们是否成功恢复的回复使用这些说明:

    潜在的解决方案:

    我假设您已重新启动 PC,但如果没有,请尝试以防万一,以确保已释放任何手柄/锁。它的工作机会相对较小,但值得一试。

    如果这不起作用,我会推荐以下方法来尝试修复 WSL1 实例。

    wsl --export基本上通过/往返 WSL1 实例wsl --import。此过程执行的tar往返可能(希望)在归档或取消归档时删除损坏的文件(或至少锁定)。

    从 PowerShell:

    # Confirm the distribution name
    wsl -l -v
    # Distribution name may be "Ubuntu" or "Ubuntu-20.04" - Adjust the following lines accordingly:
    wsl --shutdown
    cd ~\Documents
    mkdir WSL\images
    mkdir WSL\instances\UbuntuRecovery
    wsl --export Ubuntu WSL\images\ubuntu.tar
    wsl --import UbuntuRecovery WSL\instances\UbuntuRecovery WSL\images\ubuntu.tar --version 1
    wsl -d UbuntuRecovery
    

    查看该文件在该新实例中是否已消失或可删除。

    如果是这样,并且如果在新实例中其他一切看起来都不错,那么:

    • 根据此答案/etc/wsl.conf通过文件设置该实例中的默认用户名。
    • 退出实例
    • 同样,来自 PowerShell:
      wsl --terminate UbuntuRecovery
      wsl --set-default UbuntuRecovery
      

    wsl无论何时运行,新实例都将是默认实例。

    最后,使用以下命令删除原始损坏的实例:

    wsl --unregister Ubuntu
    

    重要提示:这是一种破坏性操作。确保一切都按预期工作。从好的方面来说,我们已经进行了备份......

    您还可以卸载当时从商店安装的 Ubuntu“应用程序”。

    您将通过wsl(如果您还没有)或 Windows 终端启动,因为ubuntu.exe(或ubuntu2004.exe)命令将消失。

    • 0
  2. Best Answer
    JayRugMan
    2022-02-17T08:48:45+08:002022-02-17T08:48:45+08:00

    我不确定哪些星星对齐,但今天早上我能够删除该文件。这可能是因为我关闭了电脑带回家,然后锁被清除了,但我不知道我是否能确定。为了删除它,我只是将 repo 拉到了适当的 Linux 环境中——Linux Mint 在同一台机器上的 VM 上运行——不是说它必须是 VM——或者在有问题的同一台 Windows 计算机上,但它是,所以你去。因为它是一个合适的 Linux 环境,所以我可以在 nemo 中删除它。我可以发誓这个特定的文件在我昨天同步的时候没有被拉下来,但是今天它做到了,我删除了这个小虫子。当我提交并推送,然后拉上 Windows 机器上的 Ubuntu 子系统时,该文件被删除:

     dir/to/file > master > git pull
       01239e91..452981f2  master     -> origin/master
    Updating 01239e91..452981f2
    Fast-forward
     dir/to/file/All-Production.vsdx                                    | Bin 1101177 -> 1100811 bytes
     dir/to/file/~$Copy of Full Compilation of Databases for Audit.xlsx | Bin 0 -> 165 bytes
     2 files changed, 0 insertions(+), 0 deletions(-)
     create mode 100755 dir/to/file/~$Copy of Full Compilation of Databases for Audit.xlsx
    ..
    ### I deleted file in GIU (nemo) at this point ###
    ..
     dir/to/file > master > git status
    On branch master
    Your branch is up to date with 'origin/master'.
    
    Changes not staged for commit:
      (use "git add/rm <file>..." to update what will be committed)
      (use "git restore <file>..." to discard changes in working directory)
        deleted:    ~$Copy of Full Compilation of Databases for Audit.xlsx
    ..
     dir/to/file > master > git rm \~\$Copy\ of\ Full\ Compilation\ of\ Databases\ for\ Audit.xlsx
    rm 'dir/to/file/~$Copy of Full Compilation of Databases for Audit.xlsx'
     dir/to/file > master > git commit -a -m "fixing stupborn ghost "                                         
    [master b543cc14] fixing stupborn ghost
     1 file changed, 0 insertions(+), 0 deletions(-)
     delete mode 100755 dir/to/file/~$Copy of Full Compilation of Databases for Audit.xlsx
     dir/to/file > master > git push                                 
    Enumerating objects: 9, done.
    Counting objects: 100% (9/9), done.
    Delta compression using up to 6 threads
    Compressing objects: 100% (5/5), done.
    Writing objects: 100% (5/5), 425 bytes | 425.00 KiB/s, done.
    Total 5 (delta 4), reused 0 (delta 0)
    remote: Resolving deltas: 100% (4/4), completed with 4 local objects.
    To github.com:my/repo.git
       452981f2..b543cc14  master -> master
    ....
    me@wind_mach directory $ git pull
    Enter passphrase for key '/home/me/.ssh/id_rsa':
    ...
       452981f2..b543cc14  master     -> origin/master
    Updating 452981f2..b543cc14
    Fast-forward
     dir/to/file/~$Copy of Full Compilation of Databases for Audit.xlsx | Bin 165 -> 0 bytes
     1 file changed, 0 insertions(+), 0 deletions(-)
     delete mode 100755 Dir/to/file/~$Copy of Full Compilation of Databases for Audit.xlsx
    

    所以你有它。

    • 0

相关问题

  • 如何验证我使用 9.9.9.9 作为 DNS?

  • 并行安装多个 linux 发行版

  • du/df 和 ls 报告不同的磁盘使用情况

  • 自编译 OpenVPN 不会从 systemd 启动

  • Linux 内核开发人员如何处理数百万行代码的工作?他们是一种方法吗?[关闭]

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve