• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

Awesome Linux Find Command Examples

Written by Rahul, Updated on July 4, 2020

find is a Linux command line tool to search files and directories in the file system. The find command works much fast than any other command. It provides a large number of options for more specific search. It also supports wildcard characters. Every system admin must read this article and understand the uses of the find command. This command is very useful in your daily tasks. This article will help you to understand find command and its uses in Linux system.

  • Suggested Read: 13 Awesome Linux Grep Command Examples

Syntax: To search a file or directory under specified filesystem.

find /search/in/dir -name filename

Explanation:

  • find => command line tool
  • /search/in/dir => Directory name where to start search
  • -name=> Switch to specify filename
  • filename=> file or directory name

Find files by Name

Use -name option to find a file with name “hello.txt” under root (/) file system.

find / -name hello.txt

Find files by Type

Search for the file (not directory) named “backup.zip” in entire file system. Use -type f to specify search for files and ignore direcories.

find / -type f -name backup.zip

Search directory only

Search for the directory (not file) named “backup” in entire file system. Use -type d to specify search for directory and ignore files.

find / -type d -name backup

Find files by Size

Search all files system wide, which are greater than or equal to 10 MB with find command

find / -type f -size +10M

And this command will search all files in system which are less than 10MB.

find / -type f -size -10M
  • -size: switch are used for searching file on bais of there size. Plus ( + ) is used to greater than size and minus ( – ) sign is used for less than size.
    like: +100MB, -50KB, +1GB etc…

  • Find files by Time

    Search all files which modification time is more than 30 days.

    find / -type f -mtime +30
    

    Search all files which modification time is less than 30 days.

    find / -type f -mtime -30
    

    Find files by User/Group

    Find command also provides search based on user and group ownership. like:

    Search all .txt files own by user bob.

    find  / -user bob -name "*.txt"
    

    Search all .txt files with group ownership of root.

    find  / -group root -name "*.txt"
    

    You can combine both to more specific search to files with owner bob and group ownership of the root.

    find  / -user bob -group root -name "*.txt"
    

    Find files by Permissions

    Search all files which are having 777 permissions under /var/www directory tree. This can be helpful for the security audit.

    find . -perm 777
    

    Find files by Inode Number

    This command is used to search files on basis of their inode number. -inum is used for this search.

    find / -inum 1532
    

    If you want check inode number of a file using below command. The first field of output is an inode number

    ls -li tecadmin.txt
    
    30878 -rw-r--r--. 1 root root 0 Mar 22 17:20 tecadmin.txt
    

    Find Empty files

    This command is very useful to search empty files and directories. It is useful to the cleanup system with empty files and directories.

    $ find / -empty
    

    Find files by File Types

    Search all block special files available under / filesystem.

    find / -type b
    

    Other file type options are as below:

    b – block (buffered) special
    c – character (unbuffered) special
    d – directory
    p – named pipe (FIFO)
    f – regular file
    s – socket
    l – symbolic link; this is never true if the -L option or the -follow option is in effect unless the symbolic link is broken. If you want to search for symbolic links when -L is in effect, use -xtype.

    Share it!
    Share on Facebook
    Share on Twitter
    Share on LinkedIn
    Share on Reddit
    Share on Tumblr
    Share on Whatsapp
    Rahul
    Rahul
    Connect on Facebook Connect on Twitter

    I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

    Leave a Reply Cancel reply

    Popular Posts

    • How To Install Python 3.9 on Ubuntu 20.04 5
    • How To Install Python 3.9 on Ubuntu 18.04 0
    • How to Use AppImage on Linux (Beginner Guide) 2
    • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
    • How To Install VNC Server on Ubuntu 20.04 1
    © 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy