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?

Linuxのちょっとしたコマンドたち

Last updated at Posted at 2024-07-31

Linuxには便利なコマンドやコマンドの機能があります。知らずに複雑なことをやっていたのに、ふとググってみると実は一行で片付いたり、何てことも多々あります。大したことはありませんが、備忘録t自分が便利だと思ったコマンドをリストアップします(随時更新)。

特定の行の抽出

特定の行を取り出すのためにheadとtailを組み合わせて使っていましたが、行数が処理するファイルによって異なるため、処理が複雑になっていました。取り出したい行が例えばBEGINとENDというキーワードの間にある場合

awk '/BEGIN/,/END/' [file_name]

とすれば良いようです。キーワードはその後別に処理をする必要はあります。

たとえばpw.xで構造最適化を行い、最適化後の構造を取り出すには

awk '/Begin final coordinates/,/End final coordinates/' relax.out

と実行すれば良く、不必要な行を削除するには

awk '/Begin final coordinates/,/End final coordinates/' relax.out | grep -v coordinates

とすれば良いでしょう。

tarコマンドアーカイブを作成する際に特定のファイルを除外する

Linux、あるいはMacではオプションの詳細が違うかもしれませんが、DIRのアーカイブをarchive.tarという名前で作るとし、FILEを除外したいときには

tar --exclude=FILE -cf archive.tar DIR

とします。dataで終わるファイルを除外したい場合は

tar --exclude="*.data" -cf archive.tar DIR

などとして正規表現を利用することも可能です。

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?