小编dot*_*hen的帖子

为什么在复制有限大小的设备时指定块大小?

在在线教程中,通常建议使用以下命令将 CDROM 复制到 ISO 映像:

$ dd if=/dev/dvd of=foobar.iso bs=2048
Run Code Online (Sandbox Code Playgroud)

为什么必须指定字节大小?我注意到实际上 2048 是CDROM 映像标准字节大小,但似乎dd没有指定bs=或也count=可以工作。

在什么情况下指定bs=count=从有限大小的设备复制会出现问题?

linux dd cloning hard-disk

22
推荐指数
3
解决办法
3万
查看次数

为什么“查找”不显示此文件?

使用findwith grep,可以定位匹配模式的文件:

# find | grep error
./solr-modifiedSolr4/SolrPhpClient/phpdocs/errors.html
./error_log
./includes/classes/error_log
Run Code Online (Sandbox Code Playgroud)

但是,find单独使用找不到第一个文件:

# find . -name error*
./error_log
./includes/classes/error_log
Run Code Online (Sandbox Code Playgroud)

为什么不使用 with 时find找不到errors.html文件grep?如何find用于显示此文件?

shell find quoting wildcards

21
推荐指数
1
解决办法
1823
查看次数

如何在同一个分区上挂载多个目录?

我安装了SSD,并希望把/对SSD和/home/var/tmp在硬盘上。我当前的发行版是 Kubuntu,但如果可以更轻松地完成此过程,我不介意尝试另一个发行版。我已经在多个分区上安装了许多不同的 Linux 操作系统,但是我知道没有安装程序可以让一个人在单个分区上安装多个目录。我宁愿不使用三个单独的分区,特别是/home,/var/tmp容易发生大的大小变化,并且为每个分区分配一些任意的最大值是不切实际的。

请注意,我正在讨论新安装,而不是将当前系统移至 SSD / HD 拆分。

linux partition system-installation

19
推荐指数
1
解决办法
3万
查看次数

列表中的 grep 文件

我正在尝试针对几百个文件的列表运行 grep:

$ head -n 3 <(cat files.txt)
admin.php
ajax/accept.php
ajax/add_note.php
Run Code Online (Sandbox Code Playgroud)

但是,即使我正在搜索我知道在文件中找到的字符串,以下内容也不会搜索文件:

$ grep -i 'foo' <(cat files.txt)

$ grep -i 'foo' admin.php
The foo was found
Run Code Online (Sandbox Code Playgroud)

我熟悉从文件中-f读取模式的标志。但是如何读取输入文件

我曾考虑过将文件复制到cp似乎支持该<(cat files.txt)格式的临时目录的可怕解决方法,然后从那里 grep 文件。雪莉还有更好的办法。

grep bash command-substitution process-substitution

19
推荐指数
4
解决办法
6万
查看次数

iostat:等待与 svctm

iostat联机帮助页中,我发现了这两个类似的列:

await
    The average time (in milliseconds) for I/O requests issued to the device to be  served.  This
    includes the time spent by the requests in queue and the time spent servicing them.

svctm
    The  average  service time (in milliseconds) for I/O requests that were issued to the device.
    Warning! Do not trust this field any more.  This field will be removed in  a  future  sysstat
    version.
Run Code Online (Sandbox Code Playgroud)

这些列是否代表同一件事?我似乎有时他们同意,但有时不同意:

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           4.44    0.02    1.00 …
Run Code Online (Sandbox Code Playgroud)

linux monitoring io

17
推荐指数
1
解决办法
5万
查看次数

删除文件 A 中包含文件 B 中字符串的所有行

我有一个users.csv包含用户名、用户 ID 和其他数据列表的CSV 文件:

username, userid, sidebar_side, sidebar_colour
"John Lennon", 90123412, "left", "blue"
"Paul McCartny", 30923833, "left", "black"
"Ringo Starr", 77392318, "right", "blue"
"George Harrison", 72349482, "left", "green"
Run Code Online (Sandbox Code Playgroud)

在另一个文件中,toremove.txt我有一个用户 ID 列表:

30923833
77392318
Run Code Online (Sandbox Code Playgroud)

