Find: Difference between revisions

From Psygen Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 31: Line 31:
You can have find files based on permissions:
You can have find files based on permissions:


<code>find . -type f -perm 0777 -print</code> This will find files in the current directory with 0777 permissions
<code>find . -type f -perm 644</code> This will find files in the current directory with 0777 permissions


<code></code>
<code> . </code> look in the current directory
 
<code>-type f</code> look for files
 
<code>-perm 644</code> look for permissions. What permissions? 644 (-rw-r--r--)
 
'''
More Examples of finding by permissions:'''
 
<code>find -type f ! -perm 777</code> Look for anything that does NOT have 777 permissions





Revision as of 18:21, 23 December 2016

Find is used to search the directory system for files.

find location options search pattern

find /home myfile.txt This will look in the /home folder for myfile.txt (if you leave out the location, find will look in the directory you are currently in.)

By Name

By default, find is case-sensitive. The above example will not find MYFILE.TXT. The -iname flag tells find to ignore case.

If you want the search to be case insensitive:

find -iname myfile.txt

The above will find all of the following: myfile.txt MYFILE.TXT MyFile.txt (etc...)


By Type

find -type f -name "*.txt" This will find all the files whose name ends in .txt in the current directory.

The -type f flag tells find to look for files ( -type d will tell find to look for directories.)


By Permission

You can have find files based on permissions:

find . -type f -perm 644 This will find files in the current directory with 0777 permissions

. look in the current directory

-type f look for files

-perm 644 look for permissions. What permissions? 644 (-rw-r--r--)

More Examples of finding by permissions:

find -type f ! -perm 777 Look for anything that does NOT have 777 permissions


References

  1. find man page
  2. Tecmint find Examples