简体   繁体   中英

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.

My answer is simply find /etc -size 4k -ls .

How am I supposed to use the grep command to do this? 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:

$ 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.)
  • [^ ]* * field and delimiting space(s)
  • \\(...\\)\\{4\\} four times previous, ie. filesize is in the fifth field
  • 4096 filesize. Notice the trailing space to limit the size exactly to 4096.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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