Learning the shell — Lesson 3: Looking around

Shuma Mizuno
Sep 6, 2018 · 4 min read

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

Looking Around

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

・ls (list files and directories)
・less (view text files)
・file (classify a file’s contents)

Command syntax

大抵のコマンドは下記のパターンで操作する。

command -options arguments

commnad
どのコマンドを使うかを入力する。

-options
コマンドと合わせて新たな振る舞いを追加する。

arguments
コマンドに処理させる対象(ファイルやディレクトリ)を指定する。

ls

コンテンツをリスト形式で表示するのに使う。
もっとも一般的に使用されているLinuxコマンド。

リスト表示

$ ls

リスト表示 + ディレクトリを指定

$ ls /bin

-l オプション
データサイズや修正された日付などが付与された
ロングフォーマットで表示

$ ls -l

-la オプション
リストをロングフォーマットで全て表示

$ ls -la

その他にも色々ある
ls command options
https://www.rapidtables.com/code/linux/ls.html

A Closer Look At Long Format

File Name
ファイルかディレクトリの名前

Modification Time
最後に編集した日時

Size
ファイルの大きさ

Group
ファイルを所有するグループ名

Owner
ファイルを所有するユーザー名

File Permissions
ファイルのパーミッション

パーミッションの読み方

10文字の情報で構成される。

1文字目は、ファイル形式を示す。
- : 通常ファイル
d: ディレクトリ

それ以降は3 文字ずつの 3 つのグループから構成される。
2文字目〜4文字目
所有者に対する権限

5文字目〜7文字目
所有者のグループに対する権限

8文字目〜10文字目
その他の全ユーザのアクセス権に対する権限

Linuxの権限確認と変更(超初心者向け)
https://qiita.com/shisama/items/5f4c4fa768642aad9e06

Less

テキストファイルの内容を閲覧する際に使う。
多くのファイルの設定を変更する際に便利。

$ less text_file

What is “text”?

コンピューターは2進数のみ理解できる。
人が入力したデータは最終的に2進数に変換される。

その際に使用するencoding schemeで
広く利用されているのがASCII(アスキー)

ASCIIとは
文字コードのひとつ。1963年にアメリカ規格協会(ANSI)が制定。アルファベット・数字・記号などを7ビットの情報量(最大128文字)で表現する。

ASCII (American Standard Code for Information Interchange)
https://whatis.techtarget.com/definition/ASCII-American-Standard-Code-for-Information-Interchange

Controlling less

lessで表示している際のキー操作

1画面戻る
b

1画面進む
f

終了
q

その他にも色々ある
【 less 】コマンド(基本編)――メッセージやテキストファイルを1画面ずつ表示する
http://www.atmarkit.co.jp/ait/articles/1702/09/news031.html

file

ファイルのタイプを参照する際に使う。

$ file name_of_file

Linux and Unix file command tutorial with examples
https://shapeshed.com/unix-file/#how-to-determine-the-file-type-of-a-file

質問事項

特になし

所感

1通りいろいろ試してみたけど
とりあえず迷ったら — help使えばなんとかなりそう。

メモ

プログラマのための文字コード技術入門 (WEB+DB PRESS plus) (WEB+DB PRESS plusシリーズ)
https://goo.gl/mcUfLr

    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