Table of Contents
This tip is about the how to Utilise find Command in Linux. So read this free guide, How to Utilise find Command in Linux step by step. If you have query related to same article you may contact us.
How to Utilise find Command in Linux – Guide
Need to know how to find files on Linux? Well, surprise, surprise, you will need the find command on Linux to scrape your directory or filesystem. The Linux find command can filter objects recursively using a simple conditional mechanism, and if you use the -exec flag, you can find a file directly on Linux and process it without using any other commands. will do.
If you’re a Linux user, you can’t just rely on the GUI to perform various tasks, so a solid understanding of terminal commands is really essential. All Linux-based distributions run commands to perform various administrative tasks. Although Linux Terminal is a text interface that looks complicated, it is actually very flexible, easy to use and a very useful tool. Commands can be easily copied from online sources and pasted into the terminal to perform various tasks. There are many commands, but this post will focus on the “find” command.
The “find” command is used to search, filter or locate files and folders on your system according to user-specified conditions and perform various operations on them.
How to Find files on Linux
The find command has numerous options and functions that filter files based on specified conditions.
Find Command Syntax
The basic syntax of the find command is:
find [path] [options] [expression]
For example, the following command will search for text files in the / directoryhome directory.
find /home -type f -name “*.txt”
Remember that before searching your storage for files, you need to have read permissions for that particular directory.
Search files by name
The most common use of the find command is to search for a file by name. To find a file using the filename, use the -name flag with the default command.
find /home -type f -name filename.txt
The command mentioned above will look for a file called filename.txt in the / directoryhome directory. The -type f option tells the system that we are looking for a file. If you want to ignore the case of the character in the file name, replace the -name option with -iname.
find /home -type f -iname Filename
This command will find a file that has one of the following names: Filename, filename, FileName, FiLename, etc. Like any other Linux command, you can use . (dot) to also specify the relative path of the current directory.
find . -type f -name filename.txt
Likewise, / for /root and ~ for /home can be used too.
Find files by extension
Searching for files with a specific extension can help narrow your search results. To find a file by its extension, use the following regular expression with the -name and -iname flag.
find /home -type f -name “*.pdf”
This command will display a list of all files that have the .pdf extension. Note that you will have to escape the asterisk
character with quotes (“”) or a backslash () so that the terminal interprets it as a wildcard character.
You can also reverse the above command using the -not flag. The following command will search for files that do not have a .pdf extension.home find /
-type f -not -name “*.pdf”
You can even pipe the find command with other Linux commands. For example, to change moderation permissions for each file that fits the condition:home find /
– type f “*.pdf” -exec chmod -777 {} ;home This command will search all PDF files on /
directory and change its permissions so that anyone can read, write and execute these files.
Search for specific file types
In addition to files, the find command can also search for other types of files. Directories, symlinks, sockets and character devices are some of the file types supported by find.
s:tomashome To search for subdirectories present in /
directory:home find /
-type d
Find files by size up The -size flag allows you to search for files that take
To find all files with a file size of 1GB:home find /
-type f -size 1G
To search for files smaller than 1 GB, add the minus character (-) before specifying the size:home find /
-type f -size -1G
Likewise, use the plus (+) operator to find files larger than 1 GB:home find /
-type f -size +1G
To search files within a size range:home find /
-type f -size +1M -size -10M
Find files using timestamps
You may already know that Linux assigns specific timestamps to each file in its storage. These timestamps contain the modification time, the change time, and the access time. To find files with a specific modification time:home find /
-type f -name “*.txt” -mtime 5
The command mentioned above will print all files that have been modified in the last five days. Similarly, you can also use -atime and -ctime to filter files according to access time and change time. You can also use the plus and minus signs to find files that are larger or smaller than a specific timestamp.home find /
-type f -name “*.txt” -mtime +5
Search files with specific permissions
The -perm option allows users to search for files with a certain set of permissions.home find /
-type f -perm 777
Use the forward slash character (/) to list the file if at least one category has the correct set of permissions given.home find /
-type f -perm /777
Find files by owner
Use the -user flag to get files that belong to a specific user.home find /
-user randomuser
Find and delete files
To delete all files filtered using find, add the -delete flag to the final of the command.home find /
-type f -name “*.pdf” -delete
Final note
I hope you like the guide How to Utilise find Command in Linux. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.