Administration FreeBSD Linux Tips and Tricks

Some useful ‘find’ commands

The ‘find’ command is quite useful as it helps to identify files with specific permissions, users,groups, size, etc.  Also, it is quite helpful to as it allows to process its results when combined with other commands. This article talks about some useful ‘find’ commands.

  • Find all files named ‘test.jpg’ inside /home directory

            find /home —type f -name ‘test.jpg’

  • Run case insensitive search for all files named ‘test.jpg’

            find /home —type f -iname ‘test.JPG’

  • Find all directories that are named ‘test’ under / directory.

           find / -type d – name ‘test’

  • Find all files and directories named ‘test’ starting at current location and search up to 5 levels of directories.

           find . -name ‘test’ -maxdepth 5

  • Find files and directories named ‘test’ starting at current location and search between 3-5 directory levels.

           find .  -type f -name ‘test’ -mindepth 3 -maxdepth 5

  • Find all files starting at current location owned by user ‘bec

           find . -type f -user username

  • Find all files starting at current location owned by some group

          find . -type f -group groupname

  • Find the file whose inode number is 2009

          find . -type f -inum 2009

  • Find all files starting at current location whose size is greater then 200Mb

           find .-type f -size +200M

  • Find all files starting from / whose size is in between 50Mb and 100Mb

          find / -size +50M -size -100M

  • Find all files from the current directory whose permission is 777

          find . -type f -perm 0777

  • Find all files starting from / which was modified between 50 and 100 days ago.

          find / -mtime +50 –mtime -100

  • Find all files starting from / which is owned by user ‘username’ , has permission 777 and is of size greater than 50Mb

          find / -user username -perm 0777 -size +50M

Find can also be used to search files/directories as listed above and then its result can be proccessed by some other commands. For eg:

  • Find all files starting from current directory which are greater than 900Mb and delete such files.

           find . type f  -size +900M -exec rm {} \;

  • Find top 5 big files starting from current directory

           find . -type f -exec ls -s {} \; | sort -n -r | head -5

Related Articles

  • A Basic Overview of the Vim Text Editor

    Many articles in our Webair Community advise editing configuration files. We usually recommend using your preferred text editor. I personally prefer vim. Vim, or its older sibling vi, are installed...
  • Top Open Source applications.

    These are a collection of some useful Open Source office application that are helpful by increasing productivity. Often a person would be limited in buying an expensive piece of software...
  • How to clear the YUM cache?

    What is yum? The Yellowdog Updater, Modified (yum) is an open-source command-line package-management utility for Linux operating systems using the RPM Package Manager. Yum allows automatic updates, package and dependency...
  • Add IP to CentOS 5/6

    If you recently got a secondary IP block for your server but you do not know how to bind the secondary IP address, please follow the steps below:   First, run...