便利なCUIコマンド集

ファイル・ディレクトリ操作

ls (list)

ディレクトリの内容を一覧表示します。

ls -l # 詳細表示
ls -a # 隠しファイルも表示

cd (change directory)

カレントディレクトリを変更します。

cd /path/to/directory # 指定したディレクトリへ移動
cd .. # 親ディレクトリへ移動
cd ~ # ホームディレクトリへ移動

pwd (print working directory)

現在の作業ディレクトリのパスを表示します。

pwd

mkdir (make directory)

新しいディレクトリを作成します。

mkdir new_directory # 新しいディレクトリを作成
mkdir -p parent/child # 階層的にディレクトリを作成

rm (remove)

ファイルやディレクトリを削除します。

rm file.txt # ファイルを削除
rm -r directory # ディレクトリを再帰的に削除
rm -rf directory # 確認なしで強制的に削除 (注意!)

cp (copy)

ファイルやディレクトリをコピーします。

cp file.txt /path/to/destination # ファイルをコピー
cp -r directory /path/to/destination # ディレクトリを再帰的にコピー

mv (move)

ファイルやディレクトリを移動または名前変更します。

mv file.txt /path/to/destination # ファイルを移動
mv old_name.txt new_name.txt # ファイル名を変更

ファイル内容表示・検索

cat (concatenate)

ファイルの内容を表示します。

cat file.txt

grep (global regular expression print)

ファイルの中から指定したパターンに一致する行を検索します。

grep "keyword" file.txt # キーワードを検索
grep -r "keyword" . # カレントディレクトリ以下を再帰的に検索

find

ファイルやディレクトリを検索します。

find . -name "*.txt" # カレントディレクトリ以下で.txtファイルを検索
find /home -type d -name "my_dir" # /home以下でmy_dirというディレクトリを検索

システム情報・プロセス管理

ssh (secure shell)

リモートサーバーに安全に接続します。

ssh user@hostname

top / htop

システムのプロセス状況をリアルタイムで表示します。

top # 基本的な表示
htop # より高機能でインタラクティブな表示 (要インストール)

df (disk free)

ディスクの空き容量を表示します。

df -h # 人間が読みやすい形式で表示

du (disk usage)

ファイルやディレクトリのディスク使用量を表示します。

du -sh /path/to/directory # 指定したディレクトリの合計サイズを表示

ps (process status)

現在実行中のプロセスを表示します。

ps aux # すべてのユーザーのプロセスを詳細表示
ps -ef | grep nginx # nginxプロセスを検索

kill

プロセスを終了させます。

kill PID # 指定したPIDのプロセスを終了
kill -9 PID # 強制終了 (注意!)

パーミッション・所有者変更

chmod (change mode)

ファイルやディレクトリのパーミッション(アクセス権)を変更します。

chmod 755 script.sh # 実行権限を付与
chmod +x script.sh # 実行権限を追加

chown (change owner)

ファイルやディレクトリの所有者やグループを変更します。

chown user:group file.txt # 所有者とグループを変更

ネットワーク操作

wget / curl

Webからファイルをダウンロードしたり、HTTPリクエストを送信したりします。

wget https://example.com/file.zip # ファイルをダウンロード
curl -O https://example.com/file.zip # ファイルをダウンロード
curl -X POST -d "data" https://example.com/api # POSTリクエストを送信