Monday, September 10, 2012

Fourth session of Some of basic UNIX commands that are useful very frequently


Today we are going to have some useful information on very useful command 'find' in UNIX systems. find is a command used to search any set of directories that you specified for searching files that matched your search criteria. It is useful to locate the path of files on a UNIX/LINUX system. Below is sample syntax:

 find where-to-look criteria  

  find . -name "*.java" 

Above command will display all the files that have file name extension as '.java'in the current directory.  

find . -mtime 1 

Above command will display all the files that are modified exactly one day in the current directory.  

find .. -mtime -1 

Above command will display all the files that are modified less than one day in the parent directory i.e. suppose if you are in directory '/x/y' then above command will display all files that are modified less than one day in 'x' directory. It will also include 'y' directory in searching.

 find . -perm 444 'perm' 

sub-option is used to search files based up on permissions. I.e. Above command will display all the files that have permission to read for owner,group and others in the current directory. Here in '444', first '4'indicates read permission to current user. Second '4'indicates read permission to current group that current user belongs to. Third '4'indicates read permission to other users that are in current system.

 find . -iname "string" 

If you want to search with case insensitive then you can use option '-i' preceding 'name'. I.e. Above command will display all files that have word 'string' irrespective of case. 

As specified in my previous post, you can also get more information about this command by hitting 'man find' in your terminal.

No comments: