Linux: How can I find a file on my system?

Linux: How can I find a file on my system?

To find a file on a Linux system, you can use the find command. The find command allows you to search for files based on various criteria such as the name of the file, the type of the file, the time when the file was last modified, and more.

Here's the basic syntax of the find command:

find path -options criteria
Source:ww‮l.w‬autturi.com

path is the starting directory for the search. This can be a directory on your filesystem, or a special value like . to search the current directory or / to search the entire filesystem.

options are optional flags that allow you to specify the criteria for the search. Some common options include:

  • -name pattern: Search for files with names that match the given pattern.
  • -type f: Search for regular files (not directories or other special file types).
  • -mtime n: Search for files that were modified within the last n days.
  • -iname pattern: Same as -name, but the search is case-insensitive.

criteria are additional tests that the find command can perform on the files it finds. For example, you can use the -exec option to execute a command on each file that matches the search criteria.

Here's an example of using the find command to search for all files with the .txt extension in the current directory and its subdirectories:

find . -name "*.txt"

You can also use the locate command to find files on your system. The locate command uses a database of file names to quickly locate files on your system, but it may not always have the most up-to-date information. To update the database used by locate, you can use the updatedb command.

locate filename
Created Time:2017-10-30 10:17:45  Author:lautturi