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

  • Prevent hot linking of images.

    Hot linking is displaying an image on a website by linking to the same image on another website, rather than saving a copy of it on the website on which...
  • Scanning for rootkits and possible exploits – RKHunter

    Rootkits are malicious softwares that are installed by intruders to gain access to your server once the security of the server has been breached.  Intruders can leave some malicious softwares...
  • 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...
  • Users Logged Into Server

    This article explains on how to identify those who you do not know that are on your server. This can definitely eliminate the curiosity that people can have when taking...