LoginSignup
1
2

More than 5 years have passed since last update.

Linuxコマンド集

Last updated at Posted at 2017-09-30

便利だったり、よく使ったりするコマンドまとめ。随時更新。

ファイルサイズを適当な単位で表示

  • dfは「ディスク・ドライブの使用量」、duは「ディレクトリ内のファイル容量」をそれぞれ表示する
  • .bashrcにエイリアスとして書いておいても良い
$ ls -lh  
$ df -h  # ディスク・ドライブ
$ du -h  # ディレクトリ

ファイルの行数などを表示

  • 行数、単語数、バイト数の順
$ wc [option] [file名]

# option
$ wc -l    # 行数のみ
$ wc -w    # 単語数のみ
$ wc -c    # バイト数のみ

ファイルの末尾をリアルタイム表示

  • 実行中にファイルが更新されているか確認できて便利
$ tail -f [file名]

ファイルの結合

  • ワイルドカードも使用可能
$ cat file1.txt file2.txt > new_file.txt

# 元からあるファイルに追記する
$ cat file2.txt >> file1.txt

ディレクトリ内のファイル数をカウント

  • lsを使ってカウント
  • -1オプションで1行に1ファイルずつ表示させ行数を表示
$ ls -1 | wc -l

$ ls -U1 | wc -l # ソートしなくすると早くなる(lsはデフォルトでソートするため)

$ ls | wc -w # 単語数でカウントしても良い
  • findを使ってカウント
$ find . -type f | wc -l

ファイルの解凍・圧縮

  • tar.gz
$ tar -zxvf xxxx.tar.gz # 解凍
$ tar -zcvf xxxx.tar.gz dirctory # 圧縮
  • zip
$ unzip xxxx.zip # 展開
  • tar
$ tar -xvf xxxx.tar # 解凍
$ tar -cvf xxxx.tar # 圧縮
1
2
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
1
2