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
    • 最新
    • 标签
主页 / user-1438484

cocomac's questions

Martin Hope
cocomac
Asked: 2023-08-07 03:57:37 +0800 CST

如何从 Windows 10 访问运行 X11/Xorg 的 Ubuntu 计算机?

  • 5

我有一台运行 Windows 10(或 Windows 11)的笔记本电脑。我可以ssh使用 进入我的 Ubuntu 计算机ssh [email protected],但我想 (a) 使用 Windows 中的 GUI 应用程序或 (b) 使用 Windows 中的整个桌面。理想情况下,我想通过 X 转发而不是 VNC 或 RDP 来完成此操作。请注意,我在这里没有使用 Wayland。

我怎样才能做到这一点?

ssh
  • 1 个回答
  • 36 Views
Martin Hope
cocomac
Asked: 2022-01-26 19:55:00 +0800 CST

使用 || 时如何隐藏第一个命令的输出 运营商和退出?

  • 4

这会隐藏第一个命令的输出Oops,如果失败则打印到 stderr。到目前为止,一切都很好。

#!/usr/bin/env bash
invalid_command > /dev/null 2>&1 || >&2 echo "Oops"
echo hi

输出如下:

Oops
hi

但是如果第一个命令失败,我需要退出并打印一条消息。所以我尝试使用括号。

#!/usr/bin/env bash
invalid_command > /dev/null 2>&1 || ( >&2 echo "Oops" ; exit )
echo hi

这是它的输出:

Oops
hi

但是现在exit不起作用,因为它是在子shell中执行的,导致它 print hi,即使我希望脚本退出。

echo那么,如果特定命令使用操作符失败,我如何让 Bash 进入某些文本并退出||?我知道我可以使用单线来做到这一点,但如果可以避免的话if,我宁愿不必使用完整的声明。if

#!/usr/bin/env bash
if [ "$(invalid_command > /dev/null 2>&1 ; printf $?)" != "0" ]; then >&2 echo 'Oops' ; exit 1; fi
command-line
  • 1 个回答
  • 685 Views
Martin Hope
cocomac
Asked: 2022-01-24 13:29:09 +0800 CST

如何将 Git 使用的文本编辑器更改为 micro?

  • 0

我喜欢Micro 文本编辑器。我个人更喜欢它nano。然而,即使我已经安装了它,Git 默认为nano. 如何更改文本编辑器git commit使用的内容?

git
  • 1 个回答
  • 225 Views
Martin Hope
cocomac
Asked: 2022-01-04 14:14:36 +0800 CST

如何重新运行倒数第二个命令?

  • 16

我正在使用 Ubuntu 21.10。如果我搞砸了,我可以重新运行最后一个命令!!。这是一个例子:

