Find a File by Name Using Command-line on Ubuntu 22.04

Jul 07, 2022

.

Admin

Find a File by Name Using Command-line on Ubuntu 22.04

Hi Guys,

This article will provide some of the most important example Find a File by Name Using Command-line on Ubuntu 22.04. you can understand a concept of find file in ubuntu terminal Code Example. step by step explain 4 Ways to Find a File in Linux. This article goes in detailed on Linux find command: search and find files. follow bellow step for Use the Linux terminal to see what files are on your computer.

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