>

おい小僧、勉強しろ

植木屋からITへ転職した小僧が語る雑記ブログです(プログラミング, 哲学, アート, 生活, etc...)

【外出自粛中】お勉強

概要

Linuxシステムやコマンドの理解を深めるためLinux Journeyを実施する。

実施後まとめる

lsコマンド

lsコマンドのバージョン情報(version)

  • root@kali:~# ls --version
    ls (GNU coreutils) 8.30
    Copyright (C) 2018 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    
    作者 Richard M. Stallman および David MacKenzie。

ファイル・ディレクトリ詳細情報表示(la)

  • root@kali:~# ls -la
    合計 1164
    drwxr-xr-x 22 root root   4096  4月  9 22:42 .
    drwxr-xr-x 18 root root   4096  1月 19 10:52 ..
    drwx------  4 root root   4096  1月 19 10:14 .BurpSuite
    -rw-------  1 root root   8262  4月  9 22:42 .ICEauthority
    -rw-------  1 root root     49  4月  9 22:42 .Xauthority
    drwx------  3 root root   4096  4月  9 02:26 .anthy
    -rw-r--r--  1 root root   9536  4月  9 01:05 .bash_history
    -rw-r--r--  1 root root   3391 11月 25 05:31 .bashrc
    ...

「.」と「..」を除いた全情報表示(A)

  • root@kali:~# ls -A
    .BurpSuite     .java                         .xsession-errors.old  ip.txt
    .ICEauthority  .local                        Desktop               iplist.txt
    .Xauthority    .mozilla                      Documents             ipsweep.sh
    .anthy         .profile                      Downloads             job
    .bash_history  .vboxclient-clipboard.pid     Music                 newfile.txt
    .bashrc        .vboxclient-display-svga.pid  Pictures              nmap.txt
    .cache         .vboxclient-display.pid       Public                python
    .config        .vboxclient-draganddrop.pid   Templates             work
    .dmrc          .vboxclient-seamless.pid      Videos                work_linux_journey
    .face          .viminfo                      hello.txt
    .gnupg         .xsession-errors              hey.txt

ファイル名を「”」で囲み、一行で表示する(1Q)

  • root@kali:~# ls -1Q
    "Desktop"
    "Documents"
    "Downloads"
    "Music"
    "Pictures"
    "Public"
    "Templates"
    "Videos"
    ...

サブディレクトリ情報表示(R)

  • root@kali:~# ls -R
    .:
    Desktop    Music     Templates  hey.txt     ipsweep.sh   nmap.txt  work_linux_journey
    Documents  Pictures  Videos     ip.txt      job          python
    Downloads  Public    hello.txt  iplist.txt  newfile.txt  work
    
    ./Desktop:
    
    ./Documents:
    
    ./Downloads:
    
    ./Music:
    
    ./Pictures:
    
    ./Public:
    
    ./Templates:
    
    ./Videos:
    
    ./job:
    DSC
    
    ./job/DSC:
    partner
    
    ./job/DSC/partner:
    
    ./python:
    first.py  math.py  script.py
    
    ./work:
    actcmd  hi  messages  settings
    
    ./work_linux_journey:
    banana.txt  fake  file1.txt  file2.txt  hi.txt  peanuts.txt  reading.txt  sample.txt
    
    ./work_linux_journey/fake:
    directory
    
    ./work_linux_journey/fake/directory:

/var配下など、場所によって表示数が膨大になるため注意

拡張子別にファイルソート(X)

  • root@kali:~# ls -X
    Desktop    Music     Templates  python              ipsweep.sh  ip.txt       nmap.txt
    Documents  Pictures  Videos     work                hello.txt   iplist.txt
    Downloads  Public    job        work_linux_journey  hey.txt     newfile.txt

実行可能ファイルに「*」付与(F)

  • root@kali:~# ls -F
    Desktop/    Pictures/   hello.txt*  ipsweep.sh*  python/
    Documents/  Public/     hey.txt     job/         work/
    Downloads/  Templates/  ip.txt      newfile.txt  work_linux_journey/
    Music/      Videos/     iplist.txt  nmap.txt

組み合わせ

縦1列に拡張子別表示

  • root@kali:~# ls -1XF
    Desktop/
    Documents/
    Downloads/
    Music/
    Pictures/
    Public/
    Templates/
    Videos/
    job/
    python/
    work/
    work_linux_journey/
    ipsweep.sh*
    hello.txt*
    hey.txt
    ip.txt
    iplist.txt
    newfile.txt
    nmap.txt

