How to Find Files on the Ubuntu Command line Example?

Jul 07, 2022 . Admin

Hi Guys,

In this tute, we will discuss How to find files on the Ubuntu command line Example?. if you have question about Finding Files in the Command Line then I will give simple example with solution. it's simple example of Best Examples of Find command in Linux. you will learn Fast way to find file names in Ubuntu 22.04. Let's see bellow example Easy Ways to Find Files in Linux.

You can use this post for ubuntu 14.04, ubuntu 16.04, ubuntu 18.4, ubuntu 20.04, ubuntu 21 and ubuntu 22.04 versions.

Step 1: Finding by Name using Terminal

In order to find a file by name, simply type:

find -name "File1" 

If we want to run a case insensitive search, we can do this:

find -iname "File1" 

What if we only want to return files with names that don’t contain a certain string? Then we will use:

find -not -name "file" 
Step 2: Install wget
$ sudo apt install wget

This will return all files that don’t contain the string “file” in them, and is applicable to other strings.

Step 3: Finding by Type using Terminal

If you want to search for files by type, you can do so with the following command:

find -type typequery

Some examples of file types are:

(1) f: Regular file

(2) d: Directory

(3) l: Symbolic link

(4) c: Character devices

(5) b: Block devices

Step 4: Filtering by Time and Size using Terminal

Find can filter files based on their size. SImply use the -size flag with the following size conventions:

(1) c: Bytes

(2) k: Kilobytes

(3) M: Megabytes

(4) G: Gigabytes

(5) b: 512-byte blocks

In order to find a file that is exactly 1GB in size, simply type in the phrase:

find / -size 1G

If it is greater than 1GB:

find / -size +1G

Less than 1GB:

find / -size -1G
Step 4: Find File By Time using Terminal

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

You can find files based on access time change time (-ctime) flags.

Let’s find a file modified more than 5 days ago:

find /usr -ctime +5

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

find /usr -mmin -1

Reference file and return those that are newer:

find / -newer reference_file
#Ubuntu