便利ワンライナー集
そのまま使えるLinux/Unixワンライナー集。HTTPサーバー起動・ファイル転送・テキスト抽出・高度なfind・プロセス分析・ネットワークデバッグ等のレシピをカテゴリ別に整理
56 件のワンライナー
python3 -m http.server 8080Python3 HTTPサーバー
python3 -m http.server 8080python3 -m http.server 8080 --bind 127.0.0.1バインドアドレス指定
python3 -m http.server 8080 --bind 127.0.0.1python -m SimpleHTTPServer 8080Python2 HTTPサーバー
python -m SimpleHTTPServer 8080ruby -run -e httpd . -p 8080Ruby HTTPサーバー
ruby -run -e httpd . -p 8080php -S 0.0.0.0:8080PHP組み込みサーバー
php -S 0.0.0.0:8080npx http-server -p 8080Node.js HTTPサーバー
npx http-server -p 8080busybox httpd -f -p 8080BusyBox HTTPサーバー
busybox httpd -f -p 8080perl -MHTTP::Daemon -e '$d=HTTP::Daemon->new(LocalPort=>8080)||die;print "URL: ",$d->url;while($c=$d->accept){while($r=$c->get_request){$c->send_file_response(".".$r->url->path)}}'Perl HTTPサーバー
perl -MHTTP::Daemon -e '$d=HTTP::Daemon->new(LocalPort=>8080)||die;...'nc -lvnp 4444 < file.txtNetcatでファイル送信
nc -lvnp 4444 < file.txtnc HOST 4444 > file.txtNetcatでファイル受信
nc HOST 4444 > file.txtcurl -T file.txt http://HOST:8080/curlでファイルアップロード
curl -T file.txt http://HOST:8080/curl -O http://HOST:8080/file.txtcurlでファイルダウンロード
curl -O http://HOST:8080/file.txtscp file.txt user@host:/path/SCPでファイル転送
scp file.txt user@host:/path/rsync -avz --progress src/ user@host:dest/rsyncで同期
rsync -avz --progress src/ user@host:dest/base64 file.bin | tr -d '\n'Base64エンコードで転送
base64 file.bin | tr -d '\n'wget -r -np -nH --cut-dirs=1 http://HOST/dir/wget再帰ダウンロード
wget -r -np -nH --cut-dirs=1 http://HOST/dir/grep -oE '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}' file.txtメールアドレスを抽出
grep -oE '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}' file.txtgrep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}' file.txtIPアドレスを抽出
grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}' file.txtgrep -oE 'https?://[^ "]+' file.txtURLを抽出
grep -oE 'https?://[^ "]+' file.txtgrep -oE '[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}' file.txt | sort -uドメインを抽出
grep -oE '[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}' file.txt | sort -usort file.txt | uniq -c | sort -rn | head -20出現回数でソート
sort file.txt | uniq -c | sort -rn | head -20sed '/^$/d' file.txt空行を削除
sed '/^$/d' file.txtsed -n '/START/,/END/p' file.txtパターン間を抽出
sed -n '/START/,/END/p' file.txtawk -F',' '{print $1,$3}' file.csvCSVの特定列を抽出
awk -F',' '{print $1,$3}' file.csvfind / -perm -4000 -type f 2>/dev/nullSUIDビットが設定されたファイル
find / -perm -4000 -type f 2>/dev/nullfind / -writable -type d 2>/dev/null書き込み可能なディレクトリ
find / -writable -type d 2>/dev/nullfind / -writable -type f 2>/dev/null書き込み可能なファイル
find / -writable -type f 2>/dev/nullfind / -mtime -1 -type f 2>/dev/null24時間以内に変更されたファイル
find / -mtime -1 -type f 2>/dev/nullfind / -size +100M -type f 2>/dev/null100MB以上のファイル
find / -size +100M -type f 2>/dev/nullfind . -empty -type f空のファイルを検索
find . -empty -type ffind . -name "*.tmp" -type f -deleteパターンに一致するファイルを削除
find . -name "*.tmp" -type f -deletefind . -name "*.log" -exec grep -l "error" {} \;ファイルを検索して実行
find . -name "*.log" -exec grep -l "error" {} \;lsof -p PIDプロセスのオープンファイル
lsof -p PIDlsof -i -P -n | grep LISTENリッスン中のポート
lsof -i -P -n | grep LISTENlsof -i :8080ポートを使用しているプロセス
lsof -i :8080ls -la /proc/PID/fdプロセスのFD一覧
ls -la /proc/PID/fdstrace -p PID -f -e trace=networkシステムコールをトレース
strace -p PID -f -e trace=networkps auxfプロセスツリーを表示
ps auxfps aux --sort=-%mem | head -20メモリ使用量上位
ps aux --sort=-%mem | head -20ps aux --sort=-%cpu | head -20CPU使用量上位
ps aux --sort=-%cpu | head -20xxd file.bin | head -5016進ダンプ
xxd file.bin | head -50xxd -p file.binバイナリを16進文字列に
xxd -p file.binxxd -r -p hex.txt file.bin16進文字列をバイナリに
xxd -r -p hex.txt file.binstrings -n 8 file.binバイナリから文字列を抽出
strings -n 8 file.bindd if=/dev/sda of=backup.img bs=4M status=progressディスクイメージをコピー
dd if=/dev/sda of=backup.img bs=4M status=progressobjdump -h binaryバイナリのセクション情報
objdump -h binarybase64 file.bin > file.b64Base64エンコード
base64 file.bin > file.b64base64 -d file.b64 > file.binBase64デコード
base64 -d file.b64 > file.bintcpdump -i eth0 -w capture.pcapパケットキャプチャ
tcpdump -i eth0 -w capture.pcaptcpdump -i eth0 'port 80' -AHTTP通信をキャプチャ
tcpdump -i eth0 'port 80' -Aiptables -L -n -v --line-numbersファイアウォールルール一覧
iptables -L -n -v --line-numbersss -tulnpリッスン中のTCP/UDPポート
ss -tulnpcurl -o /dev/null -s -w 'DNS: %{time_namelookup}s\nConnect: %{time_connect}s\nTLS: %{time_appconnect}s\nTotal: %{time_total}s\n' https://example.comcurl接続タイミング
curl -o /dev/null -s -w 'DNS: %{time_namelookup}s\nConnect: %{time_connect}s\n...' https://example.comss -sネットワーク接続の統計
ss -sarp -aARPテーブル表示
arp -aip route showルーティングテーブル表示
ip route show