linux command "find" with examples
Find in linux means search for files in a directory hierarchy
1.for example if you want to find a file gpg.conf
command to type
admin@smartproteam$ find . -name “gpg.conf” -print
2.To find /usr/bin directory and all sub directories. All files that are of the form ‘*,v’ and ‘.*,v’ are excluded
admin@smartproteam$ find /usr/bin -not \( -name “*,v” -o -name “.*,v” \) ‘{}’ \; -print
* -not means the negation of the expression that follows
* \( means the start of a complex expression.
* \) means the end of a complex expression.
* -o means a logical or of a complex expression.
In this case the complex expression is all files like ‘*,v’ or ‘.*,v’
3.find removes all test files from user’s home directory
admin@smartproteam$ find ~/ -name ‘test*’ -exec rm {} \;
4.Lists all files in /home/admin/test directory tree that were modified within the last day.
admin@smartproteam$ find /home/admin/test -mtime 1
5.Find all the ip address in the /etc directory
admin@smartproteam$ find /etc -exec grep ‘[0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*’ {} \;
6.Find the files in the directory with extensions
admin@smartproteam$ find . -type f \( -name “*.class” -o -name “*.sh” \)









Many thanks for your tips ,a link of this article has been added to http://www.linuxine.com in order to share it with more people.
Thanks a lot edward for sharing
Hey, great post, very well written. You should write more about this.
Leave your response!
Subscribe to Smartproteam
Subscribe to RSS Feeds
Translator
Ads
Recent Posts
Most Commented
Most Viewed