You need to input number of days after -mtime option above. Here’s the command to find file modified in last 7 days $ find /home -mtime 7 You can easily search file by modified time in Linux using -mtime option.
You can use c, KB, MB, GB to describe file sizes in bytes, kilobytes, megabytes and gigabytes respectively.īonus Read : How to List all files in Directory Here’s the command to find file greater than 10Mb in /home folder $ find /home -size +10MB You can easily search file by size in Linux using -size option. Here’s the command to find all directories in /home $ find /home -type d Here’s the command to list all symbolic links in /home folder $ find /home -type l Here’s the command to list all empty files in /home directory using -empty option $ find /home -type f -empty Here’s the command to find regular files in /home directory $ find /home -type f Since there are different file types in Linux, you can use -type option to find files by their type.
For example, here’s the find command to search all pdf files in /home directory $ find /home -name *.pdfīonus Read : How to Install Zip File in Linux We can use the above-mentioned pattern matching to find files by extension. So it will match 123unix.txt, unix.pdf and also UNIX.TXT. The above command will do a case sensitive match for “unix” pattern. If we use -iname option instead of -name option, it will do a case insensitive match. So it will match 123unix.txt, unix.pdf but not UNIX.TXT You can use wildcard characters like * to specify search patterns. The following command searches for any file that contains the string unix in its filename. Here’s the command to find files by name, using wildcard characters. The above command will match unix.txt, UNIX.TXT but not 123unix.txt. The following command searches for unix.txt file at /home folder $ find /home -iname unix.txt Here’s the command to find files by name, with a case-insensitive exact match, using -iname option. The above command will match only linux.txt and no other filename The following command searches exactly for linux.txt file at /home folder $ find /home -name linux.txt Here’s the command to find files by name, with a case-sensitive exact match, using -name option. We will look at some commonly used examples for find command. So it won’t match files like “DOCUMENT.TXT” or “word-document.txt”īonus Read : How to Create Zip File in Linux Please note, find command is case-sensitive and does an exact match by default. If you don’t specify the starting path, find command will start searching in your present working directory.įor example, here’s the command to find “document.txt” file in /home/ubuntu folder $ find /home/ubuntu/ -name document.txt In the above command, you need to specify the starting path where find command needs to start searching file, options as per your requirement, and the search expression to look for in file attributes. $ find starting_path options search_expression We will use the find command to search a file in Linux. Here are the steps to search a file in Linux. You can use it to search a file in Ubuntu, CentOS, Redhat, Fedora, and other Linux systems. Many times, you may need to search a file in Unix or to find a file in directory in Linux.