Unix help with files
I have two dat files that are created by script and stored in directory.. is there a way to find what is happening with the files after it is being cre开发者_StackOverflowated.. how can i find that out.. one more thing what command searches for particular word in all files in one directory i tried grep -r.. didnt work for me.. any other suggestion..
You can monitor the files using inotifywait(1)
.
inotifywait
efficiently waits for changes to filesIt is suitable for waiting for changes to files from shell scripts
I agree with others, the first part of your question is too vague. Why not add some detail like 'I expected the file to change like XXXX', how do I confirm that?'
You wrote
what command searches for particular word in all files in one directory
Just use plain grep, i.e.
cd myDataDir
grep 'searchTarget' *
I hope this helps.
P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.
For the second question:
find . | xargs grep word_to_search
It will list recursively all files from the current dir (.) . Then it gives them as input to grep.
For the first question: if you plained to constantly monitor the files changes, you may consider to use svn.
Don't understand your first question. But for your 2nd question, to search for word in files in directory,
Pure shell solution
shopt -s nullglob
for file in *
do
while read -r line
do
case "$line" in
*searchword*) echo "$file: $line";;
esac
done < "$file"
done
Using grep
grep -l "pattern" *
Using awk
awk '/pattern/{print FILENAME": "$0}' *
精彩评论