Upgrade to Pro — share decks privately, control downloads, hide ads and more …

UNIXコマンド抜き打ちテストやります! #loupestudy

08f1ea0292e0229e5d0415d1e9b5c9ee?s=47 sue738
December 01, 2014

UNIXコマンド抜き打ちテストやります! #loupestudy

LOUPE Study11回です
エンジニア初心者向けにUNIXコマンドでどんな事ができるのかを知ってもらうためにテスト形式で話しました

過去のLOUPE Studyはこちらから
http://lo-upe.hatenablog.com/

08f1ea0292e0229e5d0415d1e9b5c9ee?s=128

sue738

December 01, 2014
Tweet

Transcript

  1. 6/*9ίϚϯυ ൈ͖ଧͪςετ΍Γ·͢ʂ LOUPE Study#11 ຤Ӭ ণ໵

  2. ໰1: ԿΛ͢ΔίϚϯυ? mkdir diff find grep cal history curl which

    sed bc
  3. ໰1: ԿΛ͢ΔίϚϯυ? mkdir diff find grep cal history curl which

    sed bc σΟϨΫτϦ࡞੒ ࠩ෼දࣔ ϑΝΠϧݕࡧ ύλʔϯϚον ΧϨϯμʔදࣔ ίϚϯυཤྺදࣔ σʔλऔಘ ίϚϯυ͕Ͳ͜ʹଘࡏ ςΩετஔ׵ ܭࢉػ
  4. ίϚϯυϥΠϯ͚ͩͰ΋ ͍ΖΜͳࣄ͕ՄೳͰ͢

  5. ໰2: ΧϨϯτσΟϨΫτϦҎԼͰ UserMailer͕࢖ΘΕ͍ͯΔॴΛ୳͢ʹ͸ʁ ᵓᴷᴷ app ᴹ ᵓᴷᴷ assets ᴹ ᵓᴷᴷ

    controllers ᴹ ᵓᴷᴷ models ᴹ ᵓᴷᴷ vires
  6. ໰2: ΧϨϯτσΟϨΫτϦҎԼͰ UserMailer͕࢖ΘΕ͍ͯΔॴΛ୳͢ʹ͸ʁ $ grep -r UserMailer .

  7. ໰2: ΧϨϯτσΟϨΫτϦҎԼͰ UserMailer͕࢖ΘΕ͍ͯΔॴΛ୳͢ʹ͸ʁ $ grep -r UserMailer . Φϓγϣϯ

  8. $ grep -h $ man grep

  9. ίϚϯυ࢖͏࣌ศརͳ ΦϓγϣϯΛ୳ͯ͠ΈΑ͏

  10. ໰3: development.logΛௐ΂͍ͨɻ ઌ಄ʹCompleted͕ͭ͘ߦΛநग़͢Δʹ͸ʁ

  11. ໰3: development.logΛௐ΂͍ͨɻ ઌ಄ʹCompleted͕ͭ͘ߦΛநग़͢Δʹ͸ʁ $ grep -e “^Completed” \ development.log

  12. ໰3: development.logΛௐ΂͍ͨɻ ઌ಄ʹCompleted͕ͭ͘ߦΛநग़͢Δʹ͸ʁ $ grep -e “^Completed” \ development.log ਖ਼نදݱ

  13. $ grep -e "^[0-9]\{4\}/[0-9]\{2\}/[0-9]\{2\}" target_file ਖ਼نදݱΛා͕Βͳ͍Ͱ ͻͱͭͻͱͭཧղ͢Δ

  14. ໰4: ԼهͷίϚϯυ݁Ռ͔Β500ͷ ΤϥʔϩάΛநग़͍ͨ͠ $ grep -e “^Completed” \ development.log

  15. ໰4: ԼهͷίϚϯυ݁Ռ͔Β500ͷ ΤϥʔϩάΛநग़͍ͨ͠ $ grep -e “^Completed” \ development.log |

    grep 500
  16. ໰4: ԼهͷίϚϯυ݁Ռ͔Β500ͷ ΤϥʔϩάΛநग़͍ͨ͠ $ grep -e “^Completed” \ development.log |

    grep 500 ύΠϓ
  17. $ grep -r hoge . | grep huga | grep

    -v foo ύΠϓΛ஌Δͱग़ྗΛ ࢖͍·Θ͢ज़͕Ͱ͖·͢
  18. ໰5: ԼهͷίϚϯυ݁ՌΛϑΝΠϧ ʹॻ͖ग़͢ʹ͸ʁ $ grep -e “^Completed” \ development.log

  19. ໰5: ԼهͷίϚϯυ݁ՌΛϑΝΠϧ ʹॻ͖ग़͢ʹ͸ʁ $ grep -e “^Completed” \ development.log >

    output_file
  20. ໰5: ԼهͷίϚϯυ݁ՌΛϑΝΠϧ ʹॻ͖ग़͢ʹ͸ʁ $ grep -e “^Completed” \ development.log >

    output_file ϦμΠϨΫγϣϯ
  21. $ ssh user@server ‘cat >> .ssh/authorized_keys’ < .ssh/id_rsa.pub ϦμΠϨΫγϣϯ͸ҙ֎ͱ ࢖͑Δศརͳ΍ͭͰ͢

  22. ໰6: ࠓ͋ΔϑΝΠϧΛશ෦όοΫΞοϓ (.bak)ʹ͍ͨ͠Μ͚ͩͲ data20141101.txt data20141102.txt data20141103.txt data20141104.txt data20141105.txt …

  23. ໰6: ࠓ͋ΔϑΝΠϧΛશ෦όοΫΞοϓ (.bak)ʹ͍ͨ͠Μ͚ͩͲ $ for file in *; \ {

    mv -i “$file” “$file.bak”; }
  24. ໰6: ࠓ͋ΔϑΝΠϧΛશ෦όοΫΞοϓ (.bak)ʹ͍ͨ͠Μ͚ͩͲ $ for file in *; \ {

    mv -i “$file” “$file.bak”; } ੍ޚߏจ
  25. ੍ޚߏจ͸γΣϧεΫϦϓτ ʹඞਢͳ஌ࣝ

  26. ໰7: eventʹؔΘΔϑΝΠϧ͚ͩgit checkoutͰࠩ͠໭͍ͨ͠ $ git status # modified: app/models/user.rb #

    modified: app/models/event.rb … # modified: app/controllers/users_controllers.rb # modified: app/controllers/events_controllers.rb …
  27. ໰7: eventʹؔΘΔϑΝΠϧ͚ͩgit checkoutͰࠩ͠໭͍ͨ͠ $ git status | grep event |

    \ awk {‘print $3’} | \ xrges git checkout
  28. ໰7: eventʹؔΘΔϑΝΠϧ͚ͩgit checkoutͰࠩ͠໭͍ͨ͠ $ git status | grep event |

    \ awk {‘print $3’} | \ xrges git checkout awk, xargsศརʂ
  29. awkͱxargsͰग़ྗ݁Ռͷ ࢖͍ճ͠ͷ෯Λ޿͛Α͏

  30. ໰8: sample.txtͷதͷ’5%’Λ’8%’ʹจࣈ ྻม׵ʢrubyΛ࢖ͬͯʣ

  31. $ ruby -pne \ ‘$_.gsub!(/5%/, “8%”)’ \ -i sample.txt ໰8:

    sample.txtͷதͷ’5%’Λ’8%’ʹจࣈ ྻม׵ʢrubyΛ࢖ͬͯʣ
  32. $ ruby -pne \ ‘$_.gsub!(/5%/, “8%”)’ \ -i sample.txt ruby!

    ໰8: sample.txtͷதͷ’5%’Λ’8%’ʹจࣈ ྻม׵ʢrubyΛ࢖ͬͯʣ
  33. ruby΍perlͷϫϯϥΠφʔ ͰҰา্ͷॲཧ΁

  34. ɾίϚϯυͰग़དྷΔࣄ͕૿͑Δ ɾΦϓγϣϯͰग़དྷΔࣄ͕૿͑Δ ɾਖ਼نදݱͰग़དྷΔࣄ͕૿͑Δ ɾύΠϓͰग़དྷΔࣄ͕૿͑Δ ɾϦμΠϨΫτͰग़དྷΔࣄ͕૿͑Δ ɾ੍ޚߏจͰग़དྷΔࣄ͕૿͑Δ ɾxargs, awkͰग़དྷΔࣄ͕૿͑Δ ɾruby΍perlͰग़དྷΔࣄ͕૿͑Δ ·ͱΊ

  35. ͜ͷεϥΠυͰ঺հͨ͠ͷ͸Ұ෦Ͱ໌ ೔͔ΒίϚϯυΛ࢖͍͜ͳͤΔΑ͏ʹ ͸ͳΓ·ͤΜɻ·ͣ͸ͲΜͳࣄ͕ग़དྷ Δ͔Λ஌Δࣄ͕େ੾Ͱ͢ɻීஈͷۀ຿ ͷதͰɺ΋ͬͱ؆୯ʹग़དྷΔํ๏͸ͳ ͍͔Λߟ͑ɺৗʹ৽͍͠ํ๏Λൃݟɾ ։୓͍͖ͯ͠·͠ΐ͏ɻ ·ͱΊ2

  36. $ say ͋Γ͕ͱ͏͍͟͝·ͨ͠