0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ファイル編集(viコマンドとlsコマンドのオプション)とファイルシステムの確認、管理

Last updated at Posted at 2022-07-04

カーソル動かし方

コマンド名 説明
i 文字の挿入
o カーソルがある下の行にテキストを挿入
h 左に移動
l 右に移動
k 上に移動
j 下に移動
I 行の先頭にテキストを挿入
H 画面の先頭行に移動
M 画面の中央行に移動
L 画面の最後行に移動
O カーソルがある上の行にテキストを挿入
w ワード単位で移動
b ワード単位で左に移動
e 現ワードの最後の文字に移動
retun(エンタージー) 下の行の先頭文字 (空白ではない) に移動
Back Space キー 左に移動
Space Bar キー 右に移動
yy コピー(yyの後に数字を入れると数字分の行がコピーされる)  
p ペースト
dd 削除
dG カーソルがある行からファイルの最終行までを削除
d1G ファイルの先頭行からカーソルがある行までを削除
:2,6d 2行目から6行目までを削除
xp カーソルと右の文字入れ替え
大文字または小文字に変える
{} 1ブロック上下に
u 前回の変更などのコマンドを取り消す
x カーソル文字削除
gg 1行目に移動
G ファイルの最終行にジャンプ
1G ファイルの先頭行にジャンプ
6G 6行目にジャンプ

escキーを押した後

コマンド名 説明
:w 上書き
:wq 上書き保存して終了
:q 終了
:sp 水平方向に分割
:vsp 垂直方向に分割
:set number 行番号を表示
:!コマンド コマンドを実行
:!%:p 編集中のファイルの実行
:vertical diffsplit ファイル名 2つのテキストファイルの差分がわかる

!をつけると編集が終了します。
:spと:vspを使った時はCtrl + wで切り替えができます。

lsコマンドのオプション

lsコマンドはlinuxでよく使いますが、オプションがいろいろあるので紹介していきます。

ls

ファイルやディレクトリの情報を表示するコマンドです。

Animal % ls
copyto		gorillas	monkey.cpio	xaa
dog		monkey		practice.txt

-a

全てを表示するオプションです。
ファイル名の先頭にピリオドがあるファイルも表示し、先頭にピリオドがあるファイルは
普段簡単には編集されたくない設定ファイルです。

taro~ % ls -a
.
..
.bash_history
.bash_profile
.bundle
.cache
.composer
.config
.docker
.gem
.git
.gitconfig
#省略

.bash_historyはこれまでのコマンドの履歴を保存しておくファイルです。
-Aでも使えるみたいです。

-l

ファイルの詳細を表示します。

Animal % ls -l
total 32
drwxr-xr-x  6 Animal  staff   192  7  4 16:55 copyto
-rw-r--r--  1 Animal  staff  1024  7  4 16:28 dog
drwxr-xr-x  2 Animal  staff    64  7  4 16:35 gorillas
-rw-r--r--  1 Animal  staff    28  7  1 15:02 monkey
-rw-r--r--  1 Animal  staff  2048  7  4 16:33 monkey.cpio
drwxr-xr-x  4 Animal  staff   128  6 28 17:54 practice.txt
-rw-r--r--  1 Animal  staff    49  6 30 13:26 xaa

ls -laでよく併用されます。
1番左の説明でdの部分はディレクトリを表しています。
rwxなどはパーミッションを表しています。rは読み込みwは書き込み権限
xは実行権限です。

-1

リストを縦に並べる時に使います

Animal % ls -1
copyto
dog
gorillas
monkey
monkey.cpio
practice.txt
xaa

-r

リストを逆順で表示します。

Animal % ls -l
total 32
drwxr-xr-x  6 Animal  staff   192  7  4 16:55 copyto
-rw-r--r--  1 Animal  staff  1024  7  4 16:28 dog
drwxr-xr-x  2 Animal  staff    64  7  4 16:35 gorillas
-rw-r--r--  1 Animal  staff    28  7  1 15:02 monkey
-rw-r--r--  1 Animal  staff  2048  7  4 16:33 monkey.cpio
drwxr-xr-x  4 Animal  staff   128  6 28 17:54 practice.txt
-rw-r--r--  1 Animal  staff    49  6 30 13:26 xaa
 Animal % ls -lr
total 32
-rw-r--r--  1 Animal  staff    49  6 30 13:26 xaa
drwxr-xr-x  4 Animal  staff   128  6 28 17:54 practice.txt
-rw-r--r--  1 Animal  staff  2048  7  4 16:33 monkey.cpio
-rw-r--r--  1 Animal  staff    28  7  1 15:02 monkey
drwxr-xr-x  2 Animal  staff    64  7  4 16:35 gorillas
-rw-r--r--  1 Animal  staff  1024  7  4 16:28 dog
drwxr-xr-x  6 Animal  staff   192  7  4 16:55 copyto

-t

更新時間順に並べます。

Animal % ls -tl
total 32
drwxr-xr-x  6 Animal  staff   192  7  4 16:55 copyto
drwxr-xr-x  2 Animal  staff    64  7  4 16:35 gorillas
-rw-r--r--  1 Animal  staff  2048  7  4 16:33 monkey.cpio
-rw-r--r--  1 Animal  staff  1024  7  4 16:28 dog
-rw-r--r--  1 Animal  staff    28  7  1 15:02 monkey
-rw-r--r--  1 Animal  staff    49  6 30 13:26 xaa
drwxr-xr-x  4 Animal  staff   128  6 28 17:54 practice.txt

-S

*どのファイルでどのくらいの容量を使っているかを確認できます。

Animal % ls -lS
total 32
-rw-r--r--  1 Animal   staff  2048  7  4 16:33 monkey.cpio
-rw-r--r--  1 Animal   staff  1024  7  4 16:28 dog
drwxr-xr-x  6 Animal   staff   192  7  4 16:55 copyto
drwxr-xr-x  4 Animal   staff   128  6 28 17:54 practice.txt
drwxr-xr-x  2 Animal   staff    64  7  4 16:35 gorillas
-rw-r--r--  1 Animal   staff    49  6 30 13:26 xaa
-rw-r--r--  1 Animal   staff    28  7  1 15:02 monkey

-X

lsコマンドでは、拡張子の順に並び替えることもできます。

image.png

  引用  https://eng-entrance.com/linux_command_ls

-R

サブディレクトリの中も一度に並べて見たい時に使います。

 Animal % ls -R
copyto		gorillas	monkey.cpio	xaa
dog		monkey		practice.txt

./copyto:
dog		monkey		practice.txt	xaa

./copyto/practice.txt:

./gorillas:

./practice.txt:
practice.txt

-m

ファイル名をカンマで区切って表示します。

Animal % ls -m
copyto, dog, gorillas, monkey, monkey.cpio, practice.txt, xaa

-h

ファイルサイズの単位を読みやすい形式で表示します。

Animal % ls -lh
total 32
drwxr-xr-x  6 Animal  staff   192B  7  4 16:55 copyto
-rw-r--r--  1 Animal  staff   1.0K  7  4 16:28 dog
drwxr-xr-x  2 Animal  staff    64B  7  4 16:35 gorillas
-rw-r--r--  1 Animal  staff    28B  7  1 15:02 monkey
-rw-r--r--  1 Animal  staff   2.0K  7  4 16:33 monkey.cpio
drwxr-xr-x  4 Animal staff   128B  6 28 17:54 practice.txt
-rw-r--r--  1 Animal  staff    49B  6 30 13:26 xaa

-k

「-h」と似たオプションで、キロバイトで表示します。

Animal % ls -lk
total 16
drwxr-xr-x  6 Animal  staff   192  7  4 16:55 copyto
-rw-r--r--  1 Animal  staff  1024  7  4 16:28 dog
drwxr-xr-x  2 Animal  staff    64  7  4 16:35 gorillas
-rw-r--r--  1 Animal  staff    28  7  1 15:02 monkey
-rw-r--r--  1 Animal  staff  2048  7  4 16:33 monkey.cpio
drwxr-xr-x  4 Animal  staff   128  6 28 17:54 practice.txt
-rw-r--r--  1 Animal  staff    49  6 30 13:26 xaa

-i

ファイル名の左にi-node番号を表示します。

Animal % ls -li
total 32
35674008 drwxr-xr-x  6 Animal staff   192  7  4 16:55 copyto
35673710 -rw-r--r--  1 Animal  staff  1024  7  4 16:28 dog
35673854 drwxr-xr-x  2 Animal  staff    64  7  4 16:35 gorillas
35419599 -rw-r--r--  1 Animal  staff    28  7  1 15:02 monkey
35673796 -rw-r--r--  1 Animal  staff  2048  7  4 16:33 monkey.cpio
35423181 drwxr-xr-x  4 Animal  staff   128  6 28 17:54 practice.txt
35518830 -rw-r--r--  1 Animal  staff    49  6 30 13:26 xaa

左の番号がiノード番号です。

-F

ディレクトリ名の後に「/」を、実行可能なファイル名の後に「」をそれぞれ付加*します。

image.png

  引用  https://eng-entrance.com/linux_command_ls

full time

イムスタンプの詳細を表示できます。

image.png

  引用  https://eng-entrance.com/linux_command_ls

ファイルシステム

Linuxのディスクの使用について

⚫︎ディスクにパーティション作成します。
・ディスクを分割
・ /dev/sda1,sda2,sda3 など

⚫︎パーティションにファイルシステムを作成

⚫︎ファイルシステムをディレクトリマウントする

dfコマンド

ディスクの空き容量を確認するコマンドです。

$ df [オプション] ファイル名
オプション 説明
-i iノードの使用状況
-h M(メガバイト)、Gバイト(ギガバイト)
-T ファイルシステムタイプ表示

まずdfだけでやってみます。

Animal % df
Filesystem     512-blocks      Used Available Capacity iused      ifree %iused  Mounted on
/dev/disk1s1s1  489620264  29929960 148969304    17%  553605 2447547715    0%   /
devfs                 383       383         0   100%     665          0  100%   /dev
/dev/disk1s5    489620264  10485944 148969304     7%       5 2448101315    0%   /System/Volumes/VM
/dev/disk1s3    489620264   1162192 148969304     1%    3282 2448098038    0%   /System/Volumes/Preboot
/dev/disk1s6    489620264     10728 148969304     1%      18 2448101302    0%   /System/Volumes/Update
/dev/disk1s2    489620264 297574112 148969304    67% 2881056 2445220264    0%   /System/Volumes/Data
map auto_home           0         0         0   100%       0          0  100%   /System/Volumes/Data/home

-iを使ってみます。

Animal % df -i
Filesystem     512-blocks      Used Available Capacity iused      ifree %iused  Mounted on
/dev/disk1s1s1  489620264  29929960 148979136    17%  553605 2447547715    0%   /
devfs                 383       383         0   100%     665          0  100%   /dev
/dev/disk1s5    489620264  10485944 148979136     7%       5 2448101315    0%   /System/Volumes/VM
/dev/disk1s3    489620264   1162192 148979136     1%    3282 2448098038    0%   /System/Volumes/Preboot
/dev/disk1s6    489620264     10728 148979136     1%      18 2448101302    0%   /System/Volumes/Update
/dev/disk1s2    489620264 297564280 148979136    67% 2881055 2445220265    0%   /System/Volumes/Data
map auto_home           0         0         0   100%       0          0  100%   /System/Volumes/Data/home

-hを使ってみます。

Animal % df -h
Filesystem       Size   Used  Avail Capacity iused      ifree %iused  Mounted on
/dev/disk1s1s1  233Gi   14Gi   71Gi    17%  553605 2447547715    0%   /
devfs           192Ki  192Ki    0Bi   100%     665          0  100%   /dev
/dev/disk1s5    233Gi  5.0Gi   71Gi     7%       5 2448101315    0%   /System/Volumes/VM
/dev/disk1s3    233Gi  567Mi   71Gi     1%    3282 2448098038    0%   /System/Volumes/Preboot
/dev/disk1s6    233Gi  5.2Mi   71Gi     1%      18 2448101302    0%   /System/Volumes/Update
/dev/disk1s2    233Gi  142Gi   71Gi    67% 2881056 2445220264    0%   /System/Volumes/Data
map auto_home     0Bi    0Bi    0Bi   100%       0          0  100%   /System/Volumes/Data/home

-Tで使います。

Animal % df -t
Filesystem     512-blocks      Used Available Capacity iused      ifree %iused  Mounted on
/dev/disk1s1s1  489620264  29929960 148972136    17%  553605 2447547715    0%   /
devfs                 383       383         0   100%     665          0  100%   /dev
/dev/disk1s5    489620264  10485944 148972136     7%       5 2448101315    0%   /System/Volumes/VM
/dev/disk1s3    489620264   1162192 148972136     1%    3282 2448098038    0%   /System/Volumes/Preboot
/dev/disk1s6    489620264     10728 148972136     1%      18 2448101302    0%   /System/Volumes/Update
/dev/disk1s2    489620264 297571280 148972136    67% 2881084 2445220236    0%   /System/Volumes/Data
map auto_home           0         0         0   100%       0          0  100%   /System/Volumes/Data/home

⚫︎注意
-Tはwindowsで、-tはMacで動きました。

組み合わせて使ってみます。

Animal % df -it
Filesystem     512-blocks      Used Available Capacity iused      ifree %iused  Mounted on
/dev/disk1s1s1  489620264  29929960 148989432    17%  553605 2447547715    0%   /
devfs                 383       383         0   100%     665          0  100%   /dev
/dev/disk1s5    489620264  10485944 148989432     7%       5 2448101315    0%   /System/Volumes/VM
/dev/disk1s3    489620264   1162192 148989432     1%    3282 2448098038    0%   /System/Volumes/Preboot
/dev/disk1s6    489620264     10728 148989432     1%      18 2448101302    0%   /System/Volumes/Update
/dev/disk1s2    489620264 297553984 148989432    67% 2881104 2445220216    0%   /System/Volumes/Data
map auto_home           0         0         0   100%       0          0  100%   /System/Volumes/Data/home

duコマンド

ディスクの使用状況を確認します。

$ du [オプション][ディレクトリ・ファイル名]
オプション 説明
-a ディレクトリと全てのファイル情報表示
-s 合計のみ表示
-h M(メガバイト)、G(ギガバイト)

-aを使っていきます。

Animal % du -a
8	./copyto/dog
0	./copyto/practice.txt
8	./copyto/xaa
8	./copyto/monkey
24	./copyto
8	./dog
8	./practice.txt/practice.txt
24	./practice.txt/.practice.txt.swp
32	./practice.txt
0	./gorillas
8	./xaa
8	./monkey
8	./listfiles.sh
8	./monkey.cpio
96	.

-sを使っていきます。

Animal % du -s
96	.

-hを使っていきます。

Animal % du -h
  0B	./copyto/practice.txt
 12K	./copyto
 16K	./practice.txt
  0B	./gorillas
 48K	.
Animal % du -ah
4.0K	./copyto/dog
  0B	./copyto/practice.txt
4.0K	./copyto/xaa
4.0K	./copyto/monkey
 12K	./copyto
4.0K	./dog
4.0K	./practice.txt/practice.txt
 12K	./practice.txt/.practice.txt.swp
 16K	./practice.txt
  0B	./gorillas
4.0K	./xaa
4.0K	./monkey
4.0K	./listfiles.sh
4.0K	./monkey.cpio
 48K	.

⚫︎注意
-asの組み合わせは動かないです。

fsckコマンド

ファイルシステムのチェックをするコマンドです。後者hext系のみです。

$ fsck [オプション] デバイスファイル
オプション 説明
-t ファイルシステム(ext2,ex3,ex4)
-c ファイルシステム作成時に不良ブロック調査
-b バックアップスーパーブロック指定して復旧
-n コマンド実行確認

dumpe2fsコマンド

$ dumpe2fs [オプション] デバイスファイル
オプション 説明
-b 不良ブロック表示
-h スーパーブロック情報だけ表示

debugfsコマンド

ファイルシステムのメンテナンスを実行します。

$ dumpe2fs [オプション] デバイスファイル
オプション 説明
-b ブロックサイズの適用
-c 読み取り専用で開く
-Rコマンド 対話式ではなく、指定したコマンド実行
-n 読み取り

root権限にしたりして上のコマンドを実行すると

debugfs:

が出てくるのでこの後にコマンドを入力していきます。

tunes2fsコマンド

$ tune2fs [オプション] デバイスファイル
オプション 説明
-c回数 ファイルシステムチェック実行のマウント回数
-i,d,m,w ファイルシステムチェック閲覧d,m,w
-j ext3ジャーナル(変更履歴)を追加
-I スーパーブロック情報表示
Lボリューム名 ファイルシステムにボリューム名

XFS管理ツール

スクリーンショット 2022-07-06 17.21.26.png

引用 https://qiita.com/jackie0922youhei/items/1c0b3c5833cc4ebeb3

ディスククオータ

クォータ制御

各ユーザーのディスク容量上限を設定し、システムが停止を予防します。
ハードリミットとソフトリミットというものがあります。

クォータの設定

クォータモードでマウントし、/etc/fstabにて、usrquotaまたはgrpquotaで指定してマウントします。

quotacheckコマンド

クォータの初期化コマンドです。

オプション 説明
-b バックファイル作成
-c 新規作成
-v 詳細表示

edquota

$ edquota [オプション] デバイスファイル
オプション 説明
-u ユーザー名
-g グループ名
-t ソフトリミットの猶予期間

quota[オプション] ファイルシステムとquotaoff[オプション] ファイルシステム

オプション 説明
-a 全ファイルシステムの設定を有効化
-u ユーザクォータ有効化
-g グループクォータ有効化
-v メッセージ詳細表示

repquota(report、quota)コマンド

クォータの確認コマンドです。

$ repquota [-a] ファイル システム

-aオプション  全ファイルシステム対象

quota {-u,-g} ユーザ・グループのクォータ表示設定

FHS

この記事に細かいところが載ってました。

ファイル検索

locateコマンド

データベースから検索するコマンドです。

⚫︎updatedb

・PRUNEFS
・PRUNEPATHS

whereisコマンド

指定コマンドに関連するパスを表示するときに使うコマンドです。

$ whereis [option] ファイル名
オプション 説明
-b バイナリのみ
-m manページのみ
-s ソースのみ
Animal % whereis cd
/usr/bin/cd
Animal % whereis ls
/bin/ls
Animal % whereis mkdir
/bin/mkdir

whichコマンド

指定されたコマンドのパスを表示するコマンドです。

Animal % which ls
/bin/ls
Animal % which cd
cd: shell built-in command
Animal % which touch
/usr/bin/touch
Animal % which rm   
/bin/rm
Animal % which man
/usr/bin/man
Animal % which diff
/usr/bin/diff

type

コマンドのパスや種類を表示し、テキストファイルの中身を表示するときに使うコマンドです。

% type ls
ls is /bin/ls
 ~ % type cd
cd is a shell builtin
~ % type mkdir
mkdir is /bin/mkdir
 ~ % type touch
touch is /usr/bin/touch
 ~ % type rm   
rm is /bin/rm
~ % type diff
diff is /usr/bin/diff

資料

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?