find Command in Linux

Back

The find command searches through directories and sub-directories for a desired file.find exits with status 0 if all files are processed successfully, greater than 0 if errors occur.

If you wanted to find the directory with the named.conf, DNS sample configuration file, you could use the following command, which would start the search in the root directory.

#find  / -name named.conf
      But the speed of that search depends on the memory and processing power available on the local system. With the advent of virtual machines, that processing power may be relatively small. 

Alternatively , if you know that this file is located in the  /usr/subdirectory tree, you could start in that directory with the following command.

# find /usr -name named.conf
     This will find the desired file more quickly.

Examples :

#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.