LINUX

operating systemである。もともとMSーDOSのような真っ黒の画面で、キーボードからコマンドを打ち込むと言うシステム。そのプログラムの一つがx -window-systemで、これをたちあげるとウインドウズのような画面になる.(最初はそれすら知らなかった。)

commands

必要と思われるリナックスコマンドを列挙する。

    file (file-tyoeを示す.
    mkdir -p (p optionでchild dirを含めて作る。)
    mv ../report[1-4].doc /reports/Resaturants.M../   (移動)
    mv ToDo Done (rename)
    cp [-R] fromfile tofile (-R= all underlying files and subdirectories)
    rm     (remov single file)
    rmdir (remove empty directopry)
        -i option(inflict)で確認---- rm -ri srchive/
    which (実行可能プログラムを探す)--- command not found のとき便利
    which -a ls(aliasであるかを check)
        ls is aliased to `/s -F --color= auto'
        ls is /bin/ls これが機能しないなら
        alias ls
        alias is = `ls --color' とする。
    find <path> -name<searchstring>
        path 中の 全ファイルとsubdirectoris を探しsearchstring を名前中に含むファイルをプリントせよ。
        find .size +5000k
        find .name "*.tmp"  -exec rm {} \;  --*.tmpを削除する。
    locate(findよりeasier to use)

special modes

    sticky bit mode(/var/tmpで使われている.誰でもディレクトリにアクセスできるがファイル変更できるのはファイル所有者かパーミッションある場合のみ(ルート)。drwxrwxrwt  : /tmp/が例
    SUID :  user id以外通常実行できないタスクを通常のユーザーにできるようにする。(passwd)
    SGID:group id以外通常実行できないタスクを通常のユーザーにできるようにする。または誰が作ろうともこのモードが付いたディレクトリ中のファイルは親と同じグループ所有となる。

standard file permission は mask で決められる。これはumaskでdisplay表示 される。
    umask 0002
        mkdir test----> drwxrwxr-xのディレクトリができる(777から775)
        touch newfile ---> -rw-rw-r--のファイルができる。(666から664)
        directoryにXがなかったらアクセスできない。
chown chgrp
    chown jacky:myreport としたらuser jacky, group myreport     となる。

processes

  コンピュータのメモリ使用中のプログラムのこと

controlling processes


(part of) command Meaning
regular_command Runs this command in the foreground.
command & Run this command in the background (release the terminal)
jobs Show commands running in the background.
Ctrl+Z Suspend (stop, but not quit) a process running in the foreground (suspend).
Ctrl+C Interrupt (terminate and quit) a process running in the foreground.
%n
Every process running in the background gets a number assigned to it. By using the % expression a job can be referred to using its number, for instance fg %2.
bg Reactivate a suspended program in the background.
fg Puts the job back in the foreground.
kill End a process (also see Shell Builtin Commands in the Info pages of bash)

process attributes

PID(process ID)
    PPID(Parent process ID)
    Nice number
    TTY(terminal to which this process is committing)
    RUID,EUID(通常同じ、real and effective user ID:プロセスの所有者)
    RGID,EGID(group)
    ps   現在のshell & eventual process のみ表示
    ps -ef | grep username : all processes owned by a paticular user
    ps awxw | grep bash : process name bash のプロセス
    top 5秒ごとにps更新して表示
以下略

scheduling processesscheduling processes

    (sleep 1800; echo "Lunchtime...")&  30分経って"L...  "表示
    at tomorrow +2 days
    略
    cron

Command Meaning
at Queue jobs for later execution.
atq Lists the user's pending jobs.
atrm Deletes jobs, determined by their job number.
batch Executes commands when system load level permits.
crontab Maintain crontab files for individual users.
halt Stop the system.
init run level Process control initialization.
jobs Lists currently executing jobs.
kill Terminate a process.
mesg Control write access to your terminal.
netstat Display network connections, routing tables, interface statistics, masquerade connections and multicast memberships.
nice Run a program with modified scheduling priority.
pgrep Display processes.
ps Report process status.
pstree Display a tree of processes.
reboot Stop the system.
renice Alter priority of running processes.
shutdown Bring the system down.
sleep Delay for a specified time.
time Time a command or report resource usage.
top Display top CPU processes.
uptime Show how long the system has been running.
vmstat Report virtual memory statistics.
w Show who is logged on and what they are doing.
wall Send a message to everybody's terminals.
who Show who is logged on.
write Send a message to another user.

cron and crontab
# cd /etc
/etc/ # more crontab
    1st field 0~59 (min) of execution
    2nd field 0~23 (hour) of execution
    3rd                      dayof month
    4th                     month
    last  dayof the week 0&7=sunday
crontab -e     で編集

I/O redirection

simple redirection (>&|)

    cat test1 ...some words
    cat test2 ... some other words
    cat test1 test2 > test3
    cat test3
        some words
        some other words
        (file 上書きを防ぐために.bashrcにset -o noclobberと書くことができる。)
   
    truncating    >list で list を空にできる。

    grep pattern1 file | grep -v pattern2(pattern1 に matchする 全  lineを探しpattern2 に matchするlineを除外して表示。)
    ls -la | less
    ls -l | grep part _of_file_name

input redirection


    echo "this is ouryouji's test" > test1
    mail ouryouji < test1    で/var/mail/ouryouji 中に このmessage あり。
        (mailutils の install がまず必要。)

combining redirection

    inputとoutputのcombined redirection
    spell < txt.txt > error.log(まずスペルチェックされて    error.logに出力。)
    less --help | grep -i examine  --- -i ignore case
    less --help | grep -i examine >examine-files-in-less

The >> operator

    ---appendする。
    cat wishlist
        more money
        less work
    date >> wishlist

advanced

file descriptors
    standard input :0(標準入力)
    standard output :1(標準出力)
    standard error :2(標準エラー)
file descriptor number が省略されかつredirector operator  の最初が<なら redirectionは 標準入力であり、>なら標準出力である。
    ls >dirlist 2>&1 (まず>(standard out=)dirlistとなるからすべてdirlistに入る。)
    ls 2>&1 >dirlist (ls の標準出力のみ dirlist に向けられる)



Filters

grep
sort




fundamental backup techniques

gnutarのみを使うように!

Archiving with tar

    tar -v:verbose
        -t:test
        -x:extract
        -c:create
        -f archive device; source/destinator  として使う (デフォルトではstdin/stdout)
        -j:filter through bzip2
    (dash - prefixは通常不要)
example
ls images/
m.jpg n.jpg
tar cvf images-in-a-dir.tar images/
images/m.jpg
images/n.jpg
cd images
tar cvf images-without-a-dir.tar  *.jpg
        m.jpgg
        n.jpg
cd
ls */*.tar
        images-without-a-dir.tar
ls *.tar
images-in-a-dir.tar
tar xvf images-in-a-dir.tar
        images/
        images/m.jpg
        images/n.jpg
without-a-dir を展開するよりも望ましい。


incremental backup with tar

        N optionで incremental backup(日付が新しいものだけstore)
tar cvpf /var/tmp/javaproggies.tar  java/*.java
    --.java
    --.java
    --
ls -l /var/tmp/javaproggies.tar
touch java/newprog.java
tar -N /var/tmp/javaproggies.tar -cvpf /var/tmp/incremental1-javaproggies.tar  java/*.java 2> /dev/null
cd /var/tmp/
tar xvf incremental1-javaproggies.tar
    java/newpro.java
欠点 incrementしようとするarchive  中に initial archiveより古いものがあると、Noptipnがあるとinclude されない。
よりよい選択はg-option(リストを作りこれでチェックされたバックアップする)
tar cvfp work-20111223.tar -g snapshot-20111223 work/
work/
work/file1
work/file2
work/file3
file snapshot-20111223
翌日file3をいじり、file4を作って、新しいbackupを作る。
tar cvpf work-20111224.tar -g snapshot-20111223 work/
work/
work/file3
work/file4
この種のコマンドをcronで使う。
snapshotはfull backupするときreplaceされる。

compression and unpacking with gzip or bzip2

gzipはsuffix.gzを作りoriginal file をrenameする。
gzip images-without-dir.tar
gnu-tar は gzipped fileを知っている。command
tar zxvf file.atr.gz を使う。
unzipするには
tar jxvf file.tar.bz2   など使う。




using rsync:remotebackup(ただしremoteとは限らない。)

an example;rsync to a USB storage device
#    mkdir /mnt/usbstore
#    mount  -t vfat       /dev/sda1      /mnt/usbstore
                  type指定,  device(USB),     dir
rsync -arz /home/**/** /mnt/usbstore
    -a    archive mode
    -v     verbose
    -z    compress

Eucryption

dataの暗号化前に鍵ペアを作る。(private key & public key)
gpg  --key-gen(--gen-key?)


コマンドサマリー
bzip2
ファイルコンプレッサー
cdrecord

dd
convert and copy a file
fdformat

gpg
encrypt and decrypt data
gzip
compress or expand a file
mount
mount
rsync synchronize directories
tar

unmount



networking