0

运行字符串搜索/替换搜索并考虑到这些文件中可能包含一些字符串,sed 是否会因为二进制类型结构而忽略它们,或者它们会破坏函数吗?

4

1 回答 1

0

This is really a "try it and see what happens" sort of question, so...

  • Start with a copy of the wtmp file.

    $ cp /var/log/wtmp wtmp.work
    
  • Look at it using who:

    $ who wtmp.work
    lars     pts/2        2012-10-23 10:58 (:0)
    lars     pts/2        2012-10-23 11:01 (:0)
    lars     pts/2        2012-10-23 11:11 (:0)
    lars     pts/2        2012-10-23 11:43 (:0)
    lars     pts/2        2012-10-23 12:41 (:0)
    lars     pts/2        2012-10-23 12:41 (:0)
    
  • Let's try placing "lars" with "superman":

    $ sed -i s/lars/superman/ wtmp.work
    
  • And see what happened:

    $ who wtmp.work
    superman pts/7        1969-12-31 19:00
    

Oops.

Hopefully that answers your question!

于 2012-12-18T03:43:54.527 回答