cd
自分の場所を移動するコマンド
pwd
自分が今どの場所にいるのかを確認するコマンド
(例)
(base) yugo@YugonoMacBook-Air ~ % pwd
/Users/yugo
ls
場所に何(ディレクトリ、ファイルなど)があるのかを表示するためのコマンド
(base) yugo@YugonoMacBook-Air html-basic % ls
attribute.html dog.jpg heading.html remove-error-finish.html
description-list.html exericise-list.html list.html remove-error-start.html
(base) yugo@YugonoMacBook-Air html-basic % ls -l
total 168
-rw-r--r--@ 1 yugo staff 358 7 26 22:26 attribute.html
-rw-r--r--@ 1 yugo staff 777 7 21 05:09 description-list.html
-rw-r--r--@ 1 yugo staff 53650 7 21 05:19 dog.jpg
-rw-r--r-- 1 yugo staff 307 7 26 22:50 exericise-list.html
-rw-r--r--@ 1 yugo staff 503 7 21 05:14 heading.html
-rw-r--r--@ 1 yugo staff 355 7 20 05:13 list.html
-rw-r--r-- 1 yugo staff 280 7 19 05:13 remove-error-finish.html
-rw-r--r--@ 1 yugo staff 281 7 19 05:01 remove-error-start.html
(base) yugo@YugonoMacBook-Air html-basic % ls -a
. .DS_Store description-list.html exericise-list.html list.html remove-error-start.html
.. attribute.html dog.jpg heading.html remove-error-finish.html
(base) yugo@YugonoMacBook-Air html-basic % ls -F
attribute.html dog.jpg heading.html remove-error-finish.html
description-list.html exericise-list.html list.html remove-error-start.html
⚪︎使いそうなオプション
オプション | 説明 |
---|---|
-l | ファイルの設定や更新日時などの詳細情報が見たい時に使用 |
-a | 隠しファイル(普段は表示されないファイル)を含めたファイルを全て表示 |
mkdir
ディレクトリの作成をするコマンド
(フォルダみたいなもの)
⚪︎使いそうなオプション
オプション | 説明 |
---|---|
-p | 存在しない親ディレクトリもまとめて作成できる |
(base) yugo@YugonoMacBook-Air html-basic % mkdir -p test/result
#testが存在してなくてもtestを作成してtestの中にresultのディレクトリを一気に作成できる
rmdir
ディレクトリの削除をするコマンド
注意
削除できるのは中身が空のディレクトリのみ
less
ファイルの中身をスクロールできるように表示する
・操作方法
キー | 説明 |
---|---|
スペース、f | 画面下(表示されている分を下に移動) |
b | 画面上(表示されている分を上に移動) |
j | 一行下 |
k | 一行上 |
q | コマンド終了 |
・検索
キー | 説明 |
---|---|
/<文字列> | 下方向検索 |
?<文字列> | 上方向検索 |
n | 次の検索結果 |
N | 前の検索結果 |
touch
現在いるディレクトリに新規ファイルを作成する
→上書きはされない
tail
最終行から数行を表示する
・よく使いそうなオプション
オプション | 説明 |
---|---|
-n | 最後の行から表示する行数を指定 |
(例)最終の5行を表示
(base) yugo@YugonoMacBook-Air html-basic % tail -n 5 heading.html
<h4>見出し レベル4</h4>
<h5>見出し レベル5</h5>
<h6>見出し レベル6</h6>
</body>
</html>
rm
ファイル・ディレクトリを削除するコマンド
・オプション
オプション | 説明 |
---|---|
-r | ディレクトリの中身のファイル、ディレクトリをまとめて削除する |
-f | ファイル削除前に警告を表示しない |
-i | ファイルの削除前に確認する |
注意
1.ディレクトリを削除する場合は-rオプションを使用する
2.削除したものは元に戻せないのでよく確認してから実行する
mv
ファイルの移動・ファイル名の変更するコマンド
・書き方
mv <移動元・変更前のファイル名> <移動先・変更後のファイル名>
・オプション
オプション | 説明 |
---|---|
-i | 上書きする前に確認する |
cp
ディレクトリ・ファイルをコピーするコマンド
・書き方
cp <コピー元> <コピー先>
・オプション
オプション | 説明 |
---|---|
-i | 上書きする前に確認する |
-r | ディレクトリをコピーする |
ln
リンクを張るコマンド
・書き方
ln <リンク元> <リンク先>
・オプション
オプション | 説明 |
---|---|
-s | シンボリックリンクを張る |
find
ファイルを検索するコマンド
・書き方
find <検索開始ディレクトリ> <検索条件> <アクション>
(例)practice.txtファイルを探したい
(base) yugo@YugonoMacBook-Air ~ % find . -name practice.txt -print
./Desktop/web開発入門/html/linux/public/practice.txt
(例)html拡張子のものを探したい
find . -name '*.html' -print
注意
ワイルドカードを使用する場合は''で囲う
・よく使う検索条件
オプション | 説明 |
---|---|
-name | ファイル名を指定。(大文字小文字を区別する) |
-iname | ファイル名を指定。(大文字小文字を区別しない) |
-type | ファイルの種類で検索 |
chmod
ファイルやディレクトリのパーミッションを設定するコマンド
・詳細
記号 | 説明 |
---|---|
u | 所有者の権限 |
g | グループの権限 |
o | その他のユーザの権限 |
a | 前ユーザの権限 |
+ | 権限を追加 |
- | 権限を削除 |
= | 記述した権限にする |
・書き方
chmod u+r file
chmod(数値指定の場合)
・詳細
パーミッション | 数値 |
---|---|
r(読み取り) | 4 |
w(書き込み) | 2 |
x(実行) | 1 |
・ 書き方
chmod 755 file
chown
ファイル・ディレクトリの ユーザーやグループの所有権 を変更するためのコマンド
(例)ユーザー所有権を変更する
chown root test.txt
(例)グループの所有権も変更する場合
chown root:root test.txt
ループの所有権も変更する場合には引数にセミコロン「:」をはさんで「ユーザー:グループ」
ps
現在PCで動いているプロセスについて確認するコマンド
・オプション
オプション | 説明 |
---|---|
aux | 全ユーザーのプロセスを、詳細情報と合わせて表示 |
kill
ジョブやプロセスを終了させるコマンド
・書き方
kill [オプション] %<ジョブID>
kill [オプション] <プロセスID>
※どうしてもkillしても終了しない時
kill -SIGKILL 4965
-SIGKILL:強制終了のシグナル