2018年4月18日 星期三

[Linux 常見問題] How to do max-depth search in ack and grep?

Source From Here 
Question 
Is there any way to tell ack to only search for text on the current folder? (or specify a max-depth level?) And with grep

How-To 
Use -n for no-recurse: 
# ack -n foo

grep is not recursive by default, and you should use the -r flag only if you want a recursive search. Another way to search with max depth limitation is by adopting command find. For example: 
// -H, --with-filename
Print the file name for each match. This is
the default when there is more than one file
to search.

# find Github/ -maxdepth 2 -type f -exec grep -H 'test' {} \;

Supplement 
Home > Blog Tutorial: How to Use Ack and Grep on Ubuntu 14.04

沒有留言:

張貼留言

[ Python 常見問題 ] How to shift a datetime object by 12 hours in python

Source From   Here   Question   Datetime   objects hurt my head for some reason. I am writing to figure out   how to shift a date time obje...