Linux: Finding and Locating files with find command part # 1

Many newcomers find it difficult use the find command at shell prompt under Linux / *BSD or Solairs UNIX oses. Find is nifty tool on remote server where UNIX admin can find out lot of information too. Desktop users may find handy GNOME Search tool as a utility for finding files on system. Find command can perform a search based on a variety of search constraints. It searches through one or more directory tree(s) of a filesystem, locating files based on some user-specified criteria. By default, find returns all files below the current working directory. Further, find allows the user to specify an action to be taken on each matched file. Thus, it is an extremely powerful program for applying actions to many files. It also supports regexp matching.

GNOME Search Tool GUI Program

GNOME Search Tool is a utility for finding files on your system. To perform a basic search, you can type a filename or a partial filename, with or without wildcards. You can start this program from menus or by typing following command at shell prompt:
$ gnome-search-tool &
Internally GNOME Search Tool uses the find, grep, and locate UNIX commands. The case sensitivity of the search depends on your operating system. For example, on Linux, the find, grep, and locate commands support the -i option, so all searches are case-insensitive.

the GNOME Linux / UNIX GUI Search Tool(click to enlarge)

Find command syntax

find {search-path} {file-names-to-search} {action-to-take}


  • search-path : Define search path (default current directory). For example search in /home directory.
  • file-names-to-search : Name of the file you wish to find. For example all c files (*.c)
  • action-to-take : Action can be print file name, delete files etc. Default action is print file names.

Find command examples

Let us try out some examples.

Finding files and printing their full name

You wish to find out all *.c (all c source code) files located under /home directory, enter:
$ find /home -name "*.c"

You would like to find httpd.conf file location:
$ find / -name httpd.conf

Finding all files owned by a user

Find out all files owned by user vivek:
# find / -user vivek

Find out all *.sh owned by user vivek:
# find / -user vivek -name "*.sh"

Finding files according to date and time

Files not accessed in a time period Γ’β‚¬β€œ It is useful to find out files that have or have not been accessed within a specified number of days. Following command prints all files not accessed in the last 7 days:
# find /home -atime +7

  • -atime +7: All files that were last accessed more than 7 days ago
  • -atime 7: All files that were last accessed exactly 7 days ago
  • -atime -7: All files that were last accessed less than7 days ago

Finding files modified within a specified time Γ’β‚¬β€œ Display list of all files in /home directory that were not last modified less than then days ago.
# find /home -mtime -7

Finding newer (more recently) modified files

Use -newer option to find out if file was modified more recently than given file.
# find /etc/apache-perl -newer /etc/apache-perl/httpd.conf

Finding the most recent version of file

It is common practice before modifying the file is copied to somewhere in system. For example whenever I modify web server httpd.conf file I first make backup. Now I don’t remember whether I had modified the /backup.conf/httpd.conf or /etc/apache-perl/httpd.conf. You can use the find command as follows (tip you can also use ls -l command):
find / -name httpd.conf -newer /etc/apache-perl/httpd.conf

Locate command

The locate command is often the simplest and quickest way to find the locations of files and directories on Linux and other Unix-like operating systems.

For example, the following command uses the star wildcard to display all files on the system that have the .c filename extension:
# locate "*.c"

Further readings

  • Read find and locate command man page for more information.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 16 comments so far... add one
CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
16 comments… add one
  • Anonymous Jul 23, 2005 @ 14:22

    Thanks for nice blog!

  • Sabu Aug 18, 2005 @ 12:41

    This post has been removed by the author.

  • Sabu Aug 18, 2005 @ 12:43

    Good one..2 more from me..

    # files modied 3 days ago but less than 5 days.

    find /home -type f -mtime +2 -mtime -5

    # find all files with name ‘testfile’ in /home directory recursively and contains the word hello.

    find /home -type f -name testfile | xargs grep -l -i hello

  • Amit sharma Aug 4, 2006 @ 6:50

    Hi nix, appreciate your efforts.

    For all those people who are looking for sum more examples.. do check out http://www.amitsharma.linuxbloggerscom/how_to_find.htm

    With best regards..

  • Dan Coe Feb 9, 2007 @ 9:59

    Thanks for educating me on the basics of using find on Linux. Most appreciated from a newbie.

  • Paul Hudgens Feb 6, 2009 @ 22:20

    I’m hoping to find a command that will allow me to list all of my PDS files in a given directory but which may have a .pds suffix or a .PDS suffix or a .Pds suffix , ie case insensitive so that with a single command, I see all such files – and then perhaps send that list to a zip command.

    Thanks for any help
    Paul Hudgens

  • Paul Hudgens Feb 6, 2009 @ 22:20

    By the way my previous post re: case insensitivity is for a Sun system.


  • 🐧 nixCraft Feb 6, 2009 @ 22:59

    Option #1: Install gnufind

    find . -iname "*.pds"

    Option #2: Use Sun find command

    find . -type f  -print | grep -i "*.pds" 
  • Alex Feb 19, 2009 @ 6:14

    IÒ€ℒm hoping to find a command that will allow me to list all files owned by a specific user on a specific file systems. So, I can create a script and (using this script) be able to search for other owners on other file systems without having to edit this file.

    Thanks for any help,

    • 🐧 nixCraft Feb 19, 2009 @ 6:49

      Use find command:
      find /path/to/dir -iname "*.c" -user vivek -print

      The -user UID : Find file is owned by user UID (numeric user ID allowed).

  • V Feb 24, 2009 @ 16:18

    Open all .cpp files that contain the string foo (case insensitive in them):

    vi `find ./ -name ‘*.cpp’ -exec grep -qi ‘foo’ {} ; -print0 -exec echo -n ‘ ‘ ;`


    find ./ -name ‘*.cpp’ -exec grep -qi ‘foo’ {} ; -exec vim {} ;

    The second version opens one file at a time, as it finds it. The first version takes some time to find all files first, and then opens them all πŸ˜€

    And, of course, in general stuff between -exec and ; can be any command you want with {} being replaced by the matched file name.

  • manpreet Apr 17, 2009 @ 5:11

    i want to find all files with inode number 20 and less than 20 with find command.
    if someone can help me i ll be grateful to the person

  • chandan Apr 1, 2010 @ 5:37


    I am unable to find out the boot error which had occured some where in last week while rebooting the server.

    Can someone help me which command to use to find that error.


  • princeda Aug 1, 2011 @ 10:42

    Hi vivek,

    How to delete the 3 days old backup files which is in /backup file, using find command?

  • Anonymous Sep 2, 2015 @ 4:51

    Thank you so much!

  • Abigail Ava Jan 21, 2017 @ 7:07

    Sometimes we get an error when we try to delete a File or a folder for no reason , but of course there is a reason.We have many damage file or blocked files.
    Do not worry if we want to remove the error files or too long path files from our system,here I suggest a smooth way.
    So use β€œLong path tool” software and keep yourself.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum