Skip to content

Instantly share code, notes, and snippets.

@GitSumito
Created February 14, 2018 05:39
Show Gist options
  • Save GitSumito/ef666a24d12b89a2a9c4cb18eaf5b3a3 to your computer and use it in GitHub Desktop.
Save GitSumito/ef666a24d12b89a2a9c4cb18eaf5b3a3 to your computer and use it in GitHub Desktop.
source codeの追い方 -なぜlessコマンドはバイナリファイルを読めるのか- ref: https://qiita.com/S-T/items/afc356255c3c01beefaa
[root@tkd003 tmp]# which less
/usr/bin/less
[root@tkd003 tmp]# rpm -qf /usr/bin/less
less-458-9.el7.x86_64
[root@tkd003 less]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/less-458-9.el7.x86_64.rpm
--2018-02-14 14:09:32-- http://mirror.centos.org/centos/7/os/x86_64/Packages/less-458-9.el7.x86_64.rpm
mirror.centos.org (mirror.centos.org) をDNSに問いあわせています... 111.90.139.14
mirror.centos.org (mirror.centos.org)|111.90.139.14|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 122672 (120K) [application/x-rpm]
`less-458-9.el7.x86_64.rpm' に保存中
100%[===========================================================================================>] 122,672 516KB/s 時間 0.2s
2018-02-14 14:09:37 (516 KB/s) - `less-458-9.el7.x86_64.rpm' へ保存完了 [122672/122672]
[root@tkd003 less]#
[root@tkd003 less]# rpm2cpio less-458-9.el7.x86_64.rpm | cpio -idv
./etc/profile.d/less.csh
./etc/profile.d/less.sh
./usr/bin/less
./usr/bin/lessecho
./usr/bin/lesskey
./usr/bin/lesspipe.sh
./usr/share/doc/less-458
./usr/share/doc/less-458/LICENSE
./usr/share/man/man1/less.1.gz
./usr/share/man/man1/lessecho.1.gz
./usr/share/man/man1/lesskey.1.gz
424 blocks
[root@tkd003 less]#
[root@tkd003 less]# grep rpm -r *
バイナリファイル less-458-9.el7.x86_64.rpm に一致しました
usr/bin/lesspipe.sh:*.rpm) rpm -qpivl --changelog -- "$1" ;;
[root@tkd003 less]#
less -N usr/bin/lesspipe.sh
49 *.tar) tar tvvf "$1" ;;
50 *.tgz|*.tar.gz|*.tar.[zZ]) tar tzvvf "$1" ;;
51 *.tar.xz) tar Jtvvf "$1" ;;
52 *.xz|*.lzma) xz -dc -- "$1" ;;
53 *.tar.bz2|*.tbz2) bzip2 -dc -- "$1" | tar tvvf - ;;
54 *.[zZ]|*.gz) gzip -dc -- "$1" ;;
55 *.bz2) bzip2 -dc -- "$1" ;;
56 *.zip|*.jar|*.nbm) zipinfo -- "$1" ;;
57 *.rpm) rpm -qpivl --changelog -- "$1" ;;
58 *.cpi|*.cpio) cpio -itv < "$1" ;;
59 *.gpg) gpg -d "$1" ;;
60 *.gif|*.jpeg|*.jpg|*.pcd|*.png|*.tga|*.tiff|*.tif)
rpm -qpivl --changelog -- less-458-9.el7.x86_64.rpm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment