なぜLinuxコマンドを学ぶべきか
サーバーの9割はLinuxで動いています。クラウド・コンテナ・CI/CDすべての基盤となるLinuxのコマンドラインスキルは、エンジニアの根幹です。
ファイル・ディレクトリ操作
ls -la # 詳細一覧(隠しファイル含む)
cd /var/log # ディレクトリ移動
pwd # 現在地確認
mkdir -p a/b/c # 階層ごと作成
rm -rf dir/ # ディレクトリ削除(要注意)
cp -r src/ dst/ # 再帰コピー
mv old new # 移動・リネーム
find / -name "*.log" -mtime +7 # 7日以上前のログ検索
テキスト処理
cat file.txt # ファイル表示
head -20 file.txt # 先頭20行
tail -f /var/log/syslog # ログ追跡
grep -r "ERROR" /var/log/ # 再帰検索
grep -v "DEBUG" app.log # マッチ除外
awk '{print $1, $3}' file # 列抽出
sed 's/old/new/g' file # 文字列置換
wc -l file.txt # 行数カウント
sort | uniq -c | sort -rn # 頻度集計
プロセス・リソース管理
| コマンド | 用途 |
|---|---|
ps aux |
全プロセス一覧 |
top / htop |
リアルタイム監視 |
kill -9 [PID] |
強制終了 |
df -h |
ディスク使用量 |
du -sh * |
フォルダサイズ |
free -m |
メモリ使用量 |
lsof -i :80 |
ポート使用確認 |
ネットワーク
curl -I https://example.com # HTTPヘッダー確認
wget https://example.com/file # ファイルダウンロード
netstat -tlnp # 待ち受けポート確認
ss -tulnp # 新しい確認コマンド
ping -c 4 8.8.8.8 # 疎通確認
traceroute example.com # 経路確認
nmap -sV localhost # ポートスキャン
パイプとリダイレクト
# パイプで組み合わせ
cat access.log | grep "404" | wc -l
# リダイレクト
command > output.txt # 上書き
command >> output.txt # 追記
command 2>&1 # エラーも標準出力へ
シェルスクリプト基礎
#!/bin/bash
set -euo pipefail # エラー時即終了
for file in *.log; do
echo "Processing: $file"
gzip "$file"
done
コマンドを組み合わせる力がLinuxの真髄です。毎日少しずつ練習することで体に染み込んできます。




