简体   繁体   English

要求使用grep命令的分配,如果使用find命令合适,我将如何编写命令?

[英]Assignment asking to use grep command, how would I write a command when it is fine with the find command?

My Intro to OS teacher wants me to enter a command that long lists the /etc directory and finds all files modified or created with the size of 4096 bytes. 我的OS入门教师希望我输入一个长于/ etc目录的命令,并查找所有修改或创建的4096字节大小的文件。

My answer is simply find /etc -size 4k -ls . 我的答案只是find /etc -size 4k -ls

How am I supposed to use the grep command to do this? 我应该如何使用grep命令执行此操作? It seems kind of pointless... 似乎毫无意义...

It sure makes no sense but in IT you kind of get used to insane seeming requirements so here is one: 这肯定没有任何意义,但是在IT领域,您已经习惯了疯狂的看似要求,因此这里是一个:

$ ls -l /etc | grep "^-\([^ ]* *\)\{4\}4096 "
-rw-r--r--  1 root     root            4096 Oct 27  2014 wgetrc
  • ^- it's a file ( ^d for dir etc.) ^-这是一个文件(dir的^d等)
  • [^ ]* * field and delimiting space(s) [^ ]* *字段和定界空格
  • \\(...\\)\\{4\\} four times previous, ie. \\(...\\)\\{4\\}四次,即 filesize is in the fifth field 文件大小在第五个字段中
  • 4096 filesize. 4096文件大小。 Notice the trailing space to limit the size exactly to 4096. 请注意尾随空格以将大小精确限制为4096。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM