* useful linux commands

ファイル横断検索(現在のディレクトリ)

grep keyword file_names

grep rcp *.py # rcp という文字を含む行を,現在のディレクトリの*.pyファイルについてすべて表示させる

ファイル横断検索(サブディレクトリ)

find ./ -name file_names | xargs grep keyword

例) find ./ -name "*.py" | xargs grep rcp # サブディレクトリの*.pyファイルにgrep する

サブディレクトリにあるファイルの数を数える

find ./ -name ファイル名のキーワード | wc -l

find ./ -name "tmp*.nc" | wc -l

一括ファイル名置換

rename 変更前の文字 変更後の文字 ファイル名

例) rename Pacific pacific *.py

一括ファイル中の文字列置換

perl -e 's/変更前文字列/変更後文字列/g' ファイル名

perl -e 's/Pacific/pacific/g' *py

図を画面上に表示する

gthumb ./ # 複数ファイルならサムレイルが表示されるこっちが便利か

eog x1.png & # 1ファイルならこっちが速い

ファイルをエクスプローラー風に表示する.

nautilus ./

データをダウンロードする

wget -nH --cut-dirs=3 --level=7 -r -R "index.html*,*gif" http://xxx.yyy.zzz/x1/x2/x3/

-nH: no host

--cut-dirs=数値: ディレクトリを指定階層分作成しない--cut-dirs=3なら3階層.

-R: 指定したファイルを対象としない

-N: 同名のファイルがローカルに存在する場合,それよりも新しいファイルのみダウンロードする

-np: no parents 親ディレクトリを対象としない

netcdfデータの情報を知る

ncdump -c netcdf_file | less

Search key words in files in the current directory

usage: grep keyword file_names

example: grep rcp *.py

Search key words in files in the subdirectories

usage: find ./ -name file_names | xargs grep keyword

exapmle: find ./ -name "*.py" | xargs grep rcp

Count file numbers in the subdirectories

usage: find ./ -name keyword | wc -l

example: find ./ -name "tmp*.nc" | wc -l

Replace file name of multiple files

usage: rename original_character replaced_character file_names

example: rename Pac Pacific *.py

Replace string in multiple files

perl -e 's/original_string/replaced_string/g' file_names

perl -e 's/Pac/Pacific/g' *py

Display figures

gthumb ./

eog x1.png &