更新日時昇順ソート

  • root@kali:~# ls -lrt
    合計 76
    drwxr-xr-x 2 root root 4096 11月 25 13:47 Videos
    drwxr-xr-x 2 root root 4096 11月 25 13:47 Templates
    drwxr-xr-x 2 root root 4096 11月 25 13:47 Public
    drwxr-xr-x 2 root root 4096 11月 25 13:47 Pictures
    drwxr-xr-x 2 root root 4096 11月 25 13:47 Music
    drwxr-xr-x 2 root root 4096 11月 25 13:47 Downloads
    drwxr-xr-x 2 root root 4096 11月 25 13:47 Documents
    drwxr-xr-x 2 root root 4096 11月 25 13:47 Desktop
    -rw-r--r-- 1 root root   26  4月  5 02:13 hey.txt
    -rw-r--r-- 1 root root   45  4月  5 02:22 newfile.txt
    -rw-r--r-- 1 root root  255  4月  5 03:00 ip.txt
    -rw-r--r-- 1 root root   38  4月  5 03:21 iplist.txt
    -rwxr-xr-x 1 root root  214  4月  5 03:35 ipsweep.sh
    -rw-r--r-- 1 root root   62  4月  5 03:41 nmap.txt
    drwxr-xr-x 3 root root 4096  4月  7 23:03 job
    drwxr-xr-x 2 root root 4096  4月  8 01:57 work
    drwxr-xr-x 2 root root 4096  4月  8 09:29 python
    drwxr-xr-x 3 root root 4096  4月  8 22:03 work_linux_journey
    -rwxrwxrwx 1 root root  306  4月 10 02:57 hello.txt


まとめ

ディレクトリ階層

  • /

    • /bin

      • lsやcpなど基本的なコマンド(プログラム)

        • ls、cp、chmod、ssh-add、etc…

    • /boot

    • /dev

      • バイスファイル

        • random、tty、etc…

    • /etc

      • 構成ファイル

        • apt、apache2、nginx、network、python3、etc…

    • /home

      • ユーザ個人のディレクトリでドキュメント、ファイルや設定など

    • /lib

      • ライブラリファイル

    • /media

      • USBドライブなどのリムーバブルメディア

    • /mnt

    • /opt

    • /proc

      • 実行中プロセスに関する情報

    • /root

      • rootユーザのホームディレクト

        • Desktop、Pictures、Download、etc…

    • /run

      • ブート以降の実行中のシステムに関する情報

    • /sbin

      • 重要なシステムバイナリ

    • /srv

      • システム提供のサイト固有データ

    • /usr

    • /var

      • ログ、キャッシュなど。変更される可能性のあるすべてのもの


Linuxシステムの電源オン~ログインウィンドウ表示までに起こっていること

  1. BIOS

    1. ハードウェアの初期化

    2. すべてのハードウェアが正常に動作することを電源投入時自己診断し確認する

    3. Bootloaderをロードする

  2. Bootloader

    1. カーネルをメモリにロードする

    2. カーネルを起動する

  3. カーネル

    1. バイスとメモリの初期化

    2. initプロセスをロードする

      1. ring#0:特権モード

      2. ring#3:ユーザモード

  4. init

    1. システム上の重要なサービスプロセスの開始および停止を行う

      1. sysv

      2. upstart

      3. systemd


ログの種類

  • syslog(rsyslog)

    • /var/log/syslog

      • 認証メッセージを除くすべてのメッセージ

  • general log

    • /var/log/messages

      • 起動中に記録されたメッセージ(dmesg)、auth、cron、daemonなど。マシンの動作を確認するのに役立つ

  • kernel log

    • /var/log/dmesg

      • ハードウェアドライバーに関する情報、カーネル情報、起動時のステータスなど。マシン起動時エラー解決に役立つ

    • /var/log/kern.log

  • authentication log

    • /var/log/auth.log

      • 認証情報

  • loglotate

    • /etc/logrotate.d.

      • ログの管理


参考サイト

注釈

自宅で使用した環境を以下に記載する。

  • ホストOS

    • Windows10 Pro

  • ゲストOS

  • 仮想化ソフトウェア