2018年04月24日
情報科学類 コンピュータリテラシ
                                       筑波大学 システム情報系
                                       新城 靖
                                       <yas@cs.tsukuba.ac.jp>
このページは、次の URL にあります。
	http://www.coins.tsukuba.ac.jp/~yas/coins/literacy-2018/2018-04-24
あるいは、次のページから手繰っていくこともできます。
	http://www.coins.tsukuba.ac.jp/~yas/
	http://www.cs.tsukuba.ac.jp/~yas/
木構造(tree structure)というのは、コンピュータ・サイエン ス(情報科学類で学ぶ学問)でよく使われる用語。 階層構造(hierarchical structure)ともいう。
木構造の例を、大学の組織を使って説明する(図?)。

図? 大学組織に見られる木構造
 
図? 大学組織に見られる木構造(領域的な見方)
A、B、2つの集合があると、一般には、次の4つに分割される。
 
図? 2つの集合の関係
筑波大学
コンピュータの中で、文字列(文字の並び)で木構造上の位置を表現する時に は、節が分かりやすくために、はっきりと区切りを入れて表現することがよく 行われる。
区切り文字としては、「.」(点)、「/」(スラッシュ)、「\」(バック スラッシュ)、「¥」(円記号)などがよく使われる。単語を並べる時に、木 の根に近いほうから書く流儀と遠い方から書く流儀がある。
コンピュータでは、次のような場所で木構造が使われている。
コンピュータ以外では、次のような場所で木構造が使われている。
http://www.softlab.cs.tsukuba.ac.jp/~yas/gen/it-2017-11-20/

図? 本物の木

図? ファイルとディレクトリの木
ルート・ディレクトリの名前は、「/」 (スラッシュ 1 文字)。
ルートディレクトリから出発する方法で表記するパス名を、 絶対パス名(absolute path name)
絶対パス名は、ルートディレクトリを表す「/」の後に、 たどった枝の名前を並べ、間に区切りとして「/」をはさむ。
例:「/usr/bin/wc」
usr」という枝に進む
bin」という枝に進む
wc」という枝に進む
カレント・ワーキング・ディレクトリを表示するには、pwd (print working directory) コマンドを使う。
$ pwd ![[←]](../icons/screen-return.gif) /USA/California
$
/USA/California
$ ![[]](../icons/screen-cursor.gif) 
表示されている「/USA/California」が絶対パス名で表示されたカレント・ワー
キング・ディレクトリの名前。
カレント・ワーキング・ディレクトリを変更するには cd (change directory) コマ
ンドを使う。
$ cd dirname ![[←]](../icons/screen-return.gif) 
「ディレクトリ dirname に行く」とも言う。
図? 世界の街の木構造
$ pwd ![[←]](../icons/screen-return.gif) /USA/California
$ cd /USA/Florida
/USA/California
$ cd /USA/Florida ![[←]](../icons/screen-return.gif) $ pwd
$ pwd ![[←]](../icons/screen-return.gif) /USA/Florida
$ cd /USA/California/San-Francisco
/USA/Florida
$ cd /USA/California/San-Francisco ![[←]](../icons/screen-return.gif) $ pwd
$ pwd ![[←]](../icons/screen-return.gif) /USA/California/San-Francisco
$
/USA/California/San-Francisco
$ ![[]](../icons/screen-cursor.gif) 
カレントワーキングディレクトリは、名前「.」で参照できる。
lsコマンドは引数にディレクトリを指定すると、そのディレクトリの中にある
ファイルの一覧を表示するが、引数を与えないと、「.」が与えられたものとし
て働く。
$ ls ![[←]](../icons/screen-return.gif) Los-Angeles  San-Francisco
$ pwd
Los-Angeles  San-Francisco
$ pwd ![[←]](../icons/screen-return.gif) /USA/California
$ ls /USA/California
/USA/California
$ ls /USA/California ![[←]](../icons/screen-return.gif) Los-Angeles  San-Francisco
$ ls .
Los-Angeles  San-Francisco
$ ls . ![[←]](../icons/screen-return.gif) Los-Angeles  San-Francisco
$
Los-Angeles  San-Francisco
$ ![[]](../icons/screen-cursor.gif) 
カレントワーキングディレクトリを起点としたパス名を
相対パス名(relative path name)という。
「/USA/California」の時、
「San-Francisco」は「/USA/California/San-Francisco」、
「San-Francisco/China-Town」は「/USA/California/San-Francisco/China-Town」を意味する。
..」で参照可能。
../ディレクトリ名」で参照可能。
cd コマンドに引数を与えないと、ホーム・ディレクトリにもどる。
多くのシェル(csh,tcsh,bash,zsh)
やEmacsなどでは、
ホームディレクトリを「~」で指定できる
(指定できないプログラムもある。)
「〜」は、英語の端末(ASCII,後述)の形。
日本語(JIS,後述) では、「 ̄」となることがある。
他人のホーム・ディレクトリは、「~ユーザ名」で指定できるプログラムがある。
(指定できないもプログラムもある。)
「~xxx」と「~/xxx」のように
「~」直後に「/」の有無で意味が違う。
ls -l コマンドを実行するとカレントディレクトリのファイルや ディレクトリの属性が表示される。
$ ls -l ![[←]](../icons/screen-return.gif) total 99
drwx------   4 yas  prof   3072  4 10 17:37 Desktop
drwx------   3 yas  prof   1024  3 11 13:52 Documents
drwx------@ 34 yas  wheel  2048  4 18 10:05 Library
drwx------  20 yas  prof   2048  4 18 10:57 Maildir
drwx------   2 yas  prof   1024  4 21 16:03 Music
-rw-r--r--   1 yas  prof   3178  4 15 15:56 file100.txt
-rw-r--r--   1 yas  prof     25  4 15 15:58 file30
-rw-r--r--   1 yas  prof   2550  4 15 15:59 literacy-a2.txt
-rw-r--r--   1 yas  prof   2550  4 15 15:57 literacy-a2.txt~
...
$
total 99
drwx------   4 yas  prof   3072  4 10 17:37 Desktop
drwx------   3 yas  prof   1024  3 11 13:52 Documents
drwx------@ 34 yas  wheel  2048  4 18 10:05 Library
drwx------  20 yas  prof   2048  4 18 10:57 Maildir
drwx------   2 yas  prof   1024  4 21 16:03 Music
-rw-r--r--   1 yas  prof   3178  4 15 15:56 file100.txt
-rw-r--r--   1 yas  prof     25  4 15 15:58 file30
-rw-r--r--   1 yas  prof   2550  4 15 15:59 literacy-a2.txt
-rw-r--r--   1 yas  prof   2550  4 15 15:57 literacy-a2.txt~
...
$ ![[]](../icons/screen-cursor.gif) 
行単位に次のようなファイルやディレクトリの属性が表示さる。
drwx------,drwxr-xr-x,-rw------- など)
6,4,17,... など)
yas)
prof)
3072,1024,25など)
4月10日17時37分など)
Desktopなど)
ls -lu で表示される。
ls -lcで表示される「時刻」。
ファイルの型
モードの一番左1文字は、ファイルの型(type)を表わす。-
d
許可されたアクセス方法
モードからファイルの型を除いた部分はアクセスの可否を決めるための 情報。主に r, w, x, - の組み合わせの 9 文字。詳しくは、後述する。 新Linux/UNIX入門 06 ファイルのアクセス制御 参照、 新Linux/UNIX入門 06-058 パーミッションマスクの設定(umask) 参照、 The Unix Super Text 9.5.5項 モード 参照、 The Unix Super Text 21.5節 マスクとモード 参照。
補完(completion)では、人間が目で確認するが、置き換えでは人間が確認する ことはない(見つからなければエラーになる)。
例:/usr/bin にある at で始まるファイルをすべて
ls コマンドに引き渡したい。1つひとつ打つと疲れる。
$ ls -l /usr/bin/at /usr/bin/atos /usr/bin/atq /usr/bin/atrm /usr/bin/atsutil ![[←]](../icons/screen-return.gif) -r-sr-xr-x  4 root  wheel  75648  3 18 14:09 /usr/bin/at
-rwxr-xr-x  1 root  wheel  90960  2  6 17:03 /usr/bin/atos
-r-sr-xr-x  4 root  wheel  75648  3 18 14:09 /usr/bin/atq
-r-sr-xr-x  4 root  wheel  75648  3 18 14:09 /usr/bin/atrm
-rwxr-xr-x  1 root  wheel  25568  3 18 14:08 /usr/bin/atsutil
$
-r-sr-xr-x  4 root  wheel  75648  3 18 14:09 /usr/bin/at
-rwxr-xr-x  1 root  wheel  90960  2  6 17:03 /usr/bin/atos
-r-sr-xr-x  4 root  wheel  75648  3 18 14:09 /usr/bin/atq
-r-sr-xr-x  4 root  wheel  75648  3 18 14:09 /usr/bin/atrm
-rwxr-xr-x  1 root  wheel  25568  3 18 14:08 /usr/bin/atsutil
$ ![[]](../icons/screen-cursor.gif) 
次のように、「*」を使うと楽に打てる。
$ ls  -l /usr/bin/at* ![[←]](../icons/screen-return.gif) -r-sr-xr-x  4 root  wheel  75648  3 18 14:09 /usr/bin/at
-rwxr-xr-x  1 root  wheel  90960  2  6 17:03 /usr/bin/atos
-r-sr-xr-x  4 root  wheel  75648  3 18 14:09 /usr/bin/atq
-r-sr-xr-x  4 root  wheel  75648  3 18 14:09 /usr/bin/atrm
-rwxr-xr-x  1 root  wheel  25568  3 18 14:08 /usr/bin/atsutil
$
-r-sr-xr-x  4 root  wheel  75648  3 18 14:09 /usr/bin/at
-rwxr-xr-x  1 root  wheel  90960  2  6 17:03 /usr/bin/atos
-r-sr-xr-x  4 root  wheel  75648  3 18 14:09 /usr/bin/atq
-r-sr-xr-x  4 root  wheel  75648  3 18 14:09 /usr/bin/atrm
-rwxr-xr-x  1 root  wheel  25568  3 18 14:08 /usr/bin/atsutil
$ ![[]](../icons/screen-cursor.gif) 
この例では、シェルが「/usr/bin/at*」を5つのファイル名に置き換え
ている。ls が行っているのではない。ls以外のどんなプログラ
ムでも有効である。
$ echo /usr/bin/at* ![[←]](../icons/screen-return.gif) /usr/bin/at /usr/bin/atos /usr/bin/atq /usr/bin/atrm /usr/bin/atsutil
$ file /usr/bin/at*
/usr/bin/at /usr/bin/atos /usr/bin/atq /usr/bin/atrm /usr/bin/atsutil
$ file /usr/bin/at* ![[←]](../icons/screen-return.gif) /usr/bin/at:      setuid Mach-O universal binary with 2 architectures
/usr/bin/at (for architecture x86_64):	  Mach-O 64-bit executable x86_64
/usr/bin/at (for architecture i386):	  Mach-O executable i386
/usr/bin/atos:    Mach-O universal binary with 2 architectures
/usr/bin/atos (for architecture x86_64):  Mach-O 64-bit executable x86_64
/usr/bin/atos (for architecture i386):	  Mach-O executable i386
/usr/bin/atq:     setuid Mach-O universal binary with 2 architectures
/usr/bin/atq (for architecture x86_64):	  Mach-O 64-bit executable x86_64
/usr/bin/atq (for architecture i386):	  Mach-O executable i386
/usr/bin/atrm:    setuid Mach-O universal binary with 2 architectures
/usr/bin/atrm (for architecture x86_64):  Mach-O 64-bit executable x86_64
/usr/bin/atrm (for architecture i386):	  Mach-O executable i386
/usr/bin/atsutil: Mach-O 64-bit executable x86_64
$
/usr/bin/at:      setuid Mach-O universal binary with 2 architectures
/usr/bin/at (for architecture x86_64):	  Mach-O 64-bit executable x86_64
/usr/bin/at (for architecture i386):	  Mach-O executable i386
/usr/bin/atos:    Mach-O universal binary with 2 architectures
/usr/bin/atos (for architecture x86_64):  Mach-O 64-bit executable x86_64
/usr/bin/atos (for architecture i386):	  Mach-O executable i386
/usr/bin/atq:     setuid Mach-O universal binary with 2 architectures
/usr/bin/atq (for architecture x86_64):	  Mach-O 64-bit executable x86_64
/usr/bin/atq (for architecture i386):	  Mach-O executable i386
/usr/bin/atrm:    setuid Mach-O universal binary with 2 architectures
/usr/bin/atrm (for architecture x86_64):  Mach-O 64-bit executable x86_64
/usr/bin/atrm (for architecture i386):	  Mach-O executable i386
/usr/bin/atsutil: Mach-O 64-bit executable x86_64
$ ![[]](../icons/screen-cursor.gif) 
echo は、引数をそのまま表示するコマンド、
file は、ファイルの種類を表示するコマンドである。
| パタン | 意味 | 
| * | 任意の文字列(空でもよい)(.で始まるものを除く) | 
| ? | 任意の1文字 | 
| [str] | strのなかの1文字。たとえば [aA] は、a か A とマッチする。「-」があると、ASCIIでその間の文字を意味する。たとえば [0-9](数字)や[a-zA-Z](アルファベット)がよく使われる。 | 
| {str1,str2,...} | 「,」で区切られたパタン str1, str2, ... を順にファイル名置換した結果を並べたもの | 
| ~username | ユーザusernameのホーム・ディレクトリの絶対パス。 | 
| ~/ | 自分自身のホーム・ディレクトリ | 
| ~ | 自分自身のホーム・ディレクトリ | 
よく使われる形式
*」と「*.*」は違う。Windowsで「*.*」と書く
所、Unixでは、「*」で十分なことが多い。
$ ls -ld /Applications/QuickTime Player.app ![[←]](../icons/screen-return.gif) ls: /Applications/QuickTime: No such file or directory
ls: Player.app: No such file or directory
$
ls: /Applications/QuickTime: No such file or directory
ls: Player.app: No such file or directory
$ ![[]](../icons/screen-cursor.gif) 
「?」や「*」で置き換え可能な場合が多い。
$ ls -ld /Applications/QuickTime*Player.app ![[←]](../icons/screen-return.gif) drwxr-xr-x+ 3 root  wheel  102  3 18 14:11 /Applications/QuickTime Player.app
$ ls -ld /Applications/QuickTime?Player.app
drwxr-xr-x+ 3 root  wheel  102  3 18 14:11 /Applications/QuickTime Player.app
$ ls -ld /Applications/QuickTime?Player.app ![[←]](../icons/screen-return.gif) drwxr-xr-x+ 3 root  wheel  102  3 18 14:11 /Applications/QuickTime Player.app
$
drwxr-xr-x+ 3 root  wheel  102  3 18 14:11 /Applications/QuickTime Player.app
$ ![[]](../icons/screen-cursor.gif) 
バックスラッシュ「\ 」や" " を使う方法もある。
$ ls -ld /Applications/QuickTime\ Player.app ![[←]](../icons/screen-return.gif) drwxr-xr-x+ 3 root  wheel  102  3 18 14:11 /Applications/QuickTime Player.app
$ ls -ld "/Applications/QuickTime Player.app"
drwxr-xr-x+ 3 root  wheel  102  3 18 14:11 /Applications/QuickTime Player.app
$ ls -ld "/Applications/QuickTime Player.app" ![[←]](../icons/screen-return.gif) drwxr-xr-x+ 3 root  wheel  102  3 18 14:11 /Applications/QuickTime Player.app
$
drwxr-xr-x+ 3 root  wheel  102  3 18 14:11 /Applications/QuickTime Player.app
$ ![[]](../icons/screen-cursor.gif) 
ls, ls -l, ls -ld, ls -a 
cat
cp
cd、pwd
mkdir, rmdir
mv
rm
ls コマンドは、標準では、カレント・ワーキング・ディレクトリを意
味する「.」や親ディレクトリを意味する「..」を含めて、
「.」から始まるファイル名を表示しない。-a オプションを付
けると、「.」から始まるファイル名も表示する。ホーム・ディレクト
リには、「.」で始まるファイルがいくつか存在する。
$ ls ![[←]](../icons/screen-return.gif) Desktop         Library         Music           Public          WinFiles
Documents       Movies          Pictures        Sites           public_html
$ ls -a
Desktop         Library         Music           Public          WinFiles
Documents       Movies          Pictures        Sites           public_html
$ ls -a ![[←]](../icons/screen-return.gif) .                       .cshrc~                 Movies
..                      .emacs                  Music
.CFUserTextEncoding     .emacs.d                Pictures
.DS_Store               .login                  Public
.Spotlight-V100         .profile                Sites
.Xauthority             .ssh                    WinFiles
.backupfiles2006        Desktop                 public_html
.bashrc                 Documents
.cshrc                  Library
$
.                       .cshrc~                 Movies
..                      .emacs                  Music
.CFUserTextEncoding     .emacs.d                Pictures
.DS_Store               .login                  Public
.Spotlight-V100         .profile                Sites
.Xauthority             .ssh                    WinFiles
.backupfiles2006        Desktop                 public_html
.bashrc                 Documents
.cshrc                  Library
$ ![[]](../icons/screen-cursor.gif) 
ls コマンドは、引数にディレクトリ名が与えられると、ディレクトリ
の内容を表示する。
$ ls -l ~/Maildir ![[←]](../icons/screen-return.gif) total 113
drwx------  2 yas  prof  35840  4 18 11:00 cur
drwx------  2 yas  prof  17408  4 18 10:57 new
drwx------  2 yas  prof   1024  4 18 11:37 tmp
$
total 113
drwx------  2 yas  prof  35840  4 18 11:00 cur
drwx------  2 yas  prof  17408  4 18 10:57 new
drwx------  2 yas  prof   1024  4 18 11:37 tmp
$ ![[]](../icons/screen-cursor.gif) 
ディレクトリそのものを表示したい時(特に「-l」と組み合わせて日付
等の属性を表示したい時)は、「-d」オプションを付ける。
$ ls -ld ~/Maildir ![[←]](../icons/screen-return.gif) drwx------  20 yas  prof  2048  4 18 10:57 /home/prof/yas/Maildir
$
drwx------  20 yas  prof  2048  4 18 10:57 /home/prof/yas/Maildir
$ ![[]](../icons/screen-cursor.gif) 
$ cp file1 file2 dir ![[←]](../icons/screen-return.gif) 
この場合、dir 以下に、(一番葉の部分だけ)同じ名前のファイルが作られる。
次の操作と概ね同じ動作をする。
$ cp file1 dir/file1  ![[←]](../icons/screen-return.gif) $ cp file2 dir/file2
$ cp file2 dir/file2 ![[←]](../icons/screen-return.gif) 
ディレクトリを指定する時には、カレント・ワーキング・ディレクトリ 「.」 や ホーム・ディレクトリ「〜」も使える。
$ cp /etc/group . ![[←]](../icons/screen-return.gif) $ cp /etc/group ~
$ cp /etc/group ~ ![[←]](../icons/screen-return.gif) $ cp ~yas/public_html/htdocs/coins/literacy-2018/2018-04-24/literacy-a100.txt .
$ cp ~yas/public_html/htdocs/coins/literacy-2018/2018-04-24/literacy-a100.txt . ![[←]](../icons/screen-return.gif) 
ファイルを消すには、rm (remove) コマンドを用いる。
$ rm file1 ![[←]](../icons/screen-return.gif) 
このファイル file1 が削除される。
rm コマンドで消してしまったファイルは、普通2度と戻らない。 消す前に、本当に不要かどうかを確認すること。
コマンド名の置換え(alias)等て、rm を rm -i に変えることは、一般的には勧
められない。「rm -i ![[←]](../icons/screen-return.gif) y」という操作が、一連の操作として身に付い
てしまうので。
 y」という操作が、一連の操作として身に付い
てしまうので。
ファイル名を変更するには mv (move) コマンドを使う。
$ mv oldname newname ![[←]](../icons/screen-return.gif) 
この結果、ファイルoldfileのファイル名をnewnameに変更される。
ここで、newname のファイルが存在した場合、元の newname は消されてしまう。
$ mkdir dirname ![[←]](../icons/screen-return.gif) 
この結果、dirnameという名前のディレクトリが作らる。
mvコマンドは、ディレクトリの名前を変更するために使える。
$ mkdir dir1 ![[←]](../icons/screen-return.gif) $ ls
$ ls  ![[←]](../icons/screen-return.gif) dir1
$ mv dir1 dir2
dir1
$ mv dir1 dir2 ![[←]](../icons/screen-return.gif) $ ls
$ ls  ![[←]](../icons/screen-return.gif) dir2
$
dir2
$ ![[]](../icons/screen-cursor.gif) 
$ mkdir ~/dir1 ![[←]](../icons/screen-return.gif) $ mv oldname ~/dir1/newname
$ mv oldname ~/dir1/newname ![[←]](../icons/screen-return.gif) 
この結果、カレント・ワーキング・ディレクトリにある
ファイルoldfileのファイル名は、
~/dir1/newnameに変更される。
次のように、ディレクトリだけを指定することもできる。
$ mv name ~/dir1/ ![[←]](../icons/screen-return.gif) 
この場合、次のものと同じになる。
$ mv name ~/dir1/name ![[←]](../icons/screen-return.gif) 
また、変更先にディレクトリを指定する mv では、ファイル名は1個でなくて
も複数でもよい。
$ mv file1 file2 file3 ~/dir1 ![[←]](../icons/screen-return.gif) 
$ rmdir dirname ![[←]](../icons/screen-return.gif) 
この結果、
ディレクトリdirnameが削除される。
空でないディレクトリは、rmdir コマンドでは 「Directory not empty」 というエラー・メッセージが表示され削除できない。 この場合は、子供のディレクトリやファイル を削除してからもう一度削除する。
No such file or directory
Permission denied
No space left on device
Disc quota exceeded
C-SPC (Control + Space キー)または C-@ で設定する。
うまくいくと、ミニバッファに Mark set と表示される。
カーソルを動かしても移動しない。
次に新しいマークをセットするまで有効。
C-w)
M-w または Esc w)
indent-region)
C-y を
使う。
テキストの移動(カット&ペースト)の方法
C-SPC、または、C-@ でマーク
C-wでカット
C-yでペースト
C-SPC、または、C-@ でマーク
M-w、または、Esc wでコピー
C-yでペースト
C-SPC、または、C-@ でマーク
C-wでカット
Emacs で何か編集して、保存しないで C-x C-c で終了しようとすると、次のように聞かれる。
Save file ファイル名? (y, n, !, ., q, C-r, d or C-h) ![[]](../icons/screen-cursor.gif) 
ここで y と 1 文字打つ(リターン・キー不要)と、保存して終了してくれる。
保存したくない時には、 n と1 文字打つ。
この時は、Emacs は次のように問い合わせてくる。
Modified buffers exist; exit anyway? (yes or no) ![[]](../icons/screen-cursor.gif) 
保存しないで終了したい時は、次のように「yes![[←]](../icons/screen-return.gif)
」と打つ。
Modified buffers exist; exit anyway? (yes or no) yes![[←]](../icons/screen-return.gif) 
Emacs には、1 つのファイルを複数の Emacs で編集しないようにするために、ロックの機能がある。 複数の Emacs で編集しようとしていることを検出すると、Emacs は次のような警告を発する。
ファイル名 locked by ユーザ名@コンピュータ名 (pid 番号): (s, q, p, ?)?![[]](../icons/screen-cursor.gif) 
普通は、qと答えて、編集しない。
s では、ロックを (steal) して編集、
p では、ロックはそのままで編集できるが、良い方法ではない。
1つのファイルを編集するのは、1つのプログラムだけにする、 Emacs を実行するのは、1 つの iTerm だけにすると、このような難しい問題は生じない。
実行と逆順に終了するのが良い。iTerm、シェル、emacs の順に実行した ら、emacs、シェル、iTerm の順に終了する。
$ emacs filename.txt ![[←]](../icons/screen-return.gif) 
filename.txt が存在しないならば、
新規作成として扱われる。
C-x C-sで保存
C-x C-cで終了
C-SPC のキーをよく利用する。
しかし、macOS ではこのキーは、「入力ソースの切り替え」で使われている。
Emacs を使いやすくするために、次のことを行いなさい。
| C-SPC または C-@ | 領域(region)の先頭を決める(マーク) | 
| C-w | リージョン(領域)をカット | 
| ESC w | リージョン(領域)をコピー | 
| C-y | リージョン(領域)をペースト | 
$ cp literacy-a2.txt literacy-emacs-cut.txt ![[←]](../icons/screen-return.gif) 
$ emacs literacy-emacs-cut.txt ![[←]](../icons/screen-return.gif) 
C-SPC 、または、C-@ キーを打ち、マークを設定する。
C-w キーでカットする。
C-x C-s C-x C-c で終了する。
$ cd ~ ![[←]](../icons/screen-return.gif) $ ls
$ ls ![[←]](../icons/screen-return.gif) $ ls -a
$ ls -a ![[←]](../icons/screen-return.gif) $ ls -l
$ ls -l ![[←]](../icons/screen-return.gif) $ ls -la
$ ls -la ![[←]](../icons/screen-return.gif) $ ls -d
$ ls -d ![[←]](../icons/screen-return.gif) $ ls -dl
$ ls -dl ![[←]](../icons/screen-return.gif) $ ls -adl
$ ls -adl ![[←]](../icons/screen-return.gif) 
$ cd ディレクトリ名 ![[←]](../icons/screen-return.gif) $ pwd
$ pwd ![[←]](../icons/screen-return.gif) $ ls
$ ls ![[←]](../icons/screen-return.gif) $ ls -l
$ ls -l ![[←]](../icons/screen-return.gif) 
(1) 引数無しで cd コマンドを実行
$ cd / ![[←]](../icons/screen-return.gif) $ pwd
$ pwd ![[←]](../icons/screen-return.gif) $ ls
$ ls ![[←]](../icons/screen-return.gif) $ cd
$ cd ![[←]](../icons/screen-return.gif) $ pwd
$ pwd ![[←]](../icons/screen-return.gif) $ ls
$ ls ![[←]](../icons/screen-return.gif) 
(2) cd コマンドに、「~」を与える。
$ cd / ![[←]](../icons/screen-return.gif) $ pwd
$ pwd ![[←]](../icons/screen-return.gif) $ ls
$ ls ![[←]](../icons/screen-return.gif) $ cd ~
$ cd ~ ![[←]](../icons/screen-return.gif) $ pwd
$ pwd ![[←]](../icons/screen-return.gif) $ ls
$ ls ![[←]](../icons/screen-return.gif) 
(3) cd コマンドに、「~ログイン名」を与える。
$ cd / ![[←]](../icons/screen-return.gif) $ pwd
$ pwd ![[←]](../icons/screen-return.gif) $ ls
$ ls ![[←]](../icons/screen-return.gif) $ cd ~ログイン名
$ cd ~ログイン名 ![[←]](../icons/screen-return.gif) $ pwd
$ pwd ![[←]](../icons/screen-return.gif) $ ls
$ ls ![[←]](../icons/screen-return.gif) 
$ ls -l ![[←]](../icons/screen-return.gif) 
ディレクトリの場合、左端が「d」になっている。
(
ファイルの属性
参照
)
cd コマンドを使って、カレント・ワーキング・ディレクトリを
ホーム・ディレクトリの下のディレクトリに変更しなさ
い。以下は、Music に変更した例である。
$ cd ![[←]](../icons/screen-return.gif) $ pwd
$ pwd ![[←]](../icons/screen-return.gif) $ ls
$ ls ![[←]](../icons/screen-return.gif) $ cd Music
$ cd Music ![[←]](../icons/screen-return.gif) $ pwd
$ pwd ![[←]](../icons/screen-return.gif) $ ls
$ ls ![[←]](../icons/screen-return.gif) 
Music も含めて次のようなディレクトリについても、類似の操作を行い
なさい。
$ ls *.txt ![[←]](../icons/screen-return.gif) $ ls *txt
$ ls *txt ![[←]](../icons/screen-return.gif) $ ls *.text
$ ls *.text ![[←]](../icons/screen-return.gif) $ ls *text
$ ls *text ![[←]](../icons/screen-return.gif) $ ls *.txt *text
$ ls *.txt *text ![[←]](../icons/screen-return.gif) $ ls *.t*xt
$ ls *.t*xt ![[←]](../icons/screen-return.gif) 
$ cd ![[←]](../icons/screen-return.gif) $ ls -d D*
$ ls -d D* ![[←]](../icons/screen-return.gif) Desktop		Documents	Downloads
$ ls -ld D*
Desktop		Documents	Downloads
$ ls -ld D* ![[←]](../icons/screen-return.gif) drwx------  4 yas  prof  5120  4 21 14:35 Desktop
drwx------  6 yas  prof  1024  5 13  2016 Documents
drwx------  2 yas  prof  1024  4 13 17:31 Downloads
$
drwx------  4 yas  prof  5120  4 21 14:35 Desktop
drwx------  6 yas  prof  1024  5 13  2016 Documents
drwx------  2 yas  prof  1024  4 13 17:31 Downloads
$ ![[]](../icons/screen-cursor.gif) 
この例では、
lsの-dオプションによるディレクトリそのものの表示
の機能を利用している。これを付けなかった場合、どうなるか調べなさい。
$ cd ![[←]](../icons/screen-return.gif) $ ls D*
$ ls D* ![[←]](../icons/screen-return.gif) $ ls -l D*
$ ls -l D* ![[←]](../icons/screen-return.gif) 
同様に、大文字 M から始まるファイルやディレクトリを表示しなさい。
同様に、小文字 s で終わるファイルやディレクトリを表示しなさい。
$ ls -ld *s ![[←]](../icons/screen-return.gif) 
$ cd ![[←]](../icons/screen-return.gif) $ ls -ld D*
$ ls -ld D* ![[←]](../icons/screen-return.gif) drwx------  4 yas  prof  5120  4 21 14:35 Desktop
drwx------  6 yas  prof  1024  5 13  2016 Documents
drwx------  2 yas  prof  1024  4 13 17:31 Downloads
$
drwx------  4 yas  prof  5120  4 21 14:35 Desktop
drwx------  6 yas  prof  1024  5 13  2016 Documents
drwx------  2 yas  prof  1024  4 13 17:31 Downloads
$ ![[]](../icons/screen-cursor.gif) 
この中で、Desktop に cd したい。単純な方法では、長い名前を全て打ち込む
ことである。
$ cd ![[←]](../icons/screen-return.gif) $ pwd
$ pwd ![[←]](../icons/screen-return.gif) /home/ugrad/99/s9998765
$ cd Desktop
/home/ugrad/99/s9998765
$ cd Desktop ![[←]](../icons/screen-return.gif) $ pwd
$ pwd ![[←]](../icons/screen-return.gif) /home/ugrad/99/s9998765/Desktop
$
/home/ugrad/99/s9998765/Desktop
$ ![[]](../icons/screen-cursor.gif) 
ファイル名置換を使って、短い名前で cd できることを確認しなさい。
$ cd ![[←]](../icons/screen-return.gif) $ pwd
$ pwd ![[←]](../icons/screen-return.gif) /home/ugrad/99/s9998765
$ cd De*
/home/ugrad/99/s9998765
$ cd De* ![[←]](../icons/screen-return.gif) $ pwd
$ pwd ![[←]](../icons/screen-return.gif) /home/ugrad/99/s9998765/Desktop
$
/home/ugrad/99/s9998765/Desktop
$ ![[]](../icons/screen-cursor.gif) 
$ cd ![[←]](../icons/screen-return.gif) $ pwd
$ pwd ![[←]](../icons/screen-return.gif) /home/ugrad/99/s9998765
$ cd D*p
/home/ugrad/99/s9998765
$ cd D*p ![[←]](../icons/screen-return.gif) $ pwd
$ pwd ![[←]](../icons/screen-return.gif) /home/ugrad/99/s9998765/Desktop
$
/home/ugrad/99/s9998765/Desktop
$ ![[]](../icons/screen-cursor.gif) 
$ open /Applications/Calculator.app ![[←]](../icons/screen-return.gif) 
これを、ファイル名置換機能(*,?)を利用して、長い文字列をキーボードから打
たないで実行しなさい。
$ echo /App*/Calc* ![[←]](../icons/screen-return.gif) (1つしか表示されない確認する。複数あると問題がある。)
$ ls -d /App*/Calc*
(1つしか表示されない確認する。複数あると問題がある。)
$ ls -d /App*/Calc* ![[←]](../icons/screen-return.gif) (1つしか表示されない確認する。複数あると問題がある。)
$ open /App*/Calc*
(1つしか表示されない確認する。複数あると問題がある。)
$ open /App*/Calc* ![[←]](../icons/screen-return.gif) 
同様に、/Applications にある、他のアプリケーション・プログラムを実行し
てみなさい。
$ ls /Applications ![[←]](../icons/screen-return.gif) $ echo  「*」を含むファイル名
$ echo  「*」を含むファイル名 ![[←]](../icons/screen-return.gif) $ ls -d 「*」を含むファイル名
$ ls -d 「*」を含むファイル名 ![[←]](../icons/screen-return.gif) $ open  「*」を含むファイル名
$ open  「*」を含むファイル名 ![[←]](../icons/screen-return.gif) 
$ emacs file1.txt ![[←]](../icons/screen-return.gif) $ emacs file2.txt
$ emacs file2.txt ![[←]](../icons/screen-return.gif) $ emacs file3.txt
$ emacs file3.txt ![[←]](../icons/screen-return.gif) 
mkdir コマンド、ディレクトリを数個、作成しなさい。
$ mkdir dir1 ![[←]](../icons/screen-return.gif) $ mkdir dir2
$ mkdir dir2 ![[←]](../icons/screen-return.gif) $ mkdir dir3
$ mkdir dir3 ![[←]](../icons/screen-return.gif) 
そして、次の表にあるファイルの操作を行ってみなさい。
ls f1 f2 f3 ファイルの名前の一覧の表示 ls dir ディレクトリの内容の表示 ls カレント・ワーキング・ディレクトリの内容の表示 ls -d d1 d2 d3 ディレクトリの名前の一覧の表示 ls -a dir ディレクトリの内容の表示(.で始まる名前も表示) ls -l f1 f2 f3 ファイルの属性の表示 ls -ld d1 ls -l -d の組み合わせ pwd カレント・ワーキング・ディレクトリの表示 cd dir カレント・ワーキング・ディレクトリの変更 cd ホーム・ディレクトリへ移動 cat f1 ファイルの内容の表示 head f1 ファイルの内容の表示(最初の10行) cp f1 f2 ファイルのコピー cp f1 f2 f3 dir ファイルを指定されたディレクトリへコピー cp dir/f1 . ファイルをカレント・ワーキング・ディレクトリへコピー rm f1 f2 f3 ファイルの削除 mv old new ファイルの名前を変える mv f1 f2 f3 dir ファイルの名前を変える(dir以下への移動) mkdir dir ディレクトリの作成 mkdir -p d1/d2/d3 ディレクトリの作成(親も自動的に作成) rmdir dir ディレクトリの削除(空のディレクトリの時) f1, f2, f3 はファイル名、dir, d1, d2, ... は、ディレクトリ名
tree コマンドに -N オプションをつけると、ファイル名に漢字を含むものも表 示できる。
$ tree -N ディレクトリ名 ![[←]](../icons/screen-return.gif) 
注意: 表示が止まらなくなった時、強制終了したい時には、
Control キー + c キー も使える。
lv による表示。後ろに「| lv」をつける。
終了するには、q キーを打つ。
$ tree -N ディレクトリ名 | lv ![[←]](../icons/screen-return.gif) <表示省略>
<空白キーで次のページを表示>
:q
$
<表示省略>
<空白キーで次のページを表示>
:q
$ ![[]](../icons/screen-cursor.gif) 
iTerm にペーストする時に「?」が表示されるならば、次のように すれば (UTF-8ではなく) ASCII 文字を使うようになる。
$ LANG=C tree -N ディレクトリ名 ![[←]](../icons/screen-return.gif) 
tree コマンドの次のオプションの意味を ls と比較しなさい。
 
cp ~yas/public_html/htdocs/coins/literacy-2018/2018-04-24/literacy-a4.txt .注意: このコピーは、1度だけ行うこと。2度以上行うと、それまでに行った編 集内容は失われる。
$ ls ![[←]](../icons/screen-return.gif) (literacy-a4.txtが存在することを確認する)
$ emacs literacy-a4.txt
(literacy-a4.txtが存在することを確認する)
$ emacs literacy-a4.txt ![[←]](../icons/screen-return.gif) 
作成したファイルを、 レポート提出ページから提出しなさい。