2009年8月アーカイブ

continue  ループ  抜ける 次の繰り返しへ


continue  構文   】
continue [n]

【continue 説明   】
for,select,until,whileを用いた

ループ構造の途中で,

囲まれたループを抜けて

次の繰り返しをする。

 

【 使用例   】

for num in `ls -la`
do

  if [ $num = '.' ]
    then
     echo "$num continue next"
     continue
    fi
      echo roop
done







       continue [n]
              Resume the next iteration of the enclosing for,  while,  until,  or
              select  loop.  If n is specified, resume at the nth enclosing loop.
              n must be ? 1.  If n is greater than the number of enclosing loops,
              the  last  enclosing loop (the ''top-level'' loop) is resumed.  The
              return value is 0 unless the shell is not  executing  a  loop  when
              continue is executed.

サーバ構築(ランキング)
command  コマンド

【cmmand コマンド 構文   】

 command [-pVv] command [arg ...]

【 オプション   】
-p  
コマンド検索 標準のパスを用いる

-v  
コマンドのパス名などのみを表示する。
コマンドは実行しない

-V  
コマンドのパス名やその他の情報のみを表示する。
コマンドは実行しない
 

 使用例  
[takuan@localhost ~]$ command -V ls
ls is aliased to `ls --color=auto'

[takuan@localhost ~]$ command -V cd
cd is a shell builtin


[takuan@localhost ~]$ command -v ls
alias ls='ls --color=auto'
 




       command [-pVv] command [arg ...]
              Run command with args suppressing the normal shell function lookup.
              Only  builtin  commands or commands found in the PATH are executed.

              If the -p option is given, the  search  for  command  is  performed
              using  a  default  value for PATH that is guaranteed to find all of
              the standard utilities.  If either the -V or -v option is supplied,
              a description of command is printed.

 The -v option causes a single
              word indicating the command or file name used to invoke command  to
              be  displayed; 

the  -V option produces a more verbose description.
              If the -V or -v option is supplied, the exit status is 0 if command
              was  found,  and  1  if  not.  If neither option is supplied and an
              error occurred or command cannot be found, the exit status is  127.
              Otherwise,  the exit status of the command builtin is the exit sta-
              tus of command.

サーバ構築(ランキング)
リナックス コマンド cd  ディレクトリ移動

cd コマンド 構文 】 
cd [dir]

 説明  

現在のディレクトリを変更します。

指定したディレクトリに移動する。

[dir]は

相対パス,絶対パスの

どちらでも指定できます。

また,ディレクトリの表記方法として

以下のような記号を使える。


directoryに何も指定しないとホーム・ディレクトリに移動する。


★PR  VAIO type N ホワイト  

 

【ディレクトリの表記方法】

cd /
ルート・ディレクトリ へ移動

cd .
現在のディレクトリ へ移動

cd ..
親ディレクトリへ移動

cd ~/
ホーム・ディレクトリへ移動


★PR USB接続でノートPCでもマルチディスプレイ


【cdコマンド 使用例   】

[root@localhost /]# pwd
/
[root@localhost /]# cd bin
[root@localhost bin]# pwd
/bin
[root@localhost bin]# cd ~
[root@localhost ~]# pwd
/root


★PR 大容量 8000mAh(3.7V)  バッテリー

ノートPCからケータイまで幅広く対応





【参考】


       cd [-L|-P] [dir]
              Change the current directory to dir.   The  variable  HOME  is  the
              default  dir.   The variable CDPATH defines the search path for the
              directory containing dir.  Alternative directory  names  in  CDPATH
              are  separated  by a colon (:).  A null directory name in CDPATH is
              the same as the current directory, i.e., ''.''.  If dir begins with
              a slash (/), then CDPATH is not used.

The -P option says to use the
              physical directory structure instead of  following  symbolic  links
              (see  also the -P option to the set builtin command);

the -L option
              forces symbolic links to be followed.  An argument of - is  equiva-
              lent  to  $OLDPWD.   If  a  non-empty directory name from CDPATH is
              used, or if - is the first argument, and the  directory  change  is
              successful,  the  absolute pathname of the new working directory is
              written to the standard output.  The return value is  true  if  the
              directory was successfully changed; false otherwise.

サーバ構築(ランキング)
Vine Linux 5.0 についてです。

おうw 新しい Vine Linuxでたのかぁ。


【前バージョンからのおおきめな変更点】

●対応アーキテクチャにx86_64が加わったことです。これまではi386とppcです。

●起動時のメモリ消費量が大幅に低減し、起動時間が約半分になったことです。

●日本語フォントの改良です。

●パッケージのアップデート/インストールの簡略化です。

●軽量・高速です。

●収録ソフトウエアの刷新です。

●ルック&フィールの改善です。

●ユーザフレンドリなツール群です。

●USB/DVD 用インストールイメージの提供です。

詳細はこちら↓

http://www.vinelinux.org/whatsvinelinux.html#VineLinux5の特徴
サーバ構築(ランキング)
case  条件分岐

【 構文   】

case
in
 式) コマンド
esac  

【 説明   】

条件分岐を作る。
以下の例のように,

シェル変数の値が

aのときは,コマンドa

bのときは,コマンドb

...という

条件分岐にしたい場合は,

case文を使ってコードを記述することで

条件によってコマンドを変えられます。


また、式の部分には正規表現を記述できる。

最後の末尾の条件を

*

(アスタリスク)

としておくと,

他のすべての条件に合わないときだけ

実行できる。
 

【 使用例   】

一つ目の引数の値によって,
処理を分岐する

case $1
in
  a)  ls -l  ;;
  b)  ls -a  ;;
  c)  ls -lrt  ;;
  *)  pwd  ;;
esac
 

サーバ構築(ランキング)
break  ループ 抜け出す  出て行く

 構文  
break [n]  

 オプション  
[n] n重ループから出て行く。


 説明  
breakコマンドは、ループ(for,select,until,while)から
出て行くコマンドです。

       break [n]
              Exit  from  within  a  for,  while, until, or select loop.  If n is
              specified, break n levels.  n must be ? 1.  If n  is  greater  than
              the number of enclosing loops, all enclosing loops are exited.  The
              return value is 0 unless the shell is not  executing  a  loop  when
              break is executed.@



 使用例  

whileループを終わりにする。

while [ ! -e file_01.txt ]
do
    touch file_01.txt
    if [ -e file_01.txt ]
    then
    echo "make file" >>log.txt
    break
    echo "break"  >>log.txt
    fi
done




サーバ構築(ランキング)
bg  ジョブ バックグラウンド 実行 切り替え

 構文  
bg [%jobsid]  

 オプション  
%jobsid

バックグラウンドで実行するコマンドの
 ジョブ番号を指定する

ジョブ番号はjobsコマンドにて確認できる。

[takuan@localhost ~]$ jobs
[1]-  Stopped                 vim tmp.txt
[2]+  Stopped                 find / -name *.txt
 

 説明  
ジョブをバックグラウンドで実行するコマンドです。
パラメータを省略した場合は
カレントジョブ(+のついたジョブ)を実行します。


[takuan@localhost ~]$ find / -name *.txt
find: /var/cache/mod_proxy: 許可がありません
省略・・・

^Z
[1]+  Stopped                 find / -name *.txt
[takuan@localhost ~]$ jobs
[1]+  Stopped                 find / -name *.txt
[takuan@localhost ~]$ bg
[1]+ find / -name *.txt &



find: /etc/lvm/archive: 許可がありません
find: /etc/cups/ssl: 許可がありません

[1]+  Exit 1                  find / -name *.txt
[takuan@localhost ~]$

       bg [jobspec ...]
              Resume each suspended job jobspec in the background, as if  it  had
              been started with &.  If jobspec is not present, the shell's notion
              of the current job is used.  bg jobspec returns 0 unless  run  when
              job  control is disabled or, when run with job control enabled, any
              specified jobspec was not found or was started without job control.

 使用例  



[takuan@localhost ~]$ touch tmp.txt

→tmp.txtの作成


[takuan@localhost ~]$ vi tmp.txt
省略
~
~
"tmp.txt" 0L, 0C                                                        0,0-1        全て

[1]+  Stopped                 vim tmp.txt

→viでtmp.txtを開き、ctr+z で中断


[takuan@localhost ~]$ find / -name *.txt
find: /var/cache/mod_proxy: 許可がありません
省略

^Z
[2]+  Stopped                 find / -name *.txt

→findコマンドで検索中にctr+zで中断


[takuan@localhost ~]$ jobs
[1]-  Stopped                 vim tmp.txt
[2]+  Stopped                 find / -name *.txt


→現在のジョブの表示



[takuan@localhost ~]$ bg %2
[2]+ find / -name *.txt &

→bgコマンドにてバックグランドでfindコマンドを実行

[takuan@localhost ~]$ jobs
[1]+  Stopped                 vim tmp.txt
[2]-  Running                 find / -name *.txt &


jobsコマンドにて確認すると[2]のfindコマンドがRunningとなっている。




省略・・・
find: /etc/cups/ssl: 許可がありません

[2]-  Exit 1                  find / -name *.txt


→[2]がバックグランドで実行が終わる。


[takuan@localhost ~]$ jobs
[1]+  Stopped                 vim tmp.txt





 
サーバ構築(ランキング)
alias  コマンドの別名を登録する

 構文  
$ alias 別名='本来のコマンド'


≪aliasコマンド 説明   ≫

コマンドなどを

別名として登録する。



なお、aliasコマンドのオプションを省略し

alias コマンドを実行した場合は

現在登録してある別名をすべて表示します。

[takuan@localhost ~]$ alias
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'


もしくわ  オプション-pでもリストが表示されます。


[takuan@localhost ~]$ alias -p
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'



また,nameのみ指定した場合は,指定した別名についての登録状況を表示する。

[takuan@localhost ~]$ alias l.
alias l.='ls -d .* --color=auto'




       alias [-p] [name[=value] ...]
              Alias  with  no  arguments or with the -p option prints the list of
              aliases in the form alias  name=value  on  standard  output.   When
              arguments  are  supplied,  an  alias is defined for each name whose
              value is given.  A trailing space in  value causes the next word to
              be  checked for alias substitution when the alias is expanded.  For
              each name in the argument list for which no value is supplied,  the
              name  and value of the alias is printed.  Alias returns true unless
              a name is given for which no alias has been defined.


 使用例  

[takuan@localhost ~]$ alias la='ls -la'
[takuan@localhost ~]$ la
合計 28
drwx------ 4 takuan takuan 4096 2009-08-23 07:17 .
drwxr-xr-x 6 root   root   4096 2009-08-23 07:17 ..
-rw-r--r-- 1 takuan takuan   18 2008-02-29 23:27 .bash_logout
-rw-r--r-- 1 takuan takuan  176 2008-02-29 23:27 .bash_profile
-rw-r--r-- 1 takuan takuan  124 2008-02-29 23:27 .bashrc
drwxr-xr-x 2 takuan takuan 4096 2008-04-07 05:43 .gnome2
drwxr-xr-x 4 takuan takuan 4096 2009-08-20 22:18 .mozilla
[takuan@localhost ~]$ alias la
alias la='ls -la'


サーバ構築(ランキング)
リナックス コマンド useradd ユーザ作成

【説明】

useraddコマンド
新規にユーザアカウントを作成するコマンドです。
スーパーユーザのみ実行可能です。
su - root にてスーパユーザに変更後
useraddを実行できます。

構文
Usage: useradd [options] LOGIN

Options:
  -b, --base-dir BASE_DIR       base directory for the new user account
                                home directory
  -c, --comment COMMENT         set the GECOS field for the new user account
  -d, --home-dir HOME_DIR       home directory for the new user account
  -D, --defaults                print or save modified default useradd
                                configuration
  -e, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE
  -f, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -g, --gid GROUP               force use GROUP for the new user account
  -G, --groups GROUPS           list of supplementary groups for the new
                                user account
  -h, --help                    display this help message and exit
  -k, --skel SKEL_DIR           specify an alternative skel directory
  -K, --key KEY=VALUE           overrides /etc/login.defs defaults
  -l,                           do not add the user to the lastlog and
                                faillog databases
  -m, --create-home             create home directory for the new user
                                account
  -M,                     do not create user's home directory(overrides /etc/login.defs)
  -N, --no-user-group           do not create a group with the same name as
                                the user
  -o, --non-unique              allow create user with duplicate
                                (non-unique) UID
  -p, --password PASSWORD       use encrypted password for the new user
                                account
  -r, --system                  create a system account
  -s, --shell SHELL             the login shell for the new user account
  -u, --uid UID                 force use the UID for the new user account
  -U, --user-group              create a group with the same name as the user
  -Z, --selinux-user SEUSER     use a specific SEUSER for the SELinux user mapping


【-cオプション 例】

[root@localhost ~]# useradd -c izu azuki
useradd: ユーザ azuki は存在します
[root@localhost ~]# useradd -c commanduser user_name
[root@localhost ~]# su - user_name
[user_name@localhost ~]$ exit
logout
[root@localhost ~]# useradd -c comment user_name
useradd: ユーザ user_name は存在します

【-bオプション 例】

[root@localhost ~]# useradd -b /home oguraan
[root@localhost ~]# ls -l /home/oguraan
合計 0
[root@localhost ~]# su - oguraan
[oguraan@localhost ~]$


【-dオプション 例】
[root@localhost ~]# useradd -d /home/takuan takuan
[root@localhost ~]# ls -l /home/takuan
合計 0
[root@localhost ~]# su - takuan
[takuan@localhost ~]$ pwd
/home/takuan
[takuan@localhost ~]$


サーバ構築(ランキング)
[  条件式 真:true偽:false 判定  つづき

 条件式  



-n 文字列

文字列が1文字以上であれば
真:trueを返します。



-z 文字列

指定した文字列が
0文字であれば
真:trueを返します。



文字列1 = 文字列2

文字列1と文字列2が
同じ文字列であれば
真:trueを返します。


文字列1 != 文字列2

文字列1と文字列2が違ければ
真:trueを返します。


数値1 -eq 数値2
指定した数値1と数値2が
同じであれば
真:trueを返します。

数値1 -ne 数値2

数値1と数値2が
等しくなければ
真:trueを返します。


数値1 -lt 数値2

数値1が数値2より
小さければ
真:trueを返します。

数値1 -le 数値2

数値1が数値2より
小さいか同じであれば
真:trueを返します。

数値1 -gt 数値2

数値1が数値2より大きければ
真:trueを返します。

数値1 -ge 数値2

数値1が数値2より大きいか
同じであれば真:trueを返します。

! 条件式

条件式が偽:falseであれば
真:trueを返します。
(not)


条件式1 -a 条件式2

条件式1と条件式2の結果が
共に真:trueであれば
真:trueを返します。
(and)

条件式1 -o 条件式2

条件式1または条件式2の結果のいずれかが
真:trueであれば真:trueを返します。
(or)
 

 説明  
条件式を評価します。

0(真:true)か
0以外(偽:false)の戻り値を返します。
 


Lenovo IdeaPad S10e 4068-AGJ


サーバ構築(ランキング)
[  条件式 真偽 判定  つづき

 条件式  

-r

指定したファイルが存在しており、そのファイルが
読み取り可能(read)であれば真を返します。


-s

指定したファイルが存在 しており、そのファイルの
ファイル・サイズ(size)が1以上であれば真を返します。


-t

指定したファイルが端末で
オープンされていれば真を返します。


-u

指定したファイルが存在しており、そのファイルの
パーミッションにセット・ユーザーIDが付いていれば真を返します。

セット・ユーザーIDについて

  chmod 4775 file.txt

    最初の 4 がセット・ユーザ ID を設定しています。
    ls -l file.txt と実行すると
   -rwsrwxr-x と表示されます。
    所有者の rwx が rws と表示されます。


-w

指定したファイルが存在しており、そのファイルが
書き込み可能(write)であれば真を返します。


-x

指定したファイルが存在しており、そのファイルが
実行可能であれば真を返します。





file1 -nt file2

file11がfile2より
修正時刻が新しければ真を返します。


file1 -ot file2

file1がfile2より修正時刻が古ければ真を返します。


file1 -ef file2

file11とfile2のデバイス番号と
iノード番号が同じであれば真を返します。



つづきはこちら・・・・


 





サーバ構築(ランキング)
[  条件式の真偽を判定する (1)

 構文  
[ 条件式 ]  

 条件式  

-G

指定したファイルが存在し,
ファイルのグループ groupが
現在実行しているユーザーであれば真を返す


-O

指定したファイルが存在し,
ファイルの所有者 ownerが
現在実行しているユーザーであれば真を返す


-S

指定したファイルが存在し,
ソケット(socket)であれば真を返す

ソケット
IPアドレスとIPアドレスのサブアドレスであるポート番号を
組み合わせたネットワークアドレスのこと


-b

指定したファイルが存在し,
ブロック・デバイスであれば真を返す

ハードディスクやCD-ROMなどの記憶装置が代表的なブロックデバイスです。

-c

指定したファイルが存在し,
キャラクタ・スペシャル・ファイルであれば真を返す


スペシャルファイルまたはデバイスファイルとは
ファイルシステム上であたかも通常のファイルのような形で
提示されるデバイスドライバのインタフェースである。


-d

指定したファイルが存在し,
ディレクトリ(directory)であれば真を返す


-e

指定したファイルが
存在(existence)すれば真を返す

-f

指定したファイルが存在し,
通常のファイルであれば真を返す

-g

指定したファイルが存在し,
パーミッションにセット・グループIDが付いていれば真
小文字のgです。


-k

指定したファイルが存在し,
パーミッションにスティッキ・ビットが付いていれば真

スティッキ・ビットは,
Linuxなどにおけるファイルのアクセス権限の一つです。
「すべてのユーザーが書き込めるものの,所有者だけしか削除できない」
といったアクセス権限をスティッキ・ビットを用いると設定できます。



続きはこちら・・・・




サーバ構築(ランキング)
linux #  コメント 記述

 【linux 勉強:構文】
# コメント  

記号のシャープ # が頭にある行は
コメントとなります。


 【linux 勉強:構文】

シェル・スクリプトの作成で

利用方法など、その他コメントを

書きたい場合にコマンド:シャープ #が利用される。

行頭に「#」を付けると,その行は実行されない。

また,シェル・スクリプトの最初に記載する「#!/bin/sh」は

コメントではありません。

このシェル・スクリプトで利用するシェルを

指定しています。
 

 【linux 勉強:コマンド 使い方】

シェル・スクリプトに記載した場合の例です。

#  作成者:taro
#  作成日:2009/2/20

 



サーバ構築(ランキング)
linux 勉強 コマンド 順に実行 ; セミコロン コマンド区切り

 【linux 勉強:構文】
コマンド ; コマンド

コマンドとコマンドの間に

セミコロンを入れる。



 【linux 勉強:構文】

複数のコマンドを順に実行する方法は?

コマンドの間に「;」記号を挿入することで

順番に実行されます。


なお、セミコロンは右から順にコマンドを

実行させるのみで、

コマンド間で出力結果を引き渡しません。

 

 【linux 勉強:コマンド 使い方】

1.findでファイルを検索する。
さらに、他のファイルを検索する

$ find / -name "txt" > txt_result ; find / -name "doc" doc_result
 
2.ls を実行し、
.logファイルの2009で検索する。

$ls -l ; grep "2009" *.log



 
サーバ構築(ランキング)
||  パイプ 1つ目のコマンド 実行失敗  2つ目のコマンド 実行

 【linux 勉強:構文】
コマンド || コマンド  




 【linux 勉強:説明】】

|| パイプ

2つのコマンドの間に

差し込んで利用するコマンドです。

まず、|| パイプの前方のコマンドを実行して,

その前方のコマンドを実行した結果、

正常に終了しなかった(戻り値が0以外)場合に限り、

|| の後ろにあるコマンドを実行します。

||の前方のコマンドが正常に終了した場合は

||の後ろのコマンドを実行されません。






 【linux 勉強:コマンド 使い方】

1.シェル実行

make.sh を実行して正常に終了しなかったら、

make_2.sh プログラムを実行する

$ make.sh || make_2.sh

 


 
サーバ構築(ランキング)
linux 勉強 |  パイプ コマンドの出力 次コマンド 入力 渡す

 【linux 勉強:パイプの構文】

コマンド | コマンド  

コマンドとコマンドの間に

パイプ |

を入力します。




 【linux 勉強:説明】】

左側のコマンドの標準出力を

右側のコマンド標準入力に渡すコマンドです。
 

 【linux 勉強:コマンド 使い方】

$ cat IP.txt | grep 192 | grep 2009

cat の出力をパイプで渡して、 grepで192で検索する。

さらに、結果をパイプで渡して

grepで2009で検索する。





$ ls -l | more

lsの出力をパイプで渡して

moreで表示する。




 



サーバ構築(ランキング)
linux 勉強 <<  入力 終端 通知

 【linux 勉強:構文】

linux コマンド   <<

入力 終端文字列   についてです。




 【 << の説明】

<<は,入力が終わりであることを

通知するために使用するコマンドです。

<<の右側に来る文字列が

終了を通知するための

ワード 言葉 となります。
 

詳しくは↓の例をどうぞ。



 【コマンド 使い方】

catコマンドでtext.txtを編集する。

そして、catでの入力の終わりを"FIN"とする

最終行にFINを入力しエンターを

押せば編集完了となる。

$ cat > test.txt << FIN




 
 【linux 勉強:関連 コマンド】
cat








 
サーバ構築(ランキング)