Showing posts with label find. Show all posts
Showing posts with label find. Show all posts

Monday, January 18, 2010

Count number of files in directory

find files | count lines


find . -type f | wc -l

Friday, September 18, 2009

Find files & directories in terminal


# Simple method to find files recursively from path with which matches expression
find ./ -name "*.rb"

# find directories recursively which matches expression (directory type)
find ./ -name 'specs*' -type d

Wednesday, July 29, 2009

Easy command line search with grep and find

I've been using grep and find for searches on command line.

Examples:

# Search recursively for 'User' in file contents under current directory
grep -r 'User' .

# Search recursively for 'User' in file contents under current directory and display 2 lines before and after
grep -r -2 'User' .

# Search recursively for 'User' in file contents under current directory and display 2 lines before and after with color
grep -r -2 --color 'User' .

# Search for filenames that contains user.
find . -name 'user.*'


Combine them together:

grep -r -2 --color 'User' $(find . -name 'user.*')