LoginSignup
0
1

More than 5 years have passed since last update.

[memo] Linuxファイル・検索・置換系コマンド (grep,find,sed ..etc)

Last updated at Posted at 2017-03-08

make Symbolic Link: シンボリックリンクの作成

シンボリックリンクの作成

$ ln -s <filepath> <linkname>

現在のパスの表示

$ pwd         :シンボリックリンクをそのまま表示
$ pwd -P   :シンボリックリンクをたどる

Replace strings for files :一括文字列置換

non git
$ find . -type f -print0 | xargs -0 sed -i -e 's/foo/bar/g'
git directory
$ git ls-files -z | xargs -0 sed -i -e 's/foo/bar/g'

<補足:"print0|xargs -0">
http://qiita.com/maskedw/items/2dfdf6fa7eee991ddc45

xargsが空白文字でなくヌル文字を区切りとして扱うように-0を指定し、
xargsの形式に合わせるためにfindの-print0を指定する

Replace URL:URLの置換
replace http://OLDURL > http://NEWURL
# find -type f | xargs grep -l 'http://OLDURL'|xargs sed -i "s,http://OLDURL,http://NEWURL,g"

Find "string" under current directory :

$find -type f|xargs grep -l "string"
Option -l : only file name

Find recently updated file : 最近更新したファイル

$ find -type f -mtime -1|xargs ls -l

Option -mtime : -1= 1day before

0
1
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
1