2012年4月24日火曜日

2012年04月24日 講義054日目

2012年04月24日
講義054日目
------------------------------1H------------------------------
★Linuxコマンド

・ps -e
サーバのプロセスを表示
・kill
プロセスを殺すことができる
使い方に注意
●ユーザを作る
・who am i
自分がどのユーザでログインしてるか見ることができる
・root以外のユーザを作る
rootだと無制限に色々できてしまうので、制限されたユーザを作る
・ユーザを作ると/homeにフォルダができる
・useradd ユーザ名
ユーザを作成
・passwd ユーザ名
入力したユーザ名のパスワード
パスワード的に問題があるなど色々警告が出るが、入力は出来る
------------------------------2H------------------------------
★Linuxコマンド
●コマンド
・コマンドでディレクトリを作ってみる
shonanbbsディレクトリを作って、その中にindex.phpを作る
[nishi@localhost ~]$ touch shonanbbs/index.php
[nishi@localhost ~]$ ls
shonanbbs
[nishi@localhost ~]$ ls shonanbbs
index.php

・find ./ -name index.php
index.phpを探して、表示
./はどこから探したいか、現在位置を表す
-nameは名前で探すオプション
探し方はオプションで色々出来る
ワイルドカードでも探せる
・rootにあるインストールログを新たに作ったユーザのフォルダにコピー
[root@localhost ~]# cp install.log /home/nishi
[root@localhost ~]# cd /home/nishi
[root@localhost nishi]# ls
install.log  shonanbbs
・新たに作ったユーザ側のフォルダ内を確認
[nishi@localhost ~]$ ls -l
合計 40
-rw-r--r-- 1 root  root  27783  4月 24 03:32 install.log
drwxrwxr-x 2 nishi nishi  4096  4月 24 03:18 shonanbbs
コピーされたrootのファイルはユーザではいじる事が出来ない
・ユーザの設定
グループとユーザ
・chown
ファイルのオーナーを変更
root側で
[root@localhost nishi]# chown nishi:nishi /home/nishi/install.log
ユーザ側で確認
[nishi@localhost ~]$ ls -l
合計 40
-rw-r--r-- 1 nishi nishi 27783  4月 24 03:32 install.log
drwxrwxr-x 2 nishi nishi  4096  4月 24 03:18 shonanbbs
・grep
ファイルの中身を検索できる
2byte文字を検索したい場合は""で囲む
ctrl+cで入力したコマンドを止めることも出来るので挙動がおかしくなったら使う
・findとgrepは組み合わせて使うことが多い
[nishi@localhost ~]$ find -name install.log | xargs grep test
------------------------------3H------------------------------
★Linuxコマンド
●Vi操作
・Linuxのテキストエディタ
[nishi@localhost ~]$ vi config.inc.php
・iまたはa
テキスト入力モードに出来る
・Esc
コマンド入力モードに戻る
どちらのモードか分からなくなったらEscを押してコマンド入力モードに戻ればいい
・:w
保存する
・:q
終了する
・:wq
保存して終了
・:q!
保存せず終了
・h,j,k,l
↑,↓,←,→
puttyでは十字キーで移動可能だが、コマンド
・:set number,:set nu
行数を表示させる
・set nonu
行数を非表示にする
・shift+g(G)
最後の行へ移動
・数字を入力→shift+g(G)
数字の行へ移動
数字を押し間違えたらEscして再入力
・u
undoコマンド
・yy
ヤンク(コピー)
・p
ペースト
------------------------------4H------------------------------
★Linuxコマンド
●コマンド
・ln
シンボリックリンクを作成
ショートカットのようなもの
水色のファイルが作成される
・su
スイッチユーザ
suだけ打つとrootになれるが、rootに許された操作が使えない場合もある
[nishi@localhost ~]$ su root
パスワード:
[root@localhost nishi]#
exitを入力するとスイッチ前のユーザに戻る
ルートでなければ入力できないコマンドなどが拒絶される
その場合は
su -
で、rootにスイッチしてもコマンドなどが通るようになる
------------------------------5H------------------------------
★Linuxコマンド
●コマンド
・chmod
ファイルへの読み込み権限、書き込み権限などを変更する
[nishi@localhost ~]$ ls -l
合計 52
lrwxrwxrwx 1 nishi nishi    14  4月 24 06:22 conf -> config.inc.php
-rw-rw-r-- 1 nishi nishi   114  4月 24 05:39 config.inc.php
-rw-r--r-- 1 nishi nishi 27783  4月 24 03:32 install.log
drwxrwxr-x 2 nishi nishi  4096  4月 24 03:18 shonanbbs
↑--ココ--↑
書き込みの許可を表す
4 2 1
r w x
読み込み、書き込み、実行
-rwxrwxrwx
オーナー(u)、グループ(g)、その他(誰でも)(o)の順番
[nishi@localhost ~]$ chmod 777 config.inc.php
[nishi@localhost ~]$ ls -l
合計 52
lrwxrwxrwx 1 nishi nishi    14  4月 24 06:22 conf -> config.inc.php
-rwxrwxrwx 1 nishi nishi   114  4月 24 05:39 config.inc.php
-rw-r--r-- 1 nishi nishi 27783  4月 24 03:32 install.log
drwxrwxr-x 2 nishi nishi  4096  4月 24 03:18 shonanbbs
別の書き方も出来る
[nishi@localhost ~]$ chmod g-w config.inc.php
[nishi@localhost ~]$ ls -l
合計 52
lrwxrwxrwx 1 nishi nishi    14  4月 24 06:22 conf -> config.inc.php
-rwxr-xrwx 1 nishi nishi   114  4月 24 05:39 config.inc.php
-rw-r--r-- 1 nishi nishi 27783  4月 24 03:32 install.log
drwxrwxr-x 2 nishi nishi  4096  4月 24 03:18 shonanbbs
●シェルスクリプト
[nishi@localhost ~]$ vi datemake.sh
/bin/date >> /home/nishi/date.log
/bin/echo "command end."
・>>
上書き
------------------------------6H------------------------------
★Linuxコマンド
●シェルスクリプト
・シェルスクリプトの内容は行頭に#でコメントアウト出来る
・crontab
定期的に実行する期間と実行ファイルを指定できる
分  時  日  月  曜日  実行内容
10 17 25 4 0 /home/nishi/hoge.sh

