How to Find File In linux Ubuntu using Terminal

1. Use the ‘locate’ command:

The ‘locate’ command is the quickest and easiest way to find a file in Linux. It searches through a database of all the files on your system, so it’s very fast. To use it, open a terminal window and type ‘locate’ followed by the name of the file you’re looking for.

For example, if you’re looking for a file called ‘example.txt’, you would type:

locate example.txt

2. Use the ‘find’ command:

The ‘find’ command is a more powerful way to search for files. It allows you to search for files based on various criteria, such as name, size, date modified, etc. To use it, open a terminal window and type ‘find’ followed by the path to the directory you want to search.

For example, if you want to search for a file called ‘example.txt’ in the ‘/home/user’ directory, you would type:

find /home/user -name example.txt

3. Use the ‘grep’ command:

The ‘grep’ command is a powerful way to search for files based on their contents. It allows you to search for a specific string of text within a file. To use it, open a terminal window and type ‘grep’ followed by the string of text you’re looking for.

For example, if you want to search for a file containing the text ‘example’, you would type:

grep example

Find files in Linux Ubuntu using the terminal; Through this tutorial, we will learn how to find files by name, size, and type in Linux Ubuntu using the terminal.

How to Find File In Linux Ubuntu using Terminal

Follow the below-given steps to find the files by name, size, and type in Linux Ubuntu using the terminal; is as follows:

  • Finding by Name using Terminal
  • Finding by Type using Terminal
  • Filtering by Time and Size using Terminal

Finding by Name using Terminal

Use the following command to find a file by name; is as follows:

find -name "query"

Use the following command to find a file by name but ignore the case of the query; is as follow:

find -iname "query"

Use the following command to find all files that don’t adhere to a specific pattern; is as follow:

find -not -name "query_to_avoid"

Finding by Type using Terminal

Use the following command to find with the -type parameter; is as follow:

find -type type_descriptor query

There are other options in the type to find the file. Which are given below:

  • f: regular file
  • d: directory
  • l: symbolic link
  • c: character devices
  • b: block devices

Filtering by Time and Size using Terminal

You can also find files by their size and time in the Linux ubuntu system. The following commands has been given for this:

And also know as some commonly used size suffixes:

  • c: bytes
  • k: kilobytes
  • M: megabytes
  • G: gigabytes
  • b: 512-byte blocks

For example, the following command will find each file in the /usr directory that is exactly 60 bytes:

find /usr -size 60c

To find files that are less than 100 bytes, Use the following command:

find /usr -size -100c

To find files over 800 megabytes in the /usr directory, Use the following command:

find /usr -size +800M

Find File By Time using Terminal

Here we will talk about how to find time recording files in the Linux Ubuntu system.

  • Access Time: The last time a file was read or written to.
  • Modification Time: The last time the contents of the file were modified.
  • Change Time: The last time the file’s inode metadata was changed.

For example, to find files in the /usr directory that were modified in the previous day, use the following command:

find /usr -mtime 1

If you want files that were accessed less than a day ago, you could run this command:

find /usr -atime -1

To find files that last had their meta information changed more than 3 days ago, you might execute the following:

find /usr -ctime +3

These options also have companion parameters you can use to specify minutes instead of days:

find /usr -mmin -1

This will give the files that have been modified in the last minute.

find can also do comparisons against a reference file and return those that are newer:

find / -newer reference_file

Conclusion

Through this tutorial, we have learned how to find files by name, size, and type in Linux Ubuntu using the terminal.

Recommended Linux Ubuntu Tutorials

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
San Vito Al Tagliamento 33078
Pordenone Italy
Item added to cart.
0 items - 0.00
Open chat
Scan the code
Hello 👋
Can we help you?