Open your terminal window and simply type find
command with -name, -size, and -type options to find a file by their name, size, and type on the Linux Ubuntu command line.
Here are four ways how to find the files by their name, size, type and time in Linux Ubuntu via the command line or Terminal:
Press ctrl+alt+t
on the keyboard and start a terminal window or command line.
Way 1: Finding by Name
To find a file by its name, simply use find -name "query"
command on the Ubuntu terminal window and press enter:
find -name "query"
To ignore the case of the query, while searching file on terminal window, you can use the following command:
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"
Way 2: Finding by Type
To find a file by its type, simply type find -type "query"
command on Ubuntu terminal window and press enter:
find -type type_descriptor query
There are other options in the type to find the file. Which are given below:
f
: regular filed
: directoryl
: symbolic linkc
: character devicesb
: block devices
Way 3: Finding File by Size
To find a file by its size, simply use find / -size +60c
command on ubuntu terminal window and press enter:
find / -size +60c
Here are some size suffixes:
c
: bytesk
: kilobytesM
: megabytesG
: gigabytesb
: 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
Way 4: Finding File By Time
To find a file by its time, simply type find . -mtime 1
command on Ubuntu terminal window and press enter:
find . -mtime 1
- 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
To find files that were accessed less than a day ago, you could run this command:
find /usr -atime -1
In 3 days ago, changed the information of the file, To find it use this command:
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
command can also do comparisons against a reference file and return those that are newer:
find / -newer reference_file
Conclusion
That’s it, you have learned how to find files by name, size, and type in Linux Ubuntu using the terminal.