all kinds of writing

 
 
 
 
 
 
  1. •シンボリックリンクをそのままコピー(実体をコピーではなく)

$ cp -R

-Rオプションがない時は

$ cp -rP


逆にシンボリックリンクを実体としてコピーしたい時は-Lを使用(ディレクトリには-H??)


  1. •ファイル/ディレクトリ検索

$ find ./ -name “hoge*”  -ls カレントディレクトリ以下で、hoge*というファイルを検索(ls付)


  1. •ファイル/ディレクトリのみ再帰的にchmod

$ find path -type f/d |xargs chmod g+w

chmodやrmのように標準入力を受け付けないコマンドにはxargsを使用すべし


  1. •sed:行挿入

MACのsedではうまく動かなかったのでgnu-sed(gsed)を使用。

2行目に挿入

$ sed -e "2i hoge" test.txt

line1

hoge

line2

line3


2行目直下に挿入

$ sed -e "2a hoge" test.txt

line1

line2

hoge

line3


"line2"の行前に挿入

$ sed -e "/^line2$/i hoge" test.txt

line1

hoge

line2

line3


"line2"の行後に挿入

$ sed -e "/^line2$/a hoge" test.txt

line1

line2

hoge

line3


  1. •sed:メタ文字

あくまで参考。置換後の方はエスケープしなくても良いかも。

"  $  @  &  '  (  )  ^  |  [  ]  {  }  ;  *  ?  <  >  `  \  スペース

 

UNIXコマンド