View on GitHub

lectures

UNIX 入門

unix/Home


UNIX とは


なぜ UNIX か


UNIX を使う上での注意点


ファイルシステム


ホームディレクトリ


ディレクトリ関連のコマンド


ファイル操作関連のコマンド


検索

$ find . -name hoe.txt -print
$ find . -mtime -10 -print
.
./.config/dconf
./.config/dconf/user
./.config/google-chrome
./.config/google-chrome/WidevineCdm
...
$ grep "hoe" *.txt

標準入力と標準出力

接続先は変更が可能


パイプとリダイレクト


コマンドの使い方がわからないとき

$ man grep # この例ではgrepコマンドのマニュアルを表示
GREP(1)                                                                         User Commands                                                                         GREP(1)

NAME
       grep, egrep, fgrep, rgrep - print lines matching a pattern

SYNOPSIS
       grep [OPTIONS] PATTERN [FILE...]
...
# 'q'キーで終了

実習(1)


権限の管理


権限の設定


グループ


ディレクトリに対する権限


権限の設定方法


実習(2)

$ cd /
$ touch hoe.txt
touch: 'hoe.txt'touch できません: 許可がありません
$ cd /tmp
$ touch hoe.txt
$ chmod u-r hoe.txt
$ less hoe.txt
hoe.txt: 許可がありません

コマンドの実体


関連するコマンド

$ echo $PATH
/opt/ros/melodic/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$ which ls
/bin/ls
$ PATH=$PATH:/home/usrs/moto/bin
$ export PATH

コマンドファイルの中身

実行できるファイルの条件

実行可能な形式

$ file /bin/ls
/bin/ls: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 3.2.0, BuildID[sha1]=9567f9a28e66f4d7ec4baf31cfbf68d0410f0ae6, stripped

実行コマンドの指定付きファイル

#!python
#!/usr/bin/python
# 2行目以降は python 用のプログラム

ちょっと特殊な例

#!/usr/bin/emacs -nw

textline
nextline
$ chmod u+x textfile.txt
$ ./textfile.txt
(/usr/bin/emacs -nw textfile.txt と同じ)

実習(3)

$ which less

unix/Home