0
0

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 3 years have passed since last update.

現場で使える Linux Command たち

Last updated at Posted at 2021-02-20

Linuxでファイルサイズを0にする http://www.perfectsky.net/blog/?p=16

$ cp /dev/null foo.log

直下すべてのフォルダのサイズを人間に読める表現で表示する

du -h -d 1
du -m -d 1 -x . | sort -n -r

grep を正規表現使用しない https://ex1.m-yabe.com/archives/3012

ps aux | grep -F ".sh"

cksum 結果付ファイル一覧(モジュールリリース時よく使用する)

出力例:cksum 結果 権限(数字) 権限 ユーザー グループ 更新日付 ファイル名

$ find $PWD -maxdepth 1 -type f -printf " %m " -ls | awk '{cmd=sprintf("cksum %s | awk '\''{printf \"%%14s\",$1;}'\''",$12);system(cmd);printf "%12s%12s%12s%12s%4s%12s%12s%12s%4s%4s%7s  %s\n",$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13;close(cmd);}' | awk '{printf "%14s%6s%12s%12s%12s%12s%4s%4s%7s  %s\n",$1,$2,$5,$7,$8,$9,$10,$11,$12,$13}'
    1657920335   644  -rw-r--r--        root        root         176 12月  29   2013  /root/.bash_profile

history に残らない※悪用禁止!!

aaaaaaaaaaaaaaa ; history -d `history | tail -n 1 | awk '{print $1}'`

pstree

# pstree をインストール
$ sudo yum -y install psmisc
# 例として、docker の pstree を表示
$ ps --no-heading -C dockerd -o pid | xargs pstree -spAl
systemd(1)---dockerd(1271)-+-docker-proxy(8948)-+-{docker-proxy}(8949)
                           |                    |-{docker-proxy}(8950)
                           |                    |-{docker-proxy}(8951)
                           |                    |-{docker-proxy}(8952)
                           |                    |-{docker-proxy}(8953)
                           |                    |-{docker-proxy}(8954)
                           |                    |-{docker-proxy}(8955)
                           |                    `-{docker-proxy}(8956)
                           |-docker-proxy(9119)-+-{docker-proxy}(9120)
                           |                    |-{docker-proxy}(9121)
                           |                    |-{docker-proxy}(9122)
                           |                    |-{docker-proxy}(9123)
                           |                    `-{docker-proxy}(9124)
                           |-{dockerd}(1367)
                           |-{dockerd}(1368)
                           |-{dockerd}(1369)
                           |-{dockerd}(1370)
                           |-{dockerd}(1372)
                           |-{dockerd}(1461)
                           |-{dockerd}(1464)
                           |-{dockerd}(1528)
                           |-{dockerd}(1530)
                           |-{dockerd}(1552)
                           |-{dockerd}(1553)
                           |-{dockerd}(1554)
                           |-{dockerd}(2063)
                           |-{dockerd}(2070)
                           |-{dockerd}(2086)
                           |-{dockerd}(2114)
                           |-{dockerd}(2214)
                           |-{dockerd}(2215)
                           `-{dockerd}(2294)

# 現場では、JP1 の pstree を観察(出力は割愛)
$ ps --no-heading -C jajs_spmd -o pid | xargs pstree -spAl

grep の前後n行を表示

$ grep -B 3 "test"  # 前3行
$ grep -A 5 "test"  # 後ろ5行
# 現場のログ監視
$ tail -f xxxx.log | grep -A 5 "[ERROR]"

フォルダをgrep

grep -nr "done" .

ファイル名をフルパスで表示

ls -ld $PWD/*

xargs のパラメータ数とパラメータ位置

数:-L 1 1個つづ
位置:-I {}

find $PWD -type f | xargs -L 1 -I {} md5sum "{}"

find 時エラーメッセージを表示しない

find . -name "aaa" -type f 2>/dev/null

設定ファイルをコメントなし、空行なしで出力

cat xxxx.properties | grep -v '^#' | grep -v '^$'

top

1 : CPU
x : highlight
R : sort
"<" : left column
">" : right column

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?