有没有一种聪明、有效的方法来从users.csv文件中删除包含 ID 的所有行toremove.txt?我编写了一个简单的 Python 应用程序来解析这两个文件,并只将那些在toremove.txt. 也许一些sedawk魔法可以帮助这里?

考虑到上述示例,这是预期的结果:

username, userid, sidebar_side, sidebar_colour
"John Lennon", 90123412, "left", "blue"
"George Harrison", 72349482, "left", "green"
Run Code Online (Sandbox Code Playgroud)

linux command-line text-processing

16
推荐指数
1
解决办法
2万
查看次数

为什么 systemd-udev 盯住我的 CPU?

我注意到四核笔记本电脑上的一个核心是固定的,并且温度非常高。我在top

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
  359 root      20   0  188684 147228   1552 R  99.4  5.0 111:19.91 systemd-udevd
20011 root      20   0  188320 147604   2076 S  11.0  5.0   0:00.33 systemd-udevd
11053 dotanco+  20   0 3030036 918672  49608 S   9.6 31.2 280:40.65 firefox
 3468 dotanco+  20   0 3612776 136740  43484 S   1.7  4.6  57:02.52 plasma-desktop
20006 root      20   0       0      0      0 Z   1.0  0.0   0:00.37 systemd-udevd
Run Code Online (Sandbox Code Playgroud)

为什么可能systemd-udev会敲打 CPU?这是一个 Kubuntu …

systemd cpu-usage

16
推荐指数
4
解决办法
4万
查看次数

自动完成最新文件

我有一个创建文本文件的过程,其文件名基于其创建时刻的时间戳:

$ ls
1378971222.txt
1378971254.txt
1378971482.txt
1378971488.txt
1378972089.txt
1378972140.txt
1378972141.txt
1378972153.txt
1378972155.txt
1378972241.txt
Run Code Online (Sandbox Code Playgroud)

我如何自动完成最新创建的文件的文件名,即具有最新 mtime 的文件?无法对这些文件使用制表符补全,因为文件名中的几乎每个字符都与另一个文件共享。我希望找到一个快捷方式(例如Alt .自动完成最后一个命令的最后一个参数)。我已成功地炮制以下别名这是伟大的VIM,但我很想知道,如果一个通用的快捷方式存在,我可以用用kde-opensqlite3和其他应用程序。

alias lastest="vim `ls -t | grep -vE "^total [0-9]*$" | head -n1`"
Run Code Online (Sandbox Code Playgroud)

bash autocomplete

15
推荐指数
3
解决办法
1263
查看次数

Nmap -sn:扫描还是不扫描?

nmap手册页有这样说的-sn参数:

-sn (No port scan) .
    This option tells Nmap not to do a port scan after host
    discovery, and only print out the available hosts that
    responded to the scan.
Run Code Online (Sandbox Code Playgroud)

前半句说没有扫描,后半句说有扫描。是否有与后半部分所指的端口扫描不同的扫描类型?也许是主机发现扫描(根据我所知道的一点点猜测nmap)?

man nmap

14
推荐指数
2
解决办法
2万
查看次数

注释从最后注释行到'foo'行的所有行

考虑一个文本文件users.txt

#alice
#bob
charlie
dotan
eric
Run Code Online (Sandbox Code Playgroud)

我需要评论从 (exclusive) 最后一条评论行到 (inclusive) 的所有内容dotan。这是结果:

#alice
#bob
#charlie
#dotan
eric
Run Code Online (Sandbox Code Playgroud)

有没有一个不错的sedoneliner可以做到这一点?我会对任何工具感到满意,而不仅仅是sed,真的。

目前我正在获取最后评论行的行号,如下所示:

$ cat -n users.txt | grep '#' | tail -n1
  2 #bob
Run Code Online (Sandbox Code Playgroud)

然后我添加一个并评论sed

$ sed -i'' '3,/dotan/ s/^/#/' users.txt
Run Code Online (Sandbox Code Playgroud)

我知道我可以很聪明,把这一切和一些bc东西放在一起,做成一个丑陋的单线。当然必须有更清洁的方法吗?

sed text-processing

12
推荐指数
2
解决办法
321
查看次数