5
11

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.

忘れがちなLinuxコマンド

Last updated at Posted at 2017-09-17
種別 操作 コマンド
文字列操作 文字列検索 grep
文字列成形 awk
文字列切り取り cut
文字列置換 sed
文字列表示 echo
ファイル・ディレクトリ操作 ファイル検索 find
パーミッション操作 chmod
所有者・グループ操作 chown
シンボリックリンク作成 ln
ファイル差分表示 diff / sdiff
ディレクトリ移動 cd
バイナリファイル操作 ファイル表示 od / hexdump / xxd / vim
ファイル比較 cmp
ファイル分割 split
ファイル結合 cat
ファイル切り出し head / tail
ランダム0データ作成 head
オブジェクトファイル操作 オブジェクトファイル解析 objdump
逆アッセンブル結果表示 objdump
ELFファイル情報表示 readelf
シンボル情報表示 nm
行単位操作 行の並び替え sort
指定行表示 sed
行単位のファイル連結 paste
ファイルの行数表示 wc
重複行の排除 uniq
列単位操作 任意列の出力 cut
複数のファイルを列方向に連結 paste
ファイル・ディレクトリ名操作 パス名からファイル名取得 basename
パス名からディレクトリ名取得 dirname
日時を入れてファイル作成 date
圧縮・解凍 圧縮 zip / gzip / tar
解凍 unzip / gunzip / tar / bzcat
圧縮ファイル参照 tar / bzcat
セッション操作 セッション再開 screen
プロセス操作 全ての実行中プロセス情報表示 ps
プロセスをツリー表示 pstree
プロセス統計情報を表示 pidstat
プロセスID検索 pgrep
プロセス使用メモリ表示 pmap
一定間隔でプロセス情報表示 top
プロセス終了 kill
関連するプロセスを一括で終了 killall
ログアウト後もプロセス(コマンド)実行 nohup
プロセスが終了するまでウエイト wait
容量・使用量操作 ファイル容量表示 du
ディスク使用量表示 df
メモリ使用量表示 free
ハード情報表示 CPU情報表示 lscup
モジュール情報表示 lsmod
モジュール詳細情報表示 modinfo
USBデバイス表示 lsusb
USBデバイス詳細表示 usb-devices
ブロックデバイス表示 lsblk / blkid
SCSIデバイス表示 lsscsi
PCIデバイス表示 lspci
ハードウェア情報表示 dmidecode
OS情報表示 メモリ・プロセス等の情報表示 vmstat
CPU使用率・割り込み情報表示 mpstat
I/Oデバイスの使用状況表示 iostat
ユーザ情報の一覧表示 lslogins
オープン中ファイル一覧表示 lsof
ログイン情報操作 ログイン中のユーザ情報表示 w
ログイン中のユーザ名表示 users
ログイン履歴表示 last
ユーザ単位の最終ログイン履歴表示 lastlog
CPU動作時間解析 time
ネットワーク情報表示 ネットワークインタフェース設定の表示 ifconfig
IPアドレスの表示 ip addr
ネットワーク接続状況の表示 netstat
ネットワーク経路表示① traceroute
ネットワーク経路表示② mrt
ルーティングテーブル表示 route
イベント出力 カーネルのMSGを表示 dmesg
Systemdログ表示 journalctl
udevイベントをモニタする udevadm
システムコールの発行状況を表示 strace
インストール・ダウンロード パッケージ操作(Redhat系) yum
パッケージ操作(Dibian系) apt-get
通信関係 SSH接続 ssh
ターミナルエミュレータ起動 minicom
シャットダウン・リブート操作 シャットダウン shutdown
リブート reboot
マウント操作 マウント mount
アンマウント umount
バックアップ操作 バックアップ back
リストア restore

■ 文字列処理

● grep - 文字列検索

OR検索

$ grep -e "a" -e "b" output.txt

AND検索

$ grep "a" output.txt | grep "b" output.txt

