在研究另一个问题时,我遇到了一个命令,
locate something | xargs -I {} bash -c "if [ -d "{}" ]; then echo {}; fi"
Run Code Online (Sandbox Code Playgroud)
我想了解更多。所以我运行man xargs
并得到以下输出:
XARGS(1) General Commands Manual XARGS(1)
NAME
xargs - build and execute command lines from standard input
SYNOPSIS
xargs [-0prtx] [-E eof-str] [-e[eof-str]] [--eof[=eof-str]] [--null]
[-d delimiter] [--delimiter delimiter] [-I replace-str] [-i[replace-
str]] [--replace[=replace-str]] [-l[max-lines]] [-L max-lines]
[--max-lines[=max-lines]] [-n max-args] [--max-args=max-args] [-s max-
chars] [--max-chars=max-chars] [-P max-procs] [--max-procs=max-procs]
[--interactive] [--verbose] [--exit] [--no-run-if-empty]
[--arg-file=file] [--show-limits] [--version] [--help] [command …
Run Code Online (Sandbox Code Playgroud) 我们希望在 Linux 文件系统中存储数百万个文本文件,目的是能够压缩并将任意集合作为服务提供服务。我们尝试了其他解决方案,例如键/值数据库,但我们对并发性和并行性的要求使使用本机文件系统成为最佳选择。
最直接的方法是将所有文件存储在一个文件夹中:
$ ls text_files/
1.txt
2.txt
3.txt
Run Code Online (Sandbox Code Playgroud)
这在 EXT4 文件系统上应该是可能的,它对文件夹中的文件数量没有限制。
这两个 FS 进程将是:
我的问题是,在一个文件夹中存储多达 1000 万个文件是否会影响上述操作的性能或一般系统性能,这与为这些文件创建子文件夹树有什么不同?
我刚开始学习Linux 上的一切都是文件TM,这让我想知道如果我真的从 /dev/stdout 读取会发生什么:
$ cat /dev/stdout
^C
$ tail /dev/stdout
^C
Run Code Online (Sandbox Code Playgroud)
(这^C
是我在程序挂起后杀死程序)。
当我尝试使用 时vim
,我收到了不可思议的消息:“/dev/stdout”不是文件。喘气!
那么,当我尝试阅读这些“文件”时,为什么会出现挂断或错误消息?
一个常见的场景是在一个目录中有一个包含其他工作的 zip 文件:
me@work ~/my_working_folder $ ls
downloaded.zip workfile1 workfile2 workfile3
Run Code Online (Sandbox Code Playgroud)
我想解压缩downloaded.zip
,但我不知道它是否会弄得一团糟,或者它是否很好地创建了自己的目录。我正在进行的解决方法是创建一个临时文件夹并将其解压缩到那里:
me@work ~/my_working_folder $ mkdir temp && cp downloaded.zip temp && cd temp
me@work ~/my_working_folder/temp $ ls
downloaded.zip
me@work ~/my_working_folder/temp $ unzip downloaded.zip
Archive: downloaded.zip
creating: nice_folder/
Run Code Online (Sandbox Code Playgroud)
这可以防止my_working_folder
填充大量 zip 文件内容。
我的问题是:有没有更好的方法来确定一个 zip 文件在解压前是否只包含一个文件夹?
我有一个包含三个文件的文件夹:
$ ls
a b c
Run Code Online (Sandbox Code Playgroud)
如果我将ls
to的输出通过管道传输wc
,我会得到正确的结果:
$ ls | wc -l
3
Run Code Online (Sandbox Code Playgroud)
但是,当我将 to 的输入指定wc
为 的输出时ls
,我会得到额外的文本:
$ wc -l <(ls)
3 /dev/fd/63
Run Code Online (Sandbox Code Playgroud)
谁能向我解释发生了什么?
我用手机拍了两张照片,一张横拍,一张竖拍,它们在侏儒之眼中表现得很好。当我尝试使用 ImageMagick 的转换将它们从上到下粘合时:
$ convert img1.jpg img2.jpg +append both.jpg
Run Code Online (Sandbox Code Playgroud)
水平的在被附加之前旋转为垂直。如果我将它们与-append
选项并排放置,也会发生同样的事情。
如何convert
将一个图像附加到另一个图像而不将它们旋转到相同的尺寸?
安装最新版本的 Kile 后,尝试运行它会因分段错误而崩溃:
$ kile
qt5ct: using qt5ct plugin
Invalid Context= "Apps" line for icon theme: "/usr/share/icons/Mint-Y/apps/16/"
Invalid Context= "Apps" line for icon theme: "/usr/share/icons/Mint-Y/apps/16@2x/"
Invalid Context= "Mimetypes" line for icon theme: "/usr/share/icons/Mint-Y/mimetypes/16/"
Invalid Context= "Mimetypes" line for icon theme: "/usr/share/icons/Mint-Y/mimetypes/16@2x/"
Invalid Context= "Apps" line for icon theme: "/usr/share/icons/Mint-Y/apps/22/"
Invalid Context= "Apps" line for icon theme: "/usr/share/icons/Mint-Y/apps/22@2x/"
Invalid Context= "Apps" line for icon theme: "/usr/share/icons/Mint-Y/apps/24/"
Invalid Context= "Apps" line for icon theme: "/usr/share/icons/Mint-Y/apps/24@2x/"
Invalid Context= "Mimetypes" line for icon theme: …
Run Code Online (Sandbox Code Playgroud) 从手册页history
:
\n\n\n事件指示符\n 事件指示符是对历史列表中命令行条目的引用。除非引用是绝对的,否则事件是相对于历史列表中的当前位置的。
\n
! Start a history substitution, except when followed by a blank,\n newline, = or (.\n !n Refer to command line n.\n !-n Refer to the current command minus n.\n !! Refer to the previous command. This is a synonym for `!-1\'.\n !string\n Refer to the most recent command preceding the current position\n in the history list starting with string.\n !?string[?]\n Refer to the most recent command preceding the current position\n in …
Run Code Online (Sandbox Code Playgroud) 当我使用 Unetbootin 将 Linux ISO 放在 USB 驱动器上时,它进行得非常快,直到它到达filesystem.squashfs
,这比其他所有东西加起来需要更长的时间来处理。
这是在向 USB 写入一个新的文件系统,还是在复制一些巨大的文件系统相关文件?如果是这样,如果我将尝试许多发行版并希望加快这一步,有没有办法只做一次?
对于具有像此示例这样的行的初始文件:
1
12
123
1234
12345
Run Code Online (Sandbox Code Playgroud)
文件的期望状态是
'1'
'12'
'123'
'1234'
'12345'
Run Code Online (Sandbox Code Playgroud)
我已经有两个命令这样做,:%s/^/'/g
而且:%s/$/'/g
,我想进入一个。但是,当我尝试
:%s/[$^]/'/g
Run Code Online (Sandbox Code Playgroud)
我收到错误
E486: Pattern not found: [$^]
Run Code Online (Sandbox Code Playgroud)
我知道^
括号中的领先意味着排除,所以我认为$
首先意味着匹配行的开头和结尾,这显然不会发生。
如何在vim中匹配行的开头和结尾?
我通过使用-X
(或-Y
)标志进行 SSH 连接来打开 GUI 远程程序,例如,
$ ssh -Y user@host.com
Run Code Online (Sandbox Code Playgroud)
最近,我发现有一种更有效的方法可以仅通过网页浏览来做到这一点:
$ ssh -DNNNN user@host.com
Run Code Online (Sandbox Code Playgroud)
其中NNNN
是四位数的端口号。然后我将本地浏览器配置为通过端口 NNNN 通过代理连接。这比第一种 SSH 方法效率高得多,因为不需要通过隧道传输所有 GUI 信息,只需传输我请求的 Web 数据。
我的问题是:一般来说,是否有更有效的方式使用 X 转发进行 SSH?也许某种利用本地库或渲染或其他东西来帮助操作远程托管的 GUI 程序的方案?
我正在运行一台“信息亭”计算机——一个供房间内任何人通用的计算机——我想知道是否有人真的在使用它。是否有日志告诉我 Firefox、Chrome 或其他程序何时运行?
我不是要求他们在程序中做什么的日志,只是他们是否被使用。
欢迎任何其他想法。
我有一个包含三个文件和基本内容的文件夹:
$ tail *
==> file1 <==
file 1 contents
==> file2 <==
file 2 contents
==> file3 <==
file 3 contents
Run Code Online (Sandbox Code Playgroud)
我想使用cat
. 我尝试像这样使用它:
$ ls -ctr | tail -1
file3
$ ls -ctr | tail -1 | cat
file3
Run Code Online (Sandbox Code Playgroud)
但正如您所看到的,它只打印最后一个文件的名称。我认为管道会获取输出tail
并处理具有该名称的文件,就像使用 subshell 命令一样:
$ cat $(ls -ctr | tail -1)
file 3 contents
Run Code Online (Sandbox Code Playgroud)
为什么重定向方法不起作用,有没有办法用管道而不是子外壳来实现这一点?
files ×2
filesystems ×2
man ×2
performance ×2
pipe ×2
bash ×1
cat ×1
command-line ×1
cpu-usage ×1
ext4 ×1
imagemagick ×1
images ×1
input ×1
kde ×1
kile ×1
kiosk ×1
linux ×1
linux-mint ×1
logs ×1
monitoring ×1
squashfs ×1
ssh ×1
stdout ×1
subshell ×1
unetbootin ×1
vim ×1
xforwarding ×1
zip ×1