LoginSignup
48
47

More than 5 years have passed since last update.

普段よく利用しているLinuxコマンドのまとめ

Posted at

Linuxコマンドは奥が深いので、ドキュメントとしてまとめてみました。

ディレクトリの操作

一つ前のディレクトリに戻る。

$ cd -

ディレクトリが存在しなければ作成する。

$ test -d /tmp/files || mkdir /tmp/files

ディレクトリの利用容量を表示する。

$ du -hs /home/*

ディレクトリの利用容量を大きい順に表示する。

$ sudo du -sk /var/* | sort -nr

ファイルの操作

ファイル名に日付を付けてバックアップする。

$ cp -ip /etc/nginx/nginx.conf{,.`date +%Y%m%d`}

連番のファイルを作成する。

$ touch hogehoge{01..10}.txt

findコマンド

検索結果から対象ファイルをまとめてコピーする。

$ find . -name "*.txt" | xargs -i cp {} /tmp/

検索結果から対象ファイルをまとめて削除する。

$ find . -name "*.txt" | xargs rm

grepコマンド

対象ファイルからコメント行と空白行を削除して表示する。

$ grep -v -e "^\s*#" -v -e "^\s*$" /etc/apache2/apache2.conf

複数のログファイルから特定のアクセスを抽出する。

$ grep -ir "172.16.0.1" /var/log/*

その他

対象ファイルの文字列を置換する。

# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

直前に実行した引数を利用する。

$ ls -l /etc/nginx/conf.d/
$ cd $_

1秒おきにコマンドを実行する。

$ watch -n1 "cat /proc/net/ip_conntrack"

80番ポートのLISTENを確認する。

$ netstat -na | grep -e "^tcp.*:80.*LISTEN"

リモートにあるコンテンツをローカルに保存する。

$ curl -o google.html http://www.google.com/

名前解決をする。

$ host www.twiiter.com

参考リンク

48
47
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
48
47