Friday, June 3, 2011

linux file find method

SEARCH FILE HAS SPECIAL NAME AND SIZE ETC
find -name 'mypage.htm'

In the above command the system would search for any file named mypage.htm in the current directory and any subdirectory.

find / -name 'mypage.htm'

In the above example the system would search for any file named mypage.htm on the root and all subdirectories from the root.

find -name 'file*'

In the above example the system would search for any file beginning with file in the current directory and any subdirectory.

find -name '*' -size +1000k

In the above example the system would search for any file that is larger then 1000k.

find . -size +500000 -print

Next, similar to the above example, just formatted differently this command would find anything above 500MB.

---------------------------------------------------------------------------------------------
SEARCH FILE CONTAIN STRING
Task: Search all subdirectories recursively

You can search for a text string all files under each directory, recursively with -roption:
$ grep -r "redeem reward" /home/tom
Task: Only print filenames

By default, grep command prints the matching lines You can pass -H option to print the filename for each match.
$ grep -H -r “redeem reward” /home/tom

No comments:

Post a Comment