2012年4月23日月曜日

2012年04月23日 講義053日目

2012年04月23日
講義053日目
------------------------------1H------------------------------
★小テストの解答、解説
●電卓クラスの解説
・小テストの電卓クラス
Class dentaku{

    public $answer;

    function dentaku($num1,$num2){
    $this->num1 = $num1;
    $this->num2 = $num2;
    }

    function plusTwoNumber(){
        $this->answer = $num1+$num2;
    }
    function minusTwoNumber(){
        $this->answer = $num1-$num2;
    }
    function multipliTwiNumber(){
        $this->answer = $num1*$num2;
    }
    function divisionTwoNumber(){
        $this->answer = $num1/$num2;
    }
}
retrunが無いので計算するだけのクラス
$this->answerに値を放り込むだけなので、答えを出力するには$this->answerを出力する

・練習での電卓クラス
Class Dentaku{
    protected $num1;
    protected $num2;
    function Dentaku($one,$two) {
        $this->num1 = $one;
        $this->num2 = $two;
    }
    function plus(){
        return $this->num1 + $this->num2;
    }
    function minus(){
        return $this->num1 - $this->num2;
    }
    function multiply(){
        return $this->num1 * $this->num2;
    }
    function division(){
        if($this->num2 == 0){
            return 0;
        }
        return $this->num1 / $this->num2;
    }
}

------------------------------2H------------------------------
★VMwareとCentOSのインストール
------------------------------3H------------------------------
★CentOS
●rootでログイン
localhost login :root
password:パスワード←表示されないけど入力できてる
root@localhost ~ ]#
の表示でログイン成功
●コマンド
・# ls /
ディレクトリ表示
・# ifconfig
コマンドプロンプトでのipconfigのようなもの
●puttyのインストール
サーバに接続するためのソフト
サーバに接続するためには必ずしもputtyを使わなければならないわけではない
他にも接続できるソフトはいくつかある
・puttyの設定
# ifconfigでinet addrでCentOSのIPアドレスを表示
------------------------------4H------------------------------
★putty
●puttyでCentOSに接続する
・接続先の指定
ホスト名
SSH
ポート22
・セッションの読み込み、保存、削除
  セッション一覧に設定を保存
・接続ボタンでCentOSに接続する
レジストリにキャッシュ云々のアラートはとりあえず無視、「はい」を選択で大丈夫
・コマンドプロンプトのような画面が表示され、login as:が出る
CentOSにログインしたやり方でログインする
・puttyの設定を変更
keepaliveの設定を変更→0から300くらいにする
文字コードををutf-8(CJK)に変更
●コマンド
一つのコマンドに対してのバリエーションがいくつかある
・ls -l /
lsはリスト表示、-lで全情報を指定
・ls -lt /
リスト表示、リストを時間(新しい)順で並べる
オプションの記述はリナックスの種類によって多少違う
・オプションの記述方法はコマンドによって、オプションによって違う
------------------------------5H------------------------------
★Linuxコマンド
●パイプとリダイレクト
・パイプ「|」
コマンド1|コマンド2
コマンド1を実行してからコマンド2を実行する
ls -al / | wc
リストの行数や文字を
・リダイレクト「>」
コマンド1>コマンド2
コマンド1をコマンド2に出力する
例)ls ltr / > test.txt
ファイルに出力する
・cat test.txtで↑で出力したファイルを表示
●コマンドを使ってみる
●移動
・cd
ユーザに与えられた自分の場所へ戻る
・pwd
今いる場所を表示
・ctrl+Sやctrl+Cなどはputty上では使わない
・青文字はディレクトリ
[root@localhost ~]# ls -l
合計 64
-rw------- 1 root root  1088  4月 23 21:47 anaconda-ks.cfg
-rw-r--r-- 1 root root 27783  4月 23 21:47 install.log
-rw-r--r-- 1 root root  3382  4月 23 21:46 install.log.syslog
drwxr-xr-x 2 root root  4096  4月 24 00:44 test
-rw-r--r-- 1 root root  1059  4月 24 00:29 test.txt
↑dが付いてるのがディレクトリという意味
●削除
・rm
rootでリムーブするときは戻せないので、細心の注意を払って実行する
・ファイル削除
[root@localhost test]# cd /root
[root@localhost ~]# rm test.txt
rm: remove 通常ファイル `test.txt'? y(←yかyesで実行)
・ディレクトリ削除
[root@localhost ~]# ls
anaconda-ks.cfg  install.log  install.log.syslog  test
[root@localhost ~]# rm -r test
rm: remove ディレクトリ `test'? n
[root@localhost ~]# ls
anaconda-ks.cfg  install.log  install.log.syslog  test
[root@localhost ~]# rm -rf test
[root@localhost ~]# ls
anaconda-ks.cfg  install.log  install.log.syslog
[root@localhost ~]#
↑rm -rf test(-rにfを付けると確認されずに消去)

・ディレクトリ名/
------------------------------6H------------------------------
★Linuxコマンド
●コマンドを使ってみる
・>>
追加書き込み
・コマンドプロンプトを二つ開く
プロンプト1に
[root@localhost ~]# tail -f test.txt

プロンプト2に
[root@localhost ~]# ls >> test.txt
と打ってみる

プロンプト2で
ctrl+Cを打つ現在動いてるコマンドを終了させる
・more ファイル名
enterで一行づつ
spaceでも進む
qで抜ける

●圧縮
・tar -cvzf rootdata.tar.gz /root/
Linuxではtar.gz、 tarが良く使われる
・赤いファイルはアーカイブ化されてることを表す
●解凍
・tar -xvzf rootdata.tar.gz
[root@localhost backup]# ls
rootdata.tar.gz  test.txt  test2.txt
[root@localhost backup]# tar -xvzf rootdata.tar.gz
root/
root/.bash_profile
root/test.txt
root/rootdata.tar.gz
root/.bashrc
root/.bash_logout
root/.bash_history
root/install.log.syslog
root/install.log
root/.cshrc
root/backup/
root/backup/test2.txt
root/backup/aaa
root/backup/test.txt
root/.tcshrc
root/anaconda-ks.cfg
[root@localhost backup]# ls
root  rootdata.tar.gz  test.txt  test2.txt
↑解凍された
●top
タスクマネージャのようなもの
●プロセスの確認
ps -e
killコマンドでプロセスを殺す
-----------------------------memo------------------------------
風邪お大事に

0 件のコメント:

コメントを投稿