2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

知ってると便利!エンジニアのためのワンライナーチートシート

Posted at

はじめに

ワンライナー(one-liner)とは、その名の通り「1行で完結するコマンドやスクリプト」のことを指します。特にエンジニアやシステム管理者にとって、ワンライナーを活用できると作業効率が大幅に向上します。

この記事では、便利なワンライナーをカテゴリ別に紹介し、日常業務で役立つ使い方を解説します。


1. ファイル操作系ワンライナー

ファイルの行数を数える

wc -l filename.txt

指定したファイルを末尾10行だけ表示

tail -n 10 filename.txt

ファイルを10行ずつ分割して保存

split -l 10 largefile.txt part_

空のファイルを作成

touch newfile.txt

ファイルの更新日時を変更

touch -m filename.txt

特定の拡張子のファイルを削除

rm -rf *.log

ディレクトリ内のすべてのファイルサイズを合計

du -sh *

2. テキスト処理系ワンライナー

特定の文字列を含む行を抽出

grep '検索文字列' filename.txt

カンマ区切りのCSVをタブ区切りに変換

sed 's/,/\t/g' input.csv > output.tsv

すべての小文字を大文字に変換

tr '[:lower:]' '[:upper:]' < input.txt > output.txt

重複行を削除

sort input.txt | uniq > output.txt

文字列を逆順に表示

tac input.txt

JSONファイルを整形して表示

jq . data.json

3. ネットワーク系ワンライナー

指定したURLにHTTPリクエストを送る

curl -X GET https://example.com/api

自分のグローバルIPアドレスを取得

curl -s ifconfig.me

特定のポートが開いているかチェック

nc -zv example.com 80

サーバーのレスポンスタイムを測定

time curl -o /dev/null -s -w '%{time_total}\n' https://example.com

ネットワークの接続状況を確認

ping -c 4 example.com

ネットワークの帯域幅を測定

iperf -c example.com

4. システム情報系ワンライナー

CPU使用率をリアルタイム表示

top

ディスク使用量を一覧表示

df -h

メモリの使用状況を確認

free -m

現在のプロセスを確認

ps aux

システムの稼働時間を確認

uptime

利用可能なメモリを監視

vmstat 1

5. Git操作系ワンライナー

直近のコミットログを表示

git log --oneline -5

変更したファイルを確認

git status -s

指定したコミットまでリセット

git reset --hard HEAD~3

最新のリモートリポジトリの変更を取得

git pull origin main

変更をステージングしてコミット

git add . && git commit -m 'Update files'

リモートリポジトリのURLを確認

git remote -v

まとめ

ワンライナーを活用することで、コマンド操作のスピードが格段に向上します。日々の業務やシステム管理で使えるものばかりなので、ぜひ試してみてください。

他にも便利なワンライナーがあれば、ぜひコメントで共有してください!

2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?