我正在学习Ubuntu中的lsblk和mount命令。我使用Linode服务器,2CPU,4GB内存,附加了一个额外的块存储卷。
我有两个与这个问题有关的问题。
首先,我运行了lsblk命令:
michal@ubuntu:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 79.5G 0 disk /
sdb 8:16 0 512M 0 disk [SWAP]
sdc 8:32 0 50G 0 disk /mnt/movies在这里我什么都懂。
sda和sdb都是我的默认分区,当我第一次创建linode时,sdc是我后来附加的块存储卷。
然后我使用mount运行了grep命令,如下所示:
michal@ubuntu:~$ mount | grep sda
/dev/sda on / type ext4 (rw,relatime,errors=remount-ro)
michal@ubuntu:~$ mount | grep sdb
michal@ubuntu:~$ mount | grep sdc
/dev/sdc on /mnt/movies type ext4 (rw,relatime)
michal@ubuntu:~$mount | grep sdb不返回输出??这是我的[SWAP]分区。然后我跑了:
michal@ubuntu:~$ mount | grep sd?
michal@ubuntu:~$
michal@ubuntu:~$mount | grep sd?不返回输出??发布于 2022-12-20 12:06:50
swap不是一个文件系统,它没有挂载,它被激活或停用(参见man swapon)。挂载点不存在。在/etc/fstab中,挂载点被指定为none。由于没有挂载swap,所以我不希望交换分区出现在mount或findmnt的输出中。
mount | grep sdb没有提供输出,因为字符串sdb没有出现在mount-output中。请记住,/dev/sdb是您的交换,它没有挂载。
mount | grep sd?没有提供输出,因为字符串sd?没有出现在mount-output中。名为sd?的驱动器不存在,就像这样简单。如果您希望grep将sd?视为扩展正则表达式,您将使用mount | grep -E sd?,并且您的输出不会是空的,但它可能不是您所期望的,因为?的含义在regex和globbing中有很大不同。
mount | grep "/dev/sd"是您在这里所需要的输出。
更多细节:
来自info grep第2.4章“grep”程序:
’-G’
‘--basic-regexp’
Interpret patterns as basic regular expressions (BREs). This is
the default.从info grep第3.6章基本正则表达式到扩展正则表达式:
Basic vs Extended Regular Expressions
In basic regular expressions the meta-characters ?, +, {, |, (, and ) lose
their special meaning; instead use the backslashed versions
\?, \+, \{, \|, \(, and \).
Portable scripts should avoid the following constructs, as POSIX says
they produce undefined results:
...
• Basic regular expressions that use ‘\?’, ‘\+’, or ‘\|’.
...但是,即使我使用\?,它也不像我所期望的那样工作,mount | grep sd\?仍然提供空的输出,这绝对不应该是这样的。它只为我提供了-E-option的预期输出,不管有没有反斜杠。可能这是个窃听器。
https://askubuntu.com/questions/1446408
复制相似问题