我有一个 html 类型的文件,它在某处包含一个标签,如下所示:
<Currentnumber>0.3.5</Currentnumber>
Run Code Online (Sandbox Code Playgroud)
如何在变量中捕获值0.3.5
并且仅捕获此值?
我已经按照以下方式对线路进行了搜索:
grep -E "<Currentnumber>.*</Currentnumber>$" myfile
Run Code Online (Sandbox Code Playgroud)
如果出于教育目的,任何答案也提供了对所用grep
参数的解释,我将不胜感激。
请注意,该行以一些空格(或制表符)开头,这就是为什么以下内容不起作用
grep -E "^<Currentnumber>.*</Currentnumber>$" myfile
Run Code Online (Sandbox Code Playgroud) 考虑到它们产生相同的结果,在命令中使用-print
和-depth
参数有什么区别find
:
/home/pkaramol/Desktop/testdir
$ find .
.
./testfile3.txt
./testfile1.txt
./testfile4.txt
./testdir1
./testfile2.txt
./testdir2
/home/pkaramol/Desktop/testdir
$ find . -depth
./testfile3.txt
./testfile1.txt
./testfile4.txt
./testdir1
./testfile2.txt
./testdir2
.
/home/pkaramol/Desktop/testdir
$ find . -depth -print
./testfile3.txt
./testfile1.txt
./testfile4.txt
./testdir1
./testfile2.txt
./testdir2
.
Run Code Online (Sandbox Code Playgroud) 这两个工具,似乎报告不同的block
大小
root@ubuntu-xenial:~# df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 498588 0 498588 0% /dev
tmpfs 101584 3116 98468 4% /run
/dev/sda1 10098468 1438288 8643796 15% /
tmpfs 507916 0 507916 0% /dev/shm
tmpfs 5120 0 5120 0% /run/lock
tmpfs 507916 0 507916 0% /sys/fs/cgroup
vagrant 343946960 55977016 287969944 17% /vagrant
tmpfs 101584 0 101584 0% /run/user/1000
root@ubuntu-xenial:~# dumpe2fs /dev/sda1 | grep -i block | grep -i size
dumpe2fs 1.42.13 (17-May-2015)
Block size: 4096
Flex block group …
Run Code Online (Sandbox Code Playgroud) 我想要grep
一个特定的内核设置如下
$ sudo sysctl -a --ignore | grep -i max_map_count 2>/dev/null
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.docker0.stable_secret"
sysctl: reading key "net.ipv6.conf.enp2s0.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
sysctl: reading key "net.ipv6.conf.wlp3s0.stable_secret"
vm.max_map_count = 262144
Run Code Online (Sandbox Code Playgroud)
由于我既忽略了关于未知键的信息(即--ignore
选项),又将潜在的错误输出重定向到/dev/null
,这些reading jey
行打印了什么?
我正在阅读一些关于 LSM 实现的入门,所以最终我会深入研究AppArmor
和SELinux
.
我知道这个讨论,但这并没有说明我对这两个 LSM 实现的一个问题:
事实是否如此:
auto-relabeling
首次启动的过程与文件系统扫描所需的时间一样长)(?)
我正在尝试使用以下命令验证文件:
$ md5sum myfile_v2.1.ova -c myfile_v2.1.md5
md5sum: myfile_v2.1.ova: no properly formatted MD5 checksum lines found
myfile_v2.1.ova: OK
Run Code Online (Sandbox Code Playgroud)
退出状态代码似乎是 1
$ echo $?
1
Run Code Online (Sandbox Code Playgroud)
然而读出时help
的md5sum
命令,strict
模式(其将失败时格式化issues`)应当明确启用;
$ md5sum --help | grep -- --strict
--strict exit non-zero for improperly formatted checksum lines
Run Code Online (Sandbox Code Playgroud)
为什么最重要的是我得到了一个OK
关于文件的信息?
尽管有以下帮助指令:
root@Andromeda:/# du --help | grep -- -x
-x, --one-file-system skip directories on different file systems
Run Code Online (Sandbox Code Playgroud)
下面的查询继续检查例如/proc
这是一个不同的文件系统
root@Andromeda:/# du -schx *
13M bin
104M boot
4,0K cdrom
0 dev
16M etc
85G home
0 initrd.img
0 initrd.img.old
802M lib
4,0K lib64
16K lost+found
28K media
4,0K mnt
324M opt
du: cannot access 'proc/8303/task/8303/fd/4': No such file or directory
du: cannot access 'proc/8303/task/8303/fdinfo/4': No such file or directory
du: cannot access 'proc/8303/fd/3': No such file or directory
du: cannot …
Run Code Online (Sandbox Code Playgroud) 在以下示例中:
apt-file search apache2.conf | grep -E "apache2.conf\b"
Run Code Online (Sandbox Code Playgroud)
输出:
apache2: /etc/apache2/apache2.conf
apache2-doc: /usr/share/doc/apache2-doc/examples/apache2/apache2.conf.gz
dicoweb: /etc/dicoweb/apache2.conf
emboss-explorer: /etc/apache2/conf-available/emboss-explorer.apache2.conf
emboss-explorer: /etc/emboss-explorer/apache2.conf
icinga-cgi: /usr/share/doc/icinga-cgi/examples/apache2.conf
icinga-cgi: /usr/share/icinga/apache2.conf
icinga2-classicui: /etc/icinga2-classicui/apache2.conf
kopano-webapp-apache2: /etc/apache2/conf-available/kopano-webapp-apache2.conf
kopano-webapp-apache2: /etc/kopano/webapp/apache2.conf
lacme: /etc/lacme/apache2.conf
lemonldap-ng-handler: /etc/apache2/sites-available/handler-apache2.conf
libjs-twitter-bootstrap: /usr/share/twitter-bootstrap/apache2.conf
liblemonldap-ng-manager-perl: /etc/apache2/sites-available/manager-apache2.conf
liblemonldap-ng-portal-perl: /etc/apache2/sites-available/portal-apache2.conf
mirmon: /usr/share/doc/mirmon/examples/mirror-apache2.conf
nagios3-cgi: /usr/share/nagios3-cgi/apache2.conf
oar-restful-api: /usr/share/oar/oar-api/apache2.conf
octopussy: /etc/octopussy/apache2.conf
spip: /usr/share/doc/spip/apache2.conf
Run Code Online (Sandbox Code Playgroud)
为什么不grep
理解\b
as 词边界并合并这一行:
apache2-doc: /usr/share/doc/apache2-doc/examples/apache2/apache2.conf.gz
Run Code Online (Sandbox Code Playgroud)
相同的结果具有和不具有的延伸(使用发生-E
的)版本grep
。