$ apt update
Reading package lists... Done
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied)
W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)
$ sudo !!
sudo apt update
[sudo] password for [me]:
...
Fetched 336 kB in 2s (206 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
98 packages can be upgraded. Run 'apt list --upgradable' to see them.

没关系,但不是重新运行上一个命令,而是如何运行它之前的命令?像这样:

$ echo hi
hi
$ echo hello
hello
$ !!   <-- I'm trying to get that to run 'echo hi'
hello

基本上,这就是我要找的

$ echo hi
hi
$ echo hello
hello
$ ???   <-- What can I put here to get it to run 'echo hi'?
echo hello!
hello!

那么,鉴于!!运行最后一个命令,我如何在前一个命令之前运行该命令?在我的示例中,!!我可以运行什么来执行echo hi?

command-line
  • 4 个回答
  • 3494 Views
Martin Hope
cocomac
Asked: 2021-12-22 12:20:50 +0800 CST

弄乱关键目录的权限后如何修复 Ubuntu?

  • 1

所以我以 root 身份运行了一个愚蠢的命令(不要运行)

# chown -R root:root /{usr,lib,var,etc,bin,sbin,tools}

所以……哎呀。我碰巧打开了一个root shell(从我造成这个的时候开始),所以我可以sudo通过做

# chown root:root /usr/bin/sudo
# chmod 4755 /usr/bin/sudo

耶,sudo又工作了。我想安装一个包(ncdu),所以我跑了sudo apt-get install ncdu。

$ sudo apt-get install ncdu
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  ncdu
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/43.4 kB of archives.
After this operation, 106 kB of additional disk space will be used.
Selecting previously unselected package ncdu.
(Reading database ... 233654 files and directories currently installed.)
Preparing to unpack .../ncdu_1.15.1-1_amd64.deb ...
Unpacking ncdu (1.15.1-1) ...
Setting up ncdu (1.15.1-1) ...
Processing triggers for man-db (2.9.4-2) ...
/usr/bin/mandb: can't chmod /var/cache/man/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/es/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/es/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/es/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/zh_TW/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/zh_TW/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/zh_TW/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/fi/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/fi/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/fi/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/de/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/de/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/de/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/uk/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/uk/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/uk/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/sr/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/sr/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/sr/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/sl/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/sl/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/sl/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/nb/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/nb/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/nb/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/pt/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/pt/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/pt/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/ru/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/ru/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/ru/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/ko/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/ko/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/ko/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/it/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/it/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/it/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/fr/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/fr/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/fr/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/et/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/et/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/et/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/ca/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/ca/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/ca/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/tr/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/tr/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/tr/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/nl/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/nl/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/nl/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/fr.UTF-8/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/fr.UTF-8/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/fr.UTF-8/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/hu/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/hu/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/hu/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/fr.ISO8859-1/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/fr.ISO8859-1/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/fr.ISO8859-1/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/sv/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/sv/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/sv/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/id/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/id/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/id/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/el/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/el/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/el/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/pt_BR/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/pt_BR/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/pt_BR/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/ro/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/ro/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/ro/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/zh_CN/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/zh_CN/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/zh_CN/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/cs/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/cs/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/cs/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/gl/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/gl/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/gl/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/da/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/da/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/da/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/pl/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/pl/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/pl/1053532: Permission denied
/usr/bin/mandb: can't chmod /var/cache/man/ja/CACHEDIR.TAG: Operation not permitted
/usr/bin/mandb: can't remove /var/cache/man/ja/CACHEDIR.TAG: Permission denied
/usr/bin/mandb: fopen /var/cache/man/ja/1053532: Permission denied

显然我没有做足够的事情来修复我的系统。如果可能的话,我不想重新安装操作系统,但我有一个 root shell(它是我面前的一台物理笔记本电脑),所以我想知道如何修复apt,以便我可以再次安装包。我正在使用 Kubuntu 21.10。

permissions
  • 1 个回答
  • 211 Views
Martin Hope
cocomac
Asked: 2021-12-20 17:05:25 +0800 CST

如何停止 GUI(在 Kubuntu 21.10 中)

  • 7

我需要停止 GUI 并访问 NVIDIA 驱动程序的 TTY。我发现了这个问题。但是,当我尝试sudo service lightdm stop(或与 相同gdm)时,它说:

$ sudo service lightdm stop
Failed to stop lightdm.service: Unit lightdm.service not loaded.
$ sudo service gdm stop
Failed to stop gdm.service: Unit gdm.service not loaded.

我不想搞乱 Grub,因为我只需要停止 GUI 一次。那么,如何阻止 GUI 使用在 Kubuntu 21.10 中根本没有运行 GUI 的 TTY?

注意:我知道如何访问 TTY。但是一旦我在 TTY 中,我需要停止 GUI,因为 NVIDIA 驱动程序安装程序希望我在 TTY中并且 GUI not running。

nvidia
  • 4 个回答
  • 1331 Views
Martin Hope
cocomac
Asked: 2021-10-21 17:05:13 +0800 CST

如何检查命令是否失败......使用管道?

  • 8

所以我有一个这样的脚本:

somecommad | grep --invert-match something

somecommand如果失败,我希望能够有条件地运行不同的命令。这是我尝试过的:

somecommand | grep --invert-match something || {
    echo 'Oops'
}

但这没有用(grep没有执行)。这样做的正确方法是什么?

command-line
  • 2 个回答
  • 4092 Views

Sidebar

Stats

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

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve