Learning the shell — Lesson 2: Navigation

Shuma Mizuno
Sep 5, 2018 · 4 min read

学習日: 180906
所要時間: 3時間

Navigation

この記事では下記の3つのコマンドについて学ぶ。

・pwd(pring working directory)
・cd(change directory)
・ls(list files and directories)

File System Organization

Linux システムは階層的ディレクトリ構造をしている。

最初のディレクトリをrootディレクトリと呼ぶ。

レガシーシステムとUnix-likeシステムの重要な違いは
ドライブレターを採用していないこと。

ドライブレターとは
ハードディスクやCD-ROMなどの記憶装置を識別するために付与される英字1文字のことである。

フロッピーディスクはA、B
PCのハードドライブにはCが割り当てられている。

ただし、PCのバージョンによって自由にドライブレターを変更することが可能。

Drive letter
https://www.computerhope.com/jargon/d/drivelet.htm

レガシーシステムはツリーを予め複数に分割して表示する。
Unix-likeシステムは常にシングルツリーで表示する。

pwd

ワーキングディレクトリまでのパスを表示する。

[me@linuxbox me]$ pwd
/home/me

現在いるディレクトリをワーキングディレクトリと呼ぶ。

CUIはGUIのように視覚的な情報を提供してくれるわけではない。

そのためにワーキングディレクトリまでのパスや親ディレクトリを確認するために使用する。

ls

ワーキングディレクトリ内のファイルをリストにして表示する。

[me@linuxbox me]$ ls
Desktop Xrootenv.0 linuxcmd
GNUstep bin nedit.rpm
GUILG00.GZ hitni123.jpg nsmail

cd

ワーキングディレクトリを移動する際に使用する。

[me@linuxbox me]$ cd /usr/bin

cd + pathname の形で好きなディレクトリへ移動する。

pathnameの指定は以下の2通り
・絶対パス
rootを基準にしたパス

・相対パス
ワーキングディレクトリを基準にしたパス

2通りあるが状況に合わせてタイプの少ない方を選べばいい。

具体的な例

カレントディレクトリが /usr/bin で親ディレクトリの /usr に移動したい場合。

絶対パス

[me@linuxbox bin]$ cd /usr

相対パス

[me@linuxbox me]$ cd..

cdの後のドットについて
“.” ワーキングディレクトリを参照
“..” 親ディレクトリを参照

A Few Shortcuts

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

指定したユーザーのhome directoryに移動
cd ~user_name.

Important facts about file names

  1. “.”から始まるファイルは表示されない。表示したい場合は ls -a で表示できる。

2. Linuxでは、大文字と小文字は区別され “File1” and “file1” は別のファイルと認識される。

3. Linuxではレガシーシステムにおける”file extension”の概念は存在しない。

4.ファイル名にスペースは使わないように。アンスコで対応する。

質問事項

特になし

所感

圧倒的なWindowsディスを感じた。

文中に気になることがあると脱線しすぎて時間かかるので気をつけたい。
今回だとドライブレターやWindows、Linuxの違いあたり。

メモ

Characters to Avoid in Directories and Filenames
https://www.mtu.edu/umc/services/digital/writing/characters-avoid/

Linux / UNIX: Rules For Naming File And Directory Names
https://www.cyberciti.biz/faq/linuxunix-rules-for-naming-file-and-directory-names/

    Shuma Mizuno

    Written by

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade