If you use find
, you don't need xargs
in most cases.
The following should work:
find $(1) -exec stat -c "%n,%Y" {} \; | sed 's#$(1)\/##'
Note that I use $(1) as both parameter to find
and in sed
substitution command.
题
I am trying to collect file path and timestamp for each file under a certain directory(which is passed as an argument) in makefile
So, it goes like this.
TIMESTAMP_LOG := timestamp.log
TARGET_ROOT := ../../out/root
define collect-timestamp
$(shell find $(1) | xargs -lfn sh -c 'echo -n fn"," >> $(TIMESTAMP_LOG); stat -c %Y fn >> $(TIMESTAMP_LOG)')
endef
all:
$(call collect-timestamp, $(TARGET_ROOT))
If I run this, i would the get whole file path and timestamp as below ex) ../../out/root/bin/ls,133030303
but I want to get rid of "../../out/root" in file path.(passing as an argument if possible)
I thought I could do this using sed or shell script(see below) but apparently I am stuck. I tried:
$(shell find $(1) | xargs -Ifn sh -c 'echo -n ${fn##$(1)}"," >> $(TIMESTAMP_LOG); stat -c %Y fn >> $(TIMESTAMP_LOG)')
$(shell find $(1) | xargs -Ifn sh -c 'sed 's/fn//g' >> $(TIMESTAMP_LOG); stat -c %Y fn >> $(TIMESTAMP_LOG)')
解决方案
If you use find
, you don't need xargs
in most cases.
The following should work:
find $(1) -exec stat -c "%n,%Y" {} \; | sed 's#$(1)\/##'
Note that I use $(1) as both parameter to find
and in sed
substitution command.
其他提示
You may try
find $(1) | xargs stat -c %Y >> $(TIMESTAMP_LOG)