Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
8
Help us understand the problem. What is going on with this article?
@darai0512

git findじゃなくてgit ls-files

More than 1 year has passed since last update.

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で区切る
8
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
darai0512
jsとNode.jsとAutomationがお好き

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
8
Help us understand the problem. What is going on with this article?