全部の日時等を指定したい場合は「*」
10 17 * * * /home/nishi/hoge.sh

範囲指定「n-n」、毎時「n/*」指定もできる
10-20 */1 * * * /home/nishi/home.sh
一時間ごとに。10分~20分の間で
●bash
シェルからカーネルへ渡す時に動いてくれる機能
・view
読み込み
!をつけると書き込める
[root@localhost nishi]# view /home/nishi/date.log

・xargs
それまでの出力結果を次のコマンドの引数とする
[nishi@localhost ~]$ ls
conf  config.inc.php  date.log  datemake.sh  install.log  shonanbbs
[nishi@localhost ~]$ wc config.inc.php
  8   7 114 config.inc.php
[nishi@localhost ~]$ ls | wc
      6       6      63
     
[nishi@localhost ~]$ ls | xargs wc
      8       7     114 conf
      8       7     114 config.inc.php
     59     246    1363 date.log
      2       8      83 datemake.sh
    554    1116   27783 install.log
wc: shonanbbs: ディレクトリです
      0       0       0 shonanbbs
    631    1384   29457 合計
lsの結果をwcに送ることで各ファイルの情報を取得できた
・du
ファイルの容量を表示する
[nishi@localhost ~]$ du ./
8       ./.mozilla/plugins
8       ./.mozilla/extensions
24      ./.mozilla
12      ./shonanbbs
140     ./
・man
オプションでコマンドを指定する(man cd)
ヘルプを出してくれる
qで戻る
・help
コマンド別にヘルプを出す
-----------------------------memo------------------------------
linuxは楽しいかも

0 件のコメント:

コメントを投稿