LoginSignup
9

More than 3 years have passed since last update.

posted at

updated at

git findじゃなくてgit ls-files

git pathspec ~grepでもls-filesでも同じ文法でディレクトリ除外~も見てね!

拡張子指定

ワイルドカードで指定すればカレントディレクトリ以下でマッチしたgit管理ファイルを表示してくれる

$git ls-files *.css
src/components/Footer/style.css
src/components/templates/Container/style.css
# サブディレクトリで実行したけどフルパスで欲しい
$cd src/
$git ls-files *.css
components/Footer/style.css
components/templates/Container/style.css
$git ls-files --full-name components/*/*.css
src/components/Footer/style.css
src/components/templates/Container/style.css

特定ディレクトリ以下

やはりワイルドカード。src/components/*と指定するとsrc/components以下のgit管理ファイルを表示してくれる

$git ls-files src/components/*
src/components/index.js
src/components/Footer/style.css
src/components/templates/Container/style.css

階層指定

やはりワイルドカード

$git ls-files src/components/*/*.css
src/components/Footer/style.css
$git ls-files src/components/*/*/*.css
src/components/templates/Container/style.css

おまけ

grep option alias

$cat .gitconfig
[alias]
  egrep = "grep --heading --break"
$git egrep reveal
package-lock.json
14163:    "scrollreveal": {
14165:      "resolved": "https://registry.npmjs.org/scrollreveal/-/scrollreveal-3.3.6.tgz",

package.json
63:    "scrollreveal": "^3.3.6"

今日出たERRORログをgrepする

ログ置き場(ディレクトリ)に今日生成されたログの内、特定文字列をはいてるfileをgrepしたい時のコマンド

$find /var/log/apache2 -type f -ctime -1 -print0 | xargs -0 grep -n ERROR

-ctime 0でもいいかも

find option desc
type f(=file)やd(=directory)を指定
ctime created time. find -ctime -8で一週間前から今日までに生成したもの、find -ctime +6で一週間以上前に作成
atime last accessed time. 同上
mtime last modified time. 同上
print0 defaultで空白文字(改行、スペース、タブなど)で区切られるため、'hoge fuga'という名称をxargsに渡すと'hoge'と'fuga'に分解されてしまう。これをヌル文字(0×00、\0)に変換
xargs -0 上記を0x00で区切る

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
What you can do with signing up
9