ls: terminated by signal 13 when using xargs

后端 未结 3 756
梦谈多话
梦谈多话 2020-12-20 10:38

I\'m using the following command to delete four largest size files in a folder:

find \"/var/www/site1/\" -maxdepth 1 -type f | xargs ls -1S | head -n 4 | xar         


        
3条回答
  •  失恋的感觉
    2020-12-20 11:34

    I got the same error, "terminated by signal 13", under different circumstances and other answers here helped me work out the fix. I'd like to expand on the nature of the problem:

    corpy386 ~/gw/Release/5.1_v9/ClaimCenter $ find . -name '*.pcf' -not -name '*build*' | xargs grep -l ClaimSnapshotGeneralPanelSet | ( read f && echo $f && grep 'def=' $f )
    ./modules/configuration/build/idea/classes/web/pcf/claim/snapshot/default/ClaimSnapshotGeneralPanelSet.auto.pcf
              def="AddressSnapshotInputSet(Snapshot.LossLocation, Snapshot)"
    xargs: grep: terminated by signal 13
    

    So here's the same error and I'd only get a single line of output when I knew there are numerous files that match what I'm looking for. The problem was that xargs is producing multiple lines of output and read is only consuming a single line before ending. xargs tries to write the rest of its results to one of the pipes but the receiving end has already quit and gone home. Hence, signal 13: Broken Pipe.

    The fix was to consume all of xargs's output by looping - change read f && do_some_things (which reads one time only) to while read f; do do_some_things; done.

    corpy386 ~/gw/Release/5.1_v9/ClaimCenter $ **find . -name '*.pcf' -not -name '*build*' | xargs grep -l ClaimSnapshotGeneralPanelSet | while read f; do echo $f; grep 'def=' $f; done**
    ./modules/configuration/build/idea/classes/web/pcf/claim/snapshot/default/ClaimSnapshotGeneralPanelSet.auto.pcf
              def="AddressSnapshotInputSet(Snapshot.LossLocation, Snapshot)"
    ./modules/configuration/build/idea/classes/web/pcf/claim/snapshot/default/ClaimSnapshotGeneralPanelSet.gl.pcf
              def="AddressSnapshotInputSet(Snapshot.LossLocation, Snapshot)"
    ./modules/configuration/build/idea/classes/web/pcf/claim/snapshot/default/ClaimSnapshotGeneralPanelSet.Pr.pcf
          def="ClaimSnapshotGeneralPRPanelSet(Claim, Snapshot)"
    ./modules/configuration/build/idea/classes/web/pcf/claim/snapshot/default/ClaimSnapshotGeneralPanelSet.Trav.pcf
              def="AddressSnapshotInputSet(Snapshot.LossLocation, Snapshot)"
    ./modules/configuration/build/idea/classes/web/pcf/claim/snapshot/default/ClaimSnapshotGeneralPanelSet.wc.pcf
              def="AddressSnapshotInputSet(Snapshot.LossLocation, Snapshot)"
    ./modules/configuration/build/idea/classes/web/pcf/claim/snapshot/default/ClaimSnapshotLossDetailsScreen.default.pcf
          def="ClaimSnapshotGeneralPanelSet(Claim, SnapshotParam)"
    ./modules/configuration/config/web/pcf/claim/snapshot/default/ClaimSnapshotGeneralPanelSet.auto.pcf
              def="AddressSnapshotInputSet(Snapshot.LossLocation, Snapshot)"
    ./modules/configuration/config/web/pcf/claim/snapshot/default/ClaimSnapshotGeneralPanelSet.gl.pcf
              def="AddressSnapshotInputSet(Snapshot.LossLocation, Snapshot)"
    ./modules/configuration/config/web/pcf/claim/snapshot/default/ClaimSnapshotGeneralPanelSet.Pr.pcf
          def="ClaimSnapshotGeneralPRPanelSet(Claim, Snapshot)"
    ./modules/configuration/config/web/pcf/claim/snapshot/default/ClaimSnapshotGeneralPanelSet.Trav.pcf
              def="AddressSnapshotInputSet(Snapshot.LossLocation, Snapshot)"
    ./modules/configuration/config/web/pcf/claim/snapshot/default/ClaimSnapshotGeneralPanelSet.wc.pcf
              def="AddressSnapshotInputSet(Snapshot.LossLocation, Snapshot)"
    ./modules/configuration/config/web/pcf/claim/snapshot/default/ClaimSnapshotLossDetailsScreen.default.pcf
          def="ClaimSnapshotGeneralPanelSet(Claim, SnapshotParam)"
    

    This isn't exactly the same situation as OP's script - They wanted a part of the input and cut it off on purpose, I wanted the whole stream and cut it off by accident - but the shell semantics work out the same. Programs tend to be written to keep running until they have consumed all their input rather than test to see if their recipient is still listening.

提交回复
热议问题