ファイル名指定

$ grep -r --include="*.txt" "a"

特定の文字を除外

$ grep "a" output.txt | grep -v "b"

複数の特定の文字を除外

$ grep -v -e "a" -e "b" output.txt

検索Hitの行数表示

$ grep -c "a" output.txt

ファイル名を表示

一致したファイル
$ grep -l "a" output.txt
一致しないファイル
$ grep -L "a" output.txt

前後の行表示

前の行表示
$ grep -B 10 "a" output.txt
後の行表示
$ grep -A 10 "a" output.txt
前後の行表示
$ grep -C 10 "a" output.txt

ディレクトリ指定で検索

1階層下で検索
$ grep "a" */*
2階層下で検索
$ grep "a" */*/*
全階層で検索
$ grep -r "a" *

行頭・行末で検索

行頭で検索
$ grep "^a" output.txt
行末で検索
$ grep "a$" output.txt

メタ文字の検索

$ grep '\[' output.txt

オプション

$ grep -nriw "a" *

【オプション】
-n :行数表示
-r :サブディレクトリも検索
-i :大文字・小文字の区別なし
-w :指定文字と完全一致のみ表示
-l :ファイル名のみ表示
-h :ファイル名を除いて表示
-a :強制テキスト認識(バイナリファイルに一致しました対応)

● awk - 文字列成形

偶数・奇数行の表示

偶数
$ cat output.txt | awk 'NR % 2 == 0'
奇数
$ cat output.txt | awk 'NR % 2 == 1'

先頭5行の表示

$ cat output.txt | awk 'NR <= 5'

フィールド数が5の行を表示

$ awk 'NF == 5' output.txt

20文字以上の行を表示

$ awk 'length($0) > 20'

2つめのフィールドを表示

$ awk '{print ":" $2}' output.txt

空行の削除

$ awk 'NR' output.txt

先頭が/でない行の表示

$ gawk '! /^\//{ printf $0 "\n"}' output.txt

デリミタ追加

$ awk -F '[: ]' '{print $1 "-" $2}' output.txt 

● cut - 文字列切り取り

任意の文字位置を切り取り

$ cat output.txt
abcdef
$ cut -c 2-4 output.txt
bced
$ cut -c -3 output.txt
abc
$ cut -c 4- output.txt
def

-c :文字数指定
-b :バイト数指定

任意のフィールド位置を切り取り

$ cat output.txt
abc:def
$ cut -d-f 2 output.txt
def

-d :デリミタ指定
-f :フィールド位置指定

● sed - 文字列置換

文字列の置換

$ sed -e "s/oldword/newword/g"

文字列の削除

$ sed -e "s/removeword//"

スペースをカンマに置換

$ sed -e "s/ /,/g"

● echo - 文字列表示

改行なしで表示

$ echo -n No new line.

改行を表示

$ echo -e New line.\\nNext line.
$ echo -e "New line.\nNext line."

● tr - 大文字 ⇔ 小文字変換

大文字から小文字
$ echo "ABCD" | tr "[:upper:]" "[:lower:]"
abcd 
小文字から大文字
$ echo "abcd" | tr "[:lower:]" "[:upper:]"
ABCD 

● tr/nkf/sed/od - 改行コード変換

CR+LF(Windows) ⇒ LF(Linux)

$ file win.txt
win.txt: ASCII text, with CRLF line terminators
$ cat win.txt | tr -d '\r'

\r :キャリッジリターン
\n :ラインフィード

$ nkf -d win.txt > after.txt

LF(Linux) ⇒ CR+LF(Windows)

$ cat linux.txt | sed -e "s/$/\r/g"
$ nkf -c win.txt > after.txt
$ od -c linux.txt 

● file - ファイルタイプ判別

テキストの文字コード表示

$ file -i input.txt
input.c: text/plain; charset=us-ascii

● iconv/nkf - 文字コード変換

文字コードをUTF-8からSJISへ変換

$ iconv -f utf8 -t SJIS input.txt -o output.txt

【オプション】
-f :変換前の文字コード
-t :変換後に文字コード
-o :出力ファイル

【文字コード】
utf8:UTF-8
SJIS:Shift-JIS
EUCJP:EUC-JP
cp932:Microsoft コードページ 932

任意の文字コードに変換

$ nkf -w input.txt > output.txt

【オプション】
-e :EUCコードを出力
-j :JISコードを出力
-s :SJISコードを出力
-w :UTF-8コードと出力

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

● find - ファイル検索

ファイル検索

$ find . -maxdepth 2 -type f -name "output*"

【オプション】
-maxdepth 2 :検索上限階層指定

ディレクトリ検索

$ find . -type d -name "output*"

シンボリックリンク検索

$ find . -type l -name "output*"

10日よりも前にアクセスしたファイル検索

$ find . -type f -atime +10

10日アクセスされていないファイルの削除

fine . -type f -atime +10 -print0 | xargs -0 rm

10日以内にアクセスしたファイル検索

$ find . -type f -atime -10

10日以内に更新したファイル検索

$ find . -type f -mtime -10

128KB以上のファイル検索

$ find . -type f size +128k

● chmod - パーミッション操作

スクリプトに実行権限付与
$ chmod +x test.sh
所有者に全権限付与、グループ・その他にリード・実行権限付与
$ chmod 755 test.sh
パーミッション
r 4
w 2
x 1
- 0
子ディレクトリ・ファイルを含めて権限付与
$ chmod -R 777 directory

● chown - 所有者・グループ操作

ファイルの所有者変更
# chown username file
ディレクトリ内の所有者変更
# chown -R username directory

● ln - シンボリックリンク操作

シンボリックリンク作成
$ ln -s filename linkname
$ ln -s dirname linkname
シンボリックリンクリネーム
$ ln -fs new_filename linkname
$ ln -nfs new_dirname linkname

● diff/sdiff - ファイルの差分表示

同一行を含めて表示

$ diff output1.txt output2.txt
$ sdiff output1.txt output2.txt

差分のみ表示

$ sdiff -s output1.txt output2.txt

左右で比較

$ diff -y output1.txt output2.txt

【オプション】
--left-column :共通行は左側のみ表示

ディレクトリ単位で比較

$ diff -r directory1 directory2

● cd - ディレクトリ移動

$ cd /root directory file
$ cd ~/home directory file

● rm - ファイル・ディレクトリ削除

Yes確認なしで一括削除

$ yes | rm *

● rename - ファイル・ディレクトリ名変更

$ rename old new old_file*.txt
$ ls
new_file0.txt new_file1.txt

■ バイナリファイル操作

● od - ファイル表示①

$ od -tx1 -w16 -Ax input.bin
000000 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff

$ od -tx4 -w16 -Ax input.bin
000000 33221100 77665544 bbaa9988 ffeeddcc

【オプション】
-tx1 :区切りバイト数
-w16 :1行に表示するバイト数
-Ax  :アドレス部の16進数表示

● hexdump - ファイル表示②

$ hexdump -C input.bin
00000000  00 11 22 33 44 55 66 77  88 99 aa bb cc dd ee ff  |.."3DUfw........|

$ hexdump -e '"%08.8_ax  " 4/4 "%08x  " "\n"' input.bin
00000000  33221100  77665544  bbaa9988  ffeeddcc

【オプション】
-C :16進数とASCII文字で出力
-e :フォーマット文字列を指定
-v :省略せずに全入力データを表示

● xxd - ファイル表示③

$ xxd input.bin
0000000: 0011 2233 4455 6677 8899 aabb ccdd eeff  .."3DUfw........

【オプション】
-g :空白を入れるバイト数(-g 4:4Byte区切りで表示。-g 0:区切りなし)
-s :オフセット指定(ex:-s 0x10000)
-b :2進数表示

● vim - ファイル編集

$ vim -b input.bin
vim
1 ^@^Q"3DUfw<88><99><aa><bb><cc><dd><ee><ff>
:%!xxd
1 0000000: 0011 2233 4455 6677 8899 aabb ccdd eeff  .."3DUfw........
【All Fに編集】
1 0000000: ffff ffff ffff ffff ffff ffff ffff ffff  .."3DUfw........
:%!xxd -r
1 <ff><ff><ff><ff><ff><ff><ff><ff><ff><ff><ff><ff><ff><ff><ff><ff>
:wq

● cmp - ファイル比較

$ cmp -l all0.bin allF.bin
1   0 377
2   0 377
3   0 377
4   0 377

$ cmp -l -i2 -n1 all0.bin allF.bin
1   0 377

【オプション】
-l  :位置(10進数)と値(8進数)を表示
-i2 :比較開始位置の指定
-n1 :比較サイズの指定

● split - ファイル分割

$ split -b 16 all.bin binary
$ split -b 16k all.bin binary
$ split -b 16m all.bin binary

【オプション】
-b :バイト単位に分割

● cat - ファイル結合

$ cat *.bin all.bin

● head/tail - ファイル切り出し

$ head -c 16 all.bin > head.bin
$ tail -c 16 all.bin > tail.bin
$ head -c 16 all.bin | tail -c 8 > mid.bin

● head - ランダムデータ作成

完全な乱数
$ head -c 256 /dev/random > data.bin
疑似乱数が入る場合あり
$ head -c 256 /dev/urandom > data.bin

● head - 0データ作成

$ head -c 256 /dev/zero > data.bin

■ オブジェクトファイル操作

● objdump - オブジェクトファイル解析

$ objdump test.o

【オプション】
-h :セクション一覧表示
-p :プログラムヘッダ表示
-s :セクション単位の内容表示

セクション指定表示
$ objdump -s -j [.section-name] test.o
アドレス範囲を指定して表示
$ objdump -s --start-address=0x400400 --stop-address=0x400600 test.o

● objdump -d - 逆アセンブル結果表示

$ objdump -d test.o
セクション指定表示
$ objdump -d -j [.section name] test.o
アドレス範囲を指定して表示
$ objdump -d --start-address=0x400400 --stop-address=0x400600 test.o
対応するソースを表示
$ objdump -d -S test.o

● readelf - ELFファイル情報表示

$ readelf -h test.o

-h :ファイルヘッダ表示
-l :プログラムヘッダ表示
-S :セクションヘッダ表示
-e :全てのヘッダ表示
-s :シンボルテーブル表示
-r :リロケーション情報表示

指定セクションの表示
$ readelf -x [section no] test.o

● nm - シンボル情報表示

$ nm test.o

【オプション】
-A :オブジェクトファイル名を表示
-S :サイズを表示
-S --size-sort :サイズの小さい順に表示
-S --size-sort -r :サイズの大きい順に表示
-f posix :posixで表示

■ 行単位操作

● sort - 行の並び替え

整数順にソート

昇順
$ sort -n input.txt
降順
$ sort -nr input.txt

実数順にソート

昇順
$ sort -g input.txt

デリミタ指定

2番目のフィールドでソート
$ sort -k 2 -t , input.txt

● sed - 指定行表示

5行目表示

$ sed -n 5p output.txt

5行目から10行目表示

$ sed -n 5,10p output.txt

● paste - 行単位のファイル連結

$ paste input1.txt input2.txt > output.txt
デリミタ指定
$ paste -d , input1.txt input2.txt > output.txt

● wc - ファイルの行数表示

$ cat output.txt | wc

-l :行数のみ表示

● uniq - 重複行の排除

重複を除外

$ sort output.txt | uniq

重複する行のみ表示

$ sort output.txt | uniq -d

値が何行出現するか表示

$ sort output.txt | uniq -c

ユニークな行を表示

$ sort output.txt | uniq -u

■ 列単位操作

● cut - 任意の列の出力

$ cat output.txt | cut -d "," -f 2-4,6-

【オプション】
-d :デリミタ指定
-f :任意列の出力

● paste - 複数のファイルを列方向に連結

$ paste -d , *txt

-d :デリミタ指定

■ 標準出力とファイル出力を同時実行(tee)

$ ifconfig | tee output.txt

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

● basename - パス名からファイル名取得

$ basename home/workspace/test.sh
test.sh

● dirname - パス名からディレクトリ名取得

$ basename home/workspace/test.sh
home/workspace

● date - 日時操作

日時を入れてファイル作成

$ touch `date +"%Y%m%d"`.txt
$ grep "LOG" -rn * > `date +"%Y%m%d"`.txt

日時表示

$ echo `date +"%Y%m%d"`
20171012
$ echo `date +"%D"`
10/12/17
$ echo `date +"%H%M%S"`
085410

■ 圧縮・解凍

● zip/gzip/tar - 圧縮

zip
$ zip output.zip output.txt
zip(パスワード付き)
$ zip -e output.zip output.txt
zip(ディレクトリ)
$ zip -r output.zip output/
zip(ディレクトリ・パスワード付き)
$ zip -r -e output.zip output/
gzip
$ gzip output.txt
tar
$ tar czvf output.tar output.txt

● unzip/gunzip/tar/bzcat - 解凍

zip
$ unzip output.zip
gzip
$ gunzip output.gz
tar
$ tar xzvf output.tar

● tar/bzcat - 圧縮ファイル参照

tar
$ tar tvf output.tar
bzcat
$ bzcat output.bz2

■ セッション操作

● Screen - セッションの再開

セッション作成

$ screen
$ screen -S suspended_test

デタッチ

ctrl + a + d

セッション一覧表示

$ screen -ls

アタッチ

$ screen -r
$ screen -r suspended_test

強制アタッチ

$ screen -d -r PID

■ プロセス操作

● ps - 全ての実行中プロセス情報表示

$ ps axuf

● pstree - プロセスをツリー表示

$ pstree

● pidstat - プロセス統計情報を表示

$ pidstat

● pgrep - プロセスID検索

$ pgrep -a keyword

● pmap - プロセス使用メモリ表示

$ pmap pid

【オプション】
-x :詳細消費表示
-d :デバイスフォーマット表示
-p :パス表示

● top - 一定間隔でプロセス情報表示

1秒間隔で10回表示
$ top -d 1 -n 10

【オプション】
-d :一定間隔で表示
-n :規定回数表示

● kill - プロセス終了

$ kill [pid]

● killall - 関連するプロセスを一括で終了

$ killall minicom
$ ps -ef | grep "search word" | awk '{print $2}' | xargs kill

● nohup - ログアウト後もプロセス(コマンド)実行

$ nohup command &

● wait - プロセスが終了するまでウエイト

指定プロセスが終了するまでウエイト
$ wait [process id]
全プロセスが終了するまでウエイト
$ wait

■ 容量・使用量操作

● du - ファイル容量表示

ディレクトリ合計表示

$ du -sh

【オプション】
-s :合計サイズの表示
-h :最適なサイズの表示

直下のディレクトリと一緒に表示

$ du -sch *

【オプション】
-c :合計サイズの表示

個々のディレクトリで表示

$ du -Sh

【オプション】
-S :合計サイズの表示

サイズ順に表示

$ du -Sh | sort -nr

● df - ディスク使用量表示

$ df -ah

【オプション】
-a :全てのディスクの表示
-h :最適なサイズの表示
-k :KB表示
-m :MB表示
-g :GB表示

● free - メモリ使用量表示

KB表示
$ free

【オプション】
-b :Byte表示
-k :KB表示
-m :MB表示
-g :GB表示

■ ハード情報表示

● lscpu - CPU情報表示

$ lscpu

● lsmod - モジュール情報表示

$ lsmod

● modinfo - モジュール詳細情報表示

$ modinfo [module name]

● lsusb - USBデバイス表示

$ lsusb

【オプション】
-v :詳細表示
-t :ツリー構造で表示

● usb-devices - USBデバイス詳細表示

$ usb-devices

● lsblk - ブロックデバイス表示①

$ lsblk

● blkid - ブロックデバイス表示②

$ blkid

● lsscsi - SCSIデバイス表示

$ lsscsi

【オプション】
-v :詳細表示

● lspci - PCIデバイス表示

$ lspci

【オプション】
-v :詳細表示

● dmidecode - ハードウェア情報表示

# dmidecode

■ OS情報表示

● vmstat - メモリ・プロセス等の情報表示

$ vmstat

【オプション】
-a :アクティブ・インアクティブ メモリ情報表示
-d :ディスク統計情報表示
-D :ディスク統計情報 サマリ値表示
-f :ブート以降のフォーク数表示
-s :イベントカウンタ表示

● mpstat - CPU使用率・割り込み情報表示

$ mpstat -A

● iostat - CPU使用率、I/Oデバイスの使用状況表示

$ iostat

● lslogins - ユーザ情報の一覧表示

$ lslogins

● lsof - オープン中ファイル一覧表示

$ lsof [file name]

【オプション】
-i :ネットワークコネクション表示
-i :1-128 :ポートレンジ指定
-u username :ユーザ名指定

■ ログイン情報操作

● w - ログイン中のユーザ情報表示

$ w

● users - ログイン中のユーザ名表示

$ users

● last - ログイン履歴表示

$ last

● lastlog - ユーザ単位の最終ログイン履歴表示

$ lastlog

● time - CPU動作時間解析

$ time cp test1.py test2.py
real    0m0.009s
user    0m0.006s
sys     0m0.000s
表示 意味
real 経過時間
user ユーザモードの実行時間
sys システムコールの実行時間

■ ネットワーク情報表示

● ifconfig - ネットワークインタフェース設定の表示

$ ifconfig

● ip addr - IPアドレスの表示

$ ip addr

● netstat - ネットワーク接続状況の表示

$ netstat

【オプション】
-a :全情報を表示
-g :マルチキャストグループ情報を表示
-i :ネットワークインタフェースと統計情報を表示
-n :名前解決前のアクティブTCPコネクションを表示
-p :ソケットを使用しているプロセス情報を表示
-r :IPルーティングテーブルを表示
-s :プロトコル統計情報を表示
-t :TCPコネクションを表示
-u :UDPコネクションを表示

● traceroute - ネットワーク経路表示①

$ traceroute destination.com
$ traceroute IP address

● mtr - ネットワーク経路表示②

$ mtr destination.com
$ mtr IP address

● route - ルーティングテーブル表示

$ route

■ イベント出力

● dmesg - カーネルのMSGを表示

$ dmesg

● journalctl - Systemdログ表示

$ journalctl

【オプション】
-b :直近の起動時からのログ表示
-f :直近のジャーナル表示
-k :カーネルメッセージ表示
-u unitname :ユニット指定(httpd/sshd/nginx.service etc)
-n 50 :直近の指定エントリ数表示(数値指定なしの場合は10エントリ)
--since data:日時指定(yesterday/today/tomorrow etc)

● udevadm - udevイベントをモニタする

$ udevadm monitor --env

● strace - システムコールの発行状況を表示

$ strace [command]
所要時間をμsで表示
$ strace -T [command]

■ インストール・ダウンロード

● yum - パッケージ操作(Redhat系)

アップデートのあるパッケージを表示

# yum check-update

パッケージインストール

# yum install packagename

パッケージアップデート

# yum update packagename

パッケージ削除

# yum remove packagename

パッケージ情報表示

# yum info packagename

● apt-get - パッケージ操作(Debian系)

パッケージ取得

# apt-get update

パッケージアップデート

# apt-get upgrade

パッケージインストール

# apt-get install packagename

パッケージ削除

# apt-get remove packagename

● wget - ファイルダウンロード

$ wget url

● modprobe - カーネルモジュールインストール

# modprobe usbserial vendor=0xID product=0xID

■ 通信関係

● ssh - SSH接続

デフォルトポート(22番)指定

$ ssh ipaddress

ポート番号指定

$ ssh ipaddress -p portno

秘密鍵指定

$ ssh username@ipaddress -i filepath

sshログイン先でコマンド実行

$ ssh ipaddress "command1; command2; command3"

ユーザ名指定

$ ssh username@ipaddress

● minicom - ターミナルエミュレータ起動

設定メニューありで起動

# minicom -s

モデム初期化なしで起動

# minicom -o

■ シャットダウン・リブート操作

● shutdown - シャットダウン・リブート

# shutdonw -h now
# shutdown -r 17:00
# shutdown -c
# shutdown -k 1
The system is going down for maintenance in 1 minute!

【オプション】
-h :シャットダウン
-r :リブート
-c :キャンセル
-k :全ユーザにワーニングメッセージを表示

● reboot - リブート

# reboot

● init/telinit - ランレベル6に設定

# init 6
# telinit 6

■ マウント・アンマウント

● mount - マウント

# mkdir /media/external_usb
# mount /dev/sda1 /media/external_usb

● umount - アンマウント

# umount /media/external_usb

■ バックアップ・リストア

● back - バックアップ

# backup -f output.dump /home

● restore - リストア

# restore -rf output.dump

■ history - コマンド履歴

コマンド履歴表示

$ history

コマンド実行

$ !番号

コマンド履歴消去

$ history -d 1003
$ history -c

直近実行の履歴コマンド実行

$ !!

■ wall - ログインユーザへの一斉メッセージ

$ wall message

■ デフォルトアプリケーション起動

xdg-open - デフォルトアプリケーション起動

$ xdg-open filename

xdg-open - カレントディレクトリ起動

$ xdg-open .

■ プログラミング

● gcc

コンパイルしてELF形式のオブジェクトを作成

$ gcc -c main.c
$ gcc -c main.c sub.c

コンパイル・リンクしてELF形式の実行可能ファイルを作成

$ gcc -o main main.c
$ gcc -o main main.c sub.c

リンクしてELF形式の実行可能ファイルを作成

$ gcc -o main main.o sub.o

プリプロセス完了時のソースを標準出力に出す

$ gcc -E main.c

● コード解析

sort/uniq - 重複数カウント

$ cat output.txt | sort | uniq -c
      1 LOG_POINT_A
      3 LOG_POINT_B
      2 LOG_POINT_C

■ MySQL操作(Debian系)

起動

# service mysql start

停止

# service mysql stop

状態取得

# service mysql status

■ コマンド組み合わせ

CSVファイルの行列入れ替え

改行コード:LF
$ cat input.csv
a,4
b,5
c,6
a,7
b,8
c,9
$ cat input.csv | awk -F '[, ]' '{print $1}' | xargs -n 3 | awk 'NR<=1' > temp0.csv
$ cat input.csv | awk -F '[, ]' '{print $2}' | xargs -n 3 > temp1.csv
$ cat temp0.csv temp1.csv | awk 'NR==1 {print "# " $0} NR>1 {print NR-1 " " $0}' | sed -e "s/ /,/g"
#,a,b,c
1,4,5,6
2,7,8,9

拡張子の一括変換

$ ls
0.bin 1.bin 2.bin
$ ls *.bin | while read f; do mv $f `basename $f .bin`.dmp; done
$ ls
1.dmp 1.dmp 2.dmp

bash_profileの反映

$ source ~/.bash_profile
5
11
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
5
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?