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

  • Redis install steps on FreeBSD

      Install redis FreeBSD port collection: $ cd /usr/ports/databases/redis/ && make install clean # or with portmaster $ portmaster databases/redis   ===>  CONFIGURATION NOTE:   To setup “redis” you need...
  • How to Manage a Linux Server with systemd

    What Operating Systems Have Adopted systemd? CentOS: Yes, by default since CentOS 7 Fedora: Yes, since the release of Fedora 15 RedHat: Yes Debian: Yes, shipped since Debian 7 as...
  • How to Display MySQL Storage Engines

    How to Display MySQL Storage Engines From the MySQL command line, issue the following command: SHOW ENGINES; You should receive a result similar to:   Typically the default storage engine...
  • Vi Commands 101

    Cursor movement h – move left j – move down k – move up l – move right w – jump by start of words (punctuation considered